-
Notifications
You must be signed in to change notification settings - Fork 199
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 support for translating strings in JavaScript files #3219
Conversation
Nice! One more aspect of this that's still needed to hook everything up is a We should also test at some point that everything works with translate.wordpress.org. |
I noticed that the line that the JS text are referenced as being on is something like:
Of course, there is no such file in the UPDATE: I checked this in WC admin and they reference the correct files:
|
0402091
to
ed1b01d
Compare
@@ -164,6 +173,7 @@ public function prepare_wizard_page() { | |||
add_action( 'admin_print_scripts', [ $this, 'enqueue_scripts' ] ); | |||
add_action( 'admin_print_styles', [ $this, 'enqueue_styles' ] ); | |||
add_action( 'admin_body_class', [ $this, 'filter_body_class' ] ); | |||
add_action( 'init', [ $this, 'setup_wizard_set_script_translations' ] ); |
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.
wp_set_script_translations
will only work after the enqueue/register call, so instead of the init
hook this should be in enqueue_scripts
.
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.
It was fixed here: e7c577e ;)
It must be done after the script register.
It didn't work well, duplicating some translations.
Now the i18n script is using wp i18n make-pot which also merges the JS pot file.
Borrowed from WooCommerce Admin plugin.
@donnapep and @yscik, it's almost ready! We can already test following the instructions in the PR description. I just didn't understand yet what point in the WooCommerce Admin process they fix the source file references to the dist files. It's important because the JSON should be generated based in the file that our plugin is loading (the dist file). Is there a process related to the translation that I don't know yet? It looks like WC folks generate the translated files after receiving the translations. |
Actually, I'm wondering if we should rename all As WooCommerce and Guttenberg use the Opinions about that? |
For me, getting translations right is more important than UPDATE: See #3219 (comment).
|
OK, got it working. It's a bit of an inconvenience to have to build this in a WordPress directory now, but it's a small price to pay for working translations. We'll need to ensure this is added to the release instructions. |
I'd suggest asking @rrennick about this to learn more about how the translation process works in WC admin. |
Actually I believe it's automatic and we need to do it only for tests.
Yeah! I sent him a message yesterday to understand how it works for them =) |
Do you mean that we're translating strings in test files? If so, is that necessary? |
Not for our automated tests, just for our user test to see if it would work (like simulating the translate.wordpress.org job).
I talked to @rrennick and looks like there was a mistake in their last release while making the current pot file - and it's the reason why their pot file is pointing to the source files. But talking to him that we would like the translators see the correct reference (to the source files), he suggested we add the |
@yscik I think it would be the ideal. Do you know a way to do it? |
I don't think we need to test this before merging. If there are issues we can open a new PR. Given this, can this PR be merged? The .pot file looks good to me. |
Yep! Just needing approval. After that, I'll update our release docs. |
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.
🥖
Changes proposed in this Pull Request
dist
files in the pot file. The cons about that is for each new dist file, we have to add it to theadditionalReferences
array here (similar to this WooCommerce script):sensei/bin/pot-dist-references.js
Lines 8 to 13 in b12c4b9
At some point, we can think some alternative to update this file automatically while building our JS files.
How it works
pot
file for the js(x) files.pot
file, merging the JSpot
file.Testing instructions
If you want to debug the whole process, you can temporarily remove the last
npm run i18n:clean
from thei18n:build
script in thepackage.json
.npm run i18n:build
sensei-lms.pot
was generated correctly.assets/onboarding/index.jsx
), rebuild, and make sure thesensei-lms.pot
was updated correctly.sensei-lms.pot
file.Testing the translations running in dev env:
npm run i18n:build
.po
file with poedit or runningmsginit -l pt_BR -o sensei-lms-pt_BR.po
in thelang
folder.msgfmt -o sensei-lms-pt_BR.mo sensei-lms-pt_BR.po
to generate the mo file.wp i18n make-json lang --no-purge
to generate the Jed file for JS messages..mo
and.json
files to/wp-content/languages/plugins
./wp-admin/admin.php?page=sensei_onboarding
) to test and check if the messages are translated./wp-admin/edit.php?post_type=course
) to test and check if the messages are translated.Other observations:
npm run i18n:build
instead ofgulp pot
(which generates only the PHP part).wp i18n make-pot
from thewp-cli
.wp i18n make-pot
give us feedback about different translator comments that we can fix in a future PR.References:
wp-pot
is restricted only to a PHP parser: https://github.com/wp-pot/wp-pot/blob/master/translation-parser.js#L5We implemented the same idea than WooCommerce i18n script process: https://github.com/woocommerce/woocommerce-admin/blob/master/CONTRIBUTING.md#helper-scripts