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
Merged

Conversation

mkaz
Copy link
Member

@mkaz mkaz 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.

@mkaz mkaz added [Type] Developer Documentation Documentation for developers Internationalization (i18n) Issues or PRs related to internationalization efforts labels Apr 30, 2019
@mkaz mkaz self-assigned this Apr 30, 2019
@mkaz mkaz requested a review from swissspidy April 30, 2019 17:43
@dianeco
Copy link

dianeco 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
Copy link
Member Author

mkaz 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
Copy link

dianeco 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
Copy link
Member

@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
Copy link

dianeco 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
Copy link
Member

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
Copy link
Member Author

mkaz 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!

Co-Authored-By: Pascal Birchler <pascal.birchler@gmail.com>
@ajitbohra ajitbohra merged commit d77c70a into master May 12, 2019
@ajitbohra ajitbohra deleted the docs/14093/i18n branch May 12, 2019 11:07
@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
Labels
Internationalization (i18n) Issues or PRs related to internationalization efforts [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Internationalization with wp-cli make-json
5 participants