-
Notifications
You must be signed in to change notification settings - Fork 281
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
Translation files added to prod bundle #551
base: master
Are you sure you want to change the base?
Conversation
- Use wp-cli to generate the `.pot` file instead of `gulp-pot`. - Copied translation files include string replacement - Refactor gulp tests and add coverage for translations and prod string replace files.
Thank you @ataylorme for your work on this. Here are some comments:
Here's an example of what produces {"translation-revision-date":"YEAR-MO-DA HO:MI+ZONE","generator":"WP-CLI\/2.2.0","source":"assets\/js\/src\/editor\/editor-filters.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"fr","plural-forms":"nplurals=2; plural=(n != 1);"},"Checkmark":["Case \u00e0 cocher"]}}} |
I think
@benoitchantre for WP Rig do you think we can support generating |
There's also a WP-CLI command for that:
When the theme is distributed on wp.org, everything is handled by translate.wordpress.org When the theme is private, all these files are needed
If we want to be able to test translations in When we run |
Aside from no I wrote some test cases to make sure the production task runs as expected. I need to write some more test cases. If something isn't working for translations I can add more test cases for that here but otherwise, I think additional cases for the prod build, like making sure PHP files are copied and string replacement has been run, can be a follow-up issue/PR. |
For the tests, I tried using the The other tests that @phated helped me set up on gulp office hours test one task/function but the bundle task is different since it is a lot of other tasks in series/parallel and that is hard to mock. So in this case, rather than mocking, I am actually scaffolding real files, running the gulp bundle task, running the tests, then tearing down. |
Actually, I take back that this is all done except one thing
|
@ataylorme You can probably use gulp-potomo, which uses the |
- Properly generate `.mo` files with the new gulp task `generateMOfiles` - Test for `.json` files created from `.po` files when doing the production build
@benoitchantre never mind, I was able to use the WordPress core French
I think this is ready for final review/testing and then can be merged. Definitely, a more complex workflow and I am glad I was able to write tests to know all the steps are working as intended. |
Thank you for your work on this @ataylorme. I’ll test that in the next few days. |
@ataylorme Thank you for your work on this. This is a complicated workflow. Here's the results of my tests:
I still need to do more tests with
Interesting reading: Internationalization in WordPress 5.0 from Pascal Birchler. |
We are using I think I will try to remove
We will need to document the Right now there is a config option I have been thinking about this and do not know if we should enable all the translation functionality in the default |
I don't get these errors. This pull request doesn't edit any npm run build 07/22/19 at 7:18:03
> [email protected] build /Users/andrewtaylor/Sites/wprig/wp-content/themes/wprig
> gulp buildDev
[07:20:06] Requiring external module @babel/register
[07:20:09] Using gulpfile ~/Sites/wprig/wp-content/themes/wprig/gulpfile.babel.js
[07:20:09] Starting 'buildDev'...
[07:20:09] Starting 'php'...
[07:20:09] Starting 'images'...
[07:20:09] Starting 'scripts'...
[07:20:09] Starting 'translate'...
[07:20:09] Starting 'generateMOfiles'...
[07:20:09] Starting 'styles'...
[07:20:10] Finished 'generateMOfiles' after 825 ms
> "vendor/wp-cli/wp-cli/bin/wp" 'i18n' 'make-pot' '/Users/andrewtaylor/Sites/wprig/wp-content/themes/wprig' '/Users/andrewtaylor/Sites/wprig/wp-content/themes/wprig/languages/wp-rig.pot' '--exclude=vendor,node_modules,.git,gulp,tests,config,assets/js/src,assets/css/src,optional'
> "vendor/wp-cli/wp-cli/bin/wp" 'i18n' 'make-json' '/Users/andrewtaylor/Sites/wprig/wp-content/themes/wprig/languages' '--no-purge'
[07:20:12] Finished 'translate' after 2.48 s
[07:20:12] gulp-imagemin: Minified 0 images
[07:20:12] Finished 'images' after 3.06 s
[07:20:15] Finished 'scripts' after 5.44 s
[07:20:17] Finished 'styles' after 8.01 s
[07:20:17] Starting 'editorStyles'...
[07:20:18] Finished 'editorStyles' after 521 ms
[07:20:30] Finished 'php' after 21 s
[07:20:30] Finished 'buildDev' after 21 s |
* WP Rig doesn't have any translatable strings in JS. | ||
* Once there are some, we can run this test. | ||
* failMessage = `The .pot file ${ filePath } does not contain any .js translations`; | ||
* expect( fileContents, failMessage ).toContain( '.js' ); |
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.
@benoitchantre I'm not testing for JS translation in the dev .pot
since we don't have any translatable strings yet.
|
||
// Test that the .pot file contains .js translations | ||
failMessage = `The .pot file ${ filePath } does not contain any .js translations`; | ||
expect( fileContents, failMessage ).toContain( '.js' ); |
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 am testing JS translations in the prod .pot
file since I am mocking the editor-filters.js
file from #379
Renaming JSON files to the correct handle name might be tough as I don't know how to decode the hash. |
I think keeping i18n function names in the minified files is also safer for themes that will be uploaded to wp.org |
I’m in favor to remove it from the build task and to keep it callable on its own. It will speed up the build task. Another argument in that direction is that people who build themes for wp.org don’t need to create a |
So generating the |
The error was on my side only: I haven't seen that I had an unwanted subdirectory. |
@benoitchantre there is some more conversation on It seems that generating a I don't think we can generate the At this point, I feel out of options. Let me know if you have any suggestions |
@benoitchantre summary of the discussion over on wp-cli is that minified files are not supported for translations.
I am going to recommend two things:
I don't think this will be a breaking change as WP Rig currently does not generate translation files ( What are your thoughts? |
@ataylorme I have tested that now with a plugin. It can work under the following conditions:
If these conditions are met, For info, I have asked in the WP-CLi Slack channel if this is the recommended way. Another direction is to use I'm also in favor to make translation file generation opt-in instead of opt-out for the following reasons:
Update: I just found the following related WP CLI i18n issues (one is from you).
Following your idea, I think that, minification should only be disabled when the theme as internationalized JS files. |
If the I'm at WP Campus still but I think you and I should schedule some time to discuss this next week. I've spent many hours on this and we still haven't reached a solution. I think we still need to ask if this is something WP Rig should do or, if like IE11 support, we leave the generation of all the translation files up to the user. |
Thank you for all your work @ataylorme. Your solution works well with PHP files, and that's already a big improvement from what we have now. Maybe we can move forward with that already and wait for improvements in WP-CLI path handling when generating JSON files. I'll be on holidays tomorrow evening until August 19, but I'll keep an eye on GitHub and try to schedule some time to discuss this topic with you. |
@ataylorme As discussed in Slack, here's a summary of the steps for the gulp process. Javascript translation will be handled later (waiting for improvements on
|
@ataylorme Do you have some time to update this PR? |
@benoitchantre not currently. I have been very busy with work and personal life recently 😞 |
Description
Addresses issue #512.
.pot
file instead ofgulp-pot
.List of changes
Checklist: