-
Notifications
You must be signed in to change notification settings - Fork 28
Add PO command #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PO command #31
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request introduces support for translating gettext PO files by reverting modifications to the existing translator commands and adding new PO-specific translation functionality. Key changes include:
- Implementation of PoLangTransformer to parse and write PO files.
- Creation of the TranslatePoFileCommand for PO file translation using an AI provider.
- Addition of PoTranslationContextProvider to supply translation context and updates to the README for PO command usage.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/Transformers/PoLangTransformer.php | Implements PO file parsing and transformation for translations. |
src/Console/TranslatePoFileCommand.php | Provides a dedicated CLI command for translating PO files using AI. |
src/AI/PoTranslationContextProvider.php | Supplies contextual data for PO file translations based on available source files. |
README.md | Updates documentation to inform users about PO file translation support. |
Comments suppressed due to low confidence (1)
README.md:63
- The documentation refers to a 'translate-po' command while the actual command signature in the code is 'ai-translator:translate-po-file'; update the README for consistency.
+ Supports gettext PO files via the `translate-po` command
foreach ($lines as $line) { | ||
if (preg_match('/^msgid\s+"(.*)"/', $line, $m)) { | ||
$currentId = stripcslashes($m[1]); | ||
} elseif ($currentId !== null && preg_match('/^msgstr\s+"(.*)"/', $line, $m)) { | ||
$this->entries[$currentId] = stripcslashes($m[1]); | ||
$currentId = null; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current regex only captures single-line msgid entries, which may break for multi-line PO strings; consider enhancing the parser to support multi-line entries in accordance with the PO file specification.
foreach ($lines as $line) { | |
if (preg_match('/^msgid\s+"(.*)"/', $line, $m)) { | |
$currentId = stripcslashes($m[1]); | |
} elseif ($currentId !== null && preg_match('/^msgstr\s+"(.*)"/', $line, $m)) { | |
$this->entries[$currentId] = stripcslashes($m[1]); | |
$currentId = null; | |
} | |
} | |
$currentId = null; | |
$currentStr = null; | |
$isMsgid = false; | |
$isMsgstr = false; | |
foreach ($lines as $line) { | |
if (preg_match('/^msgid\s+"(.*)"/', $line, $m)) { | |
$currentId = stripcslashes($m[1]); | |
$isMsgid = true; | |
$isMsgstr = false; | |
} elseif ($isMsgid && preg_match('/^"(.*)"/', $line, $m)) { | |
$currentId .= stripcslashes($m[1]); | |
} elseif (preg_match('/^msgstr\s+"(.*)"/', $line, $m)) { | |
$currentStr = stripcslashes($m[1]); | |
$isMsgid = false; | |
$isMsgstr = true; | |
} elseif ($isMsgstr && preg_match('/^"(.*)"/', $line, $m)) { | |
$currentStr .= stripcslashes($m[1]); | |
} elseif ($currentId !== null && $currentStr !== null) { | |
$this->entries[$currentId] = $currentStr; | |
$currentId = null; | |
$currentStr = null; | |
$isMsgid = false; | |
$isMsgstr = false; | |
} | |
} | |
// Handle any remaining entry | |
if ($currentId !== null && $currentStr !== null) { | |
$this->entries[$currentId] = $currentStr; | |
} |
Copilot uses AI. Check for mistakes.
|
||
public function handle() | ||
{ | ||
$GLOBALS['instant_results'] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a global variable for storing instant results can lead to maintainability issues and unintended side effects; consider refactoring to use dependency injection or a dedicated storage mechanism.
$GLOBALS['instant_results'] = []; | |
$this->instantResults = []; |
Copilot uses AI. Check for mistakes.
Summary
TranslatePoStrings
andTranslatePoFileCommand
for gettext PO filesPoTranslationContextProvider
Testing