-
Notifications
You must be signed in to change notification settings - Fork 129
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
1368: Add I18n to JavaScript #1369
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.
Thanks for trying to improve I18N in GlotPress itself! But when making such large changes it's better to discuss them first so feedback can be provided earlier.
These are two separate issues which again should be handled in separate pull requests. For the JavaScript part it makes more sense to refactor this by using the wp-i18n JavaScript package and its wp.i18n
API.
For the validation part, I'm not sure why you added the $message
parameter to the second position. This seems like an unnecessary back-compat break.
Building the message like this is also still cumbersome and not easy to translate since the sentence is split into multiple parts.
I think it would be much easier if the full message, one for positive and one for negative can be provided and only the type and field names are (optionally) injected.
This reverts commit 11345bc7432294e472e090cf1ff8a9fe006aa7e9.
Hi, I understand, and I agree. For the validation error messages I can revert and open a separate PR. |
@ocean90 I've reduced this PR to only JS i18n. |
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 think it's okay to use wp.i18n.{methodName}
everywhere instead of having an extra variable.
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.
To test this functionality, I have created the .pot file to add the new strings to the translation:
wp i18n make-pot . languages/glotpress.pot
This command adds the new strings:
Then I have imported this file in my local GlotPress and I have translated some strings like "Dismiss":
Then I have created the .mo file (glotpress-gl_ES.mo as I am testing with Galician language) and I have moved it to the wp-content/language/plugins
, overwriting the current file.
I have reloaded the page content, to load the new translations, and then I have tried to translate a string with empty content, to fire an error, and the "Dismiss" text is not translated.
The updates in the JavaScript file are loaded fine, but the translation in the JavaScript file is not showed.
I have updated the file version for the common.js
file, using the filemtime
function, to look for some cache problem, but the result is the same.
wp_register_script( 'gp-common', $url . '/common' . $suffix, array( 'jquery', 'wp-i18n' ), filemtime(plugin_dir_path( __FILE__ ) . '/../assets/js/common.js') );
Am I missing some steps to test this code?
Have you generated the .json files from the current .po with those new strings translated? |
For JavaScript translations to be loaded you need those .json files generated from your |
Co-authored-by: Jesús Amieiro Becerra <[email protected]>
The changes requested here (#1369 (review)) have been made
Partially fixes (JS i18n) #1368
@ocean90 this is built on top of some of the changes of #1364 and assumes the renaming of the callbacks or to and.
So is better to first merge #1364 and then fix any necessary naming.
Feel free to add feedback on consolidate some more.I just moved all the strings from JS to PHP and tried to sort it in a way it's easier for review.Edited: This PR doesn't use JS strings in PHP anymore. Just adds common
wp.i18n
to JavaScript.