-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 locale:import:all - imports multiple custom translation po files #5569
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.
Initial review of the code. I did not test the command yet.
Note: Performing the same import with locale:import is possible but requires bash scripting.
@Sutharsan Is all feedback addressed? |
src/Commands/core/LocaleCommands.php
Outdated
$files = []; | ||
foreach ($poFiles as $file) { | ||
// Ensure we have the file intended for upload. | ||
if (file_exists($file)) { |
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 other if conditions in this foreach loop use continue
to skip processing the current $file
. I agree with using this code style (early return). I'd like to use it consistently and apply it to this condition too, and remove these nested if conditions. With this being done, the comment 'Ensure we have the file ...' can go away. It is pretty obvious what is going on here.
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.
fixed
I have tested the code and all works as expected. @weitzman If you provide an array of command aliases, drush shows all aliases except the first. Is this intended behavior? (I see the same behavior with existing commands) The command code:
The output of
|
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.
Yeah, we should omit "dash" aliases for new commands.
src/Commands/core/LocaleCommands.php
Outdated
#[CLI\Usage(name: 'drush locale:import-all /var/www/translations', description: 'Import all translations from the defined directory (non-recursively). Supported filename patterns are: {project}-{version}.{langcode}.po, {prefix}.{langcode}.po or {langcode}.po.')] | ||
#[CLI\Usage(name: 'drush locale:import-all /var/www/translations/custom --types=customized --override=all', description: 'Import all custom translations from the defined directory (non-recursively) and override any existing translation. Supported filename patterns are: {project}-{version}.{langcode}.po, {prefix}.{langcode}.po or {langcode}.po.')] | ||
#[CLI\ValidateModulesEnabled(modules: ['locale'])] | ||
public function importAll($directory, $options = ['type' => self::OPT, 'override' => self::OPT]) |
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.
public function importAll($directory, $options = ['type' => self::OPT, 'override' => self::OPT]) | |
public function importAll($directory, $options = ['type' => self::REQ, 'override' => self::REQ]) |
The meaning of REQ is that a value must be supplied when the option is used.
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.
done
src/Commands/core/LocaleCommands.php
Outdated
*/ | ||
#[CLI\Command(name: self::IMPORT_ALL, aliases: ['locale-import-all', 'locale:import:all'])] | ||
#[CLI\Argument(name: 'directory', description: 'The path to directory with translation files to import.')] | ||
#[CLI\Option(name: 'type', description: 'String types to include, defaults to <info>not-customized</info>. Recognized values: <info>not-customized</info>, <info>customized</info>')] |
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.
Use suggestionValues param as per
drush/src/Commands/config/ConfigCommands.php
Line 146 in 166af7a
#[CLI\Option(name: 'input-format', description: 'Format to parse the object. Recognized values: <info>string</info>, <info>yaml</info>. Since JSON is a subset of YAML, $value may be in JSON format.', suggestedValues: ['string', 'json'])] |
https://github.com/weitzman/drush/blob/166af7acb72ad256cbc8c33fba58f5981683cd5a/src/Commands/config/ConfigCommands.php#L146. Helps with shell completion.
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.
done, for override option as well
Looks like a bug. I think we should show only the first alias. Otherwise the first column gets too wide. |
293a922
to
c1cce04
Compare
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.
LGTM. @Sutharsan will merge when satisfied.
rebased forked branch, so all checks should be fine now |
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.
I found two sentences that need some improvement.
Once this is fixed, I will merge the PR. |
Co-authored-by: Erik Stielstra <info@erikstielstra.nl>
Fixed and rebased again |
Thanks all for working on this. |
Supersedes #4251