-
Notifications
You must be signed in to change notification settings - Fork 52
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
Improve language handling when creating JSON files #133
Conversation
Hello, I still get this error even after replacing underscores with dashes. When I run the make-json command, I get absolutely nothing. No errors, no success messages and no files created. I went to |
@alialaa Are you using the latest version of the command that includes the fixes from this PR? |
I guess so I ran |
Also in |
Ah yes, that looks correct. Looks like the issue is that the language list (https://github.com/mlocati/cldr-to-gettext-plural-rules/blob/master/src/cldr-data/main/en-US/languages.json) includes The upstream library we use leverages the language information solely for the purpose of adding plural forms: https://github.com/oscarotero/Gettext/blob/545f716f08338030d2d0d35a1835d04a9d4f18ed/src/Translations.php#L352-L361 However, we already do that ourselves anyway: i18n-command/src/MakeJsonCommand.php Lines 168 to 173 in af14c16
So I guess we can just silently ignore that exception... |
The thing is if I hard code 'en' like so in the try catch block, I also get
Also not sure if this is related but Language::getAll() that I am dumping returns an empty array. Languages is from |
Weird, I'm pretty sure that worked in tests. But not really a problem. With my suggestion (created #142 for it) we don't need that list anyway. |
So I can just remove that whole try, catch block if I need to test it now, correct? |
You could certainly do that for testing, yes, but that's not really the solution. We definitely should set the language for the translations. The correct solution would probably be more like this: try {
$mapping[ $source ]->setLanguage( $translations->getLanguage() );
} catch ( \InvalidArgumentException $e ) {
// Do nothing.
} Or perhaps $mapping[ $source ]->setHeader( \Gettext\Translations::HEADER_LANGUAGE, $translations->getLanguage() ); |
Thanks, I will wait for your fix. I just tried this and it worked but I have some notes that maybe could be helpful to you:
Thanks for your help! |
|
Thanks a lot :) |
I enocuntered the same issue. This is what I do to fix the wp-cli.phar
$phar = new Phar('.....wp-cli.phar'); $phar['vendor/wp-cli/i18n-command/src/MakeJsonCommand.php'] = str_replace( ['Symfony\\Component\\Finder\\', '$mapping[ $source ]->setLanguage( $translations->getLanguage() );'], ['', '$mapping[ $source ]->setHeader( \\Gettext\\Translations::HEADER_LANGUAGE, $translations->getLanguage() );'], $phar['vendor/wp-cli/i18n-command/src/MakeJsonCommand.php']->getContent()); |
Which WP-CLI version will include this fix? |
@cbratschi The next one? :-) Once #150 is merged, you can install the latest version of this package over what's included in WP-CLI by running this:
This way you don't have to wait for the next WP-CLI release. |
@swissspidy Thanks a lot, it works now fine. |
Improve language handling when creating JSON files
Turns out
\Gettext\Translations::setLanguage()
throws an exception when trying to pass a language that's not in the list provided by https://packagist.org/packages/gettext/languages (CLDR).That means it fails when passing
de_DE
, because it expectsde-DE
.This PR does two things: