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

Update i18n docs to use make-json command from wp-cli #15303

Merged
merged 2 commits into from May 12, 2019

Conversation

@mkaz
Copy link
Member

commented Apr 30, 2019

Description

Updates the Internationalization documentation recommending to use the wp-cli make-json command to generate the necessary json file needed for translations.

This replaces the instructions to use the npm po2json module, it is simpler for a user to use only the wp-cli tool which is also used earlier in the documentation for creating the pot files.

There was a bug fixed in wp-cli wp-cli/i18n-command#146

Fixes #14093

How has this been tested?

Follow instructions in documentation to confirm JSON file is created and translations work.

Types of changes

Documentation.

@dianeco

This comment has been minimized.

Copy link

commented May 5, 2019

@mkaz I've followed your instructions. I have a plugin that create custom blocks which is divided into 11 .js files that contain translation strings. For the last step, when I use wp-cli to convert the po file to JSON, it creates 11 plugin-eo-[md5].json files. Is there an extra step to merge all these files into one?

@mkaz

This comment has been minimized.

Copy link
Member Author

commented May 6, 2019

@dianeco The language files are directly related to the JavaScript files, so when a JS file is enqueued WP will use the related language files when needed. So you can combine the JS together prior to translations, or it is fine to have all the additional language files.

@dianeco

This comment has been minimized.

Copy link

commented May 9, 2019

@mkaz Thanks for your answer. I use create-guten-block which combine the files into one but the command wp i18n make-pot ./ languages/myguten.pot doesn't succeed to add the translatable javascript strings into the pot file. Any idea?

@swissspidy

This comment has been minimized.

Copy link
Member

commented May 9, 2019

@dianeco Make sure you use the correct text domain throughout all of your PHP and JavaScript code. This is a best practice and required for string extraction to work properly across the board. wp i18n make-pot skips any strings with wrong missing text domains unless you use --ignore-domain.

@dianeco

This comment has been minimized.

Copy link

commented May 9, 2019

@swissspidy Thanks for your reply. Yes I use the correct text domain in the JavaScript code. The process described above works fine when I use it on the dev files (but it creates a json file for each js file).
However on production mode with all my js files combined into one, wp i18n make-pot doesn't extract the translatable javascript strings even if I use --ignore-domain.

@swissspidy

This comment has been minimized.

Copy link
Member

commented May 9, 2019

That sounds like your production JS files is all minified, so instead of having wp.i18n.__() in it there will be something like xyz(). But WP-CLI can only find __() calls. I suggest you to report an issue with the create-guten-block repository.

@mkaz

This comment has been minimized.

Copy link
Member Author

commented May 10, 2019

@swissspidy Can you take a look at this PR? I'd love to get the instructions to use make-json instead of po2json updated and out to users. Thanks!

Apply suggestions from code review
Co-Authored-By: Pascal Birchler <pascal.birchler@gmail.com>

@ajitbohra ajitbohra merged commit d77c70a into master May 12, 2019

1 check passed

Travis CI - Pull Request Build Passed
Details

@ajitbohra ajitbohra deleted the docs/14093/i18n branch May 12, 2019

@youknowriad youknowriad added this to the 5.7 (Gutenberg) milestone May 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.