Skip to content
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

Merged
merged 8 commits into from
Aug 23, 2023

Conversation

andypost
Copy link
Contributor

Supersedes #4251

Copy link
Contributor

@Sutharsan Sutharsan left a 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.

src/Commands/core/LocaleCommands.php Outdated Show resolved Hide resolved
src/Commands/core/LocaleCommands.php Outdated Show resolved Hide resolved
src/Commands/core/LocaleCommands.php Outdated Show resolved Hide resolved
src/Commands/core/LocaleCommands.php Outdated Show resolved Hide resolved
src/Commands/core/LocaleCommands.php Outdated Show resolved Hide resolved
@weitzman
Copy link
Member

weitzman commented Jun 2, 2023

@Sutharsan Is all feedback addressed?

$files = [];
foreach ($poFiles as $file) {
// Ensure we have the file intended for upload.
if (file_exists($file)) {
Copy link
Contributor

@Sutharsan Sutharsan Jun 8, 2023

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@Sutharsan
Copy link
Contributor

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)
Since this is a new command why should we provide aliases? No BC required, no short code.

The command code:

#[CLI\Command(name: self::IMPORT_ALL, aliases: ['locale-import-all', 'locale:import:all'])]

The output of drush list:

locale:                                                                                                                        
  locale:check                                 Checks for available translation updates.                                       
  locale:clear-status                          Clears the translation status.                                                  
  locale:export                                Exports to a gettext translation file.                                          
  locale:import                                Imports to a gettext translation file.                                          
  locale:import-all (locale:import:all)        Imports multiple translation files from the defined directory.                  
  locale:update                                Imports the available translation updates.                                      

Copy link
Member

@weitzman weitzman left a 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.

#[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])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

*/
#[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>')]
Copy link
Member

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

#[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.

Copy link
Contributor

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

@weitzman
Copy link
Member

If you provide an array of command aliases, drush shows all aliases except the first. Is this intended behavior?

Looks like a bug. I think we should show only the first alias. Otherwise the first column gets too wide.

@weitzman
Copy link
Member

weitzman commented Jun 12, 2023

Copy link
Member

@weitzman weitzman left a 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.

@Sergey-Orlov
Copy link
Contributor

rebased forked branch, so all checks should be fine now

Copy link
Contributor

@Sutharsan Sutharsan left a 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.

src/Commands/core/LocaleCommands.php Outdated Show resolved Hide resolved
src/Commands/core/LocaleCommands.php Outdated Show resolved Hide resolved
@Sutharsan
Copy link
Contributor

Once this is fixed, I will merge the PR.

Co-authored-by: Erik Stielstra <info@erikstielstra.nl>
@Sergey-Orlov
Copy link
Contributor

Sergey-Orlov commented Aug 22, 2023

Once this is fixed, I will merge the PR.

Fixed and rebased again

@Sutharsan Sutharsan merged commit 6ab5d13 into drush-ops:12.x Aug 23, 2023
2 checks passed
@Sutharsan
Copy link
Contributor

Thanks all for working on this.

@andypost andypost deleted the locale-drush-12 branch December 17, 2023 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants