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

1368: Add I18n to JavaScript #1369

Merged
merged 25 commits into from
Apr 19, 2023
Merged

Conversation

pedro-mendonca
Copy link
Member

@pedro-mendonca pedro-mendonca commented Mar 30, 2022

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.

@pedro-mendonca pedro-mendonca requested a review from ocean90 March 30, 2022 15:52
Copy link
Member

@ocean90 ocean90 left a 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.
@pedro-mendonca
Copy link
Member Author

Hi, I understand, and I agree.
About the JS, as the time is limited I tried to fix things following the same pattern as already exists assuming it won't be necessary to discuss as no code pattern was changed, making it easier for everyone. But I'll go for the new wp.i18n as it's a better solution.
About the consistency of strings listed above, if no suggestions, I'll keep em as they are.
Glossary and Translation -> verb Save
Priority and Status -> verb Set

For the validation error messages I can revert and open a separate PR.

@pedro-mendonca pedro-mendonca changed the title 1368: I18n fixes for validation error messages and JavaScript 1368: Add I18n to JavaScript Mar 31, 2022
@pedro-mendonca pedro-mendonca requested a review from ocean90 March 31, 2022 11:08
@pedro-mendonca
Copy link
Member Author

@ocean90 I've reduced this PR to only JS i18n.
Please let me know if it's ok now.

ocean90
ocean90 previously requested changes Apr 1, 2022
Copy link
Member

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

@pedro-mendonca pedro-mendonca requested a review from ocean90 April 1, 2022 18:55
@pedro-mendonca
Copy link
Member Author

As more and more JS is being added in functionalities like Local Translations branch, it would be good to make the current JS fully i18nized. Would you please recheck this PR @ocean90?
With the recent active dev team, should I also request review to @amieiro and @akirk?

Copy link
Member

@amieiro amieiro left a 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:

image

Then I have imported this file in my local GlotPress and I have translated some strings like "Dismiss":

image

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.

image

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?

@pedro-mendonca
Copy link
Member Author

Have you generated the .json files from the current .po with those new strings translated?
https://developer.wordpress.org/cli/commands/i18n/make-json/

@pedro-mendonca
Copy link
Member Author

For JavaScript translations to be loaded you need those .json files generated from your glotpress-gl_ES.po on the same ./wp-content/languages/plugins/ folder.

Co-authored-by: Jesús Amieiro Becerra <[email protected]>
@amieiro amieiro self-requested a review April 17, 2023 08:04
@amieiro amieiro dismissed ocean90’s stale review April 19, 2023 08:23

The changes requested here (#1369 (review)) have been made

@amieiro amieiro merged commit 3e555bc into GlotPress:develop Apr 19, 2023
@pedro-mendonca pedro-mendonca deleted the issue-i18n branch April 19, 2023 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants