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 `i18n make-json` command #109

Merged
merged 22 commits into from Dec 4, 2018

Conversation

4 participants
@swissspidy
Copy link
Collaborator

swissspidy commented Nov 25, 2018

See https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/ to learn more about JavaScript internationalization changes in WordPress 5.0.

Plugins can opt into this new feature by using wp_set_script_translations() and providing the necessary JSON files.

There should be exactly 1 JSON file per JavaScript handle and the JSON file should only contain strings relevant for that script.

Of course, with these new JSON files there's no need for JavaScript-only strings to still be included in PO files.

This PR aims to support developers by giving them the necessary tool to create such PO und JSON files using the powers of WP-CLI.

By simply using wp i18n po2json, one can create all the necessary JSON files in the required format and even declutter the PO file afterwards.

This is perfect for anyone who can't use more complex solutions like GlotPress or very limited tools like po2json.

Fixes #108.

swissspidy added some commits Nov 25, 2018

@swissspidy swissspidy changed the title [WIP] po2json command po2json command Nov 28, 2018

@swissspidy swissspidy requested a review from wp-cli/committers Nov 28, 2018

@danielbachhuber danielbachhuber added this to the 2.0.4 milestone Nov 29, 2018

Show resolved Hide resolved src/Po2JsonCommand.php Outdated
Show resolved Hide resolved src/Po2JsonCommand.php Outdated
Show resolved Hide resolved src/Po2JsonCommand.php Outdated
Show resolved Hide resolved src/Po2JsonCommand.php Outdated
Show resolved Hide resolved src/Po2JsonCommand.php Outdated
Show resolved Hide resolved src/JedGenerator.php Outdated
Show resolved Hide resolved src/JedGenerator.php Outdated
Show resolved Hide resolved i18n-command.php Outdated
Show resolved Hide resolved features/po2json.feature Outdated
@@ -22,3 +22,12 @@
}
}
) );
WP_CLI::add_command( 'i18n po2json', '\WP_CLI\I18n\Po2JsonCommand', array(

This comment has been minimized.

@schlessera

schlessera Dec 1, 2018

Member

I'm not happy with the command name po2json. It does not really fit with how commands are named everywhere else in WP-CLI.

Here are a few suggestions (in no particular shape or order, just a brainstorm), happy to hear your thoughts:

  • extract-js
  • po extract-js
  • po split
  • make-json
  • ...

This comment has been minimized.

@swissspidy

swissspidy Dec 2, 2018

Collaborator

Oh yeah, I'm not fully happy with the command name either. I just wanted to kick things off quickly and because there's the npm command with the same name, I stuck with it.

make-json sounds interesting because we already have make-pot.

split-translations could work as well, because it actually splits up translations into multiple translation files.

This comment has been minimized.

@swissspidy

swissspidy Dec 4, 2018

Collaborator

@ocean90 Thoughts on the command name by chance? 🙂

This comment has been minimized.

@schlessera

schlessera Dec 4, 2018

Member

I think I'd go with make-json for now, but I'd change a few arguments to better fit that naming:

  • Add a --source=<extension(s)> to define what type of extensions to use for extracting the strings. This might not make immediate sense for our initial use case, but "making JSON files from translations" would not necessarily be restricted to one source. The --source flag would default to js but could also be js,php or anything else, basically.
  • Rename the --keep-source-strings flag to --prune and invert its logic. --prune would default to true but could be disabled through --no-prune or --prune=false then.

This would make the command a more universal JSON file generation. Thoughts?

schlessera and others added some commits Dec 2, 2018

Use list() to make function arguments more clear
Co-Authored-By: swissspidy <pascal.birchler@gmail.com>

@schlessera schlessera changed the title po2json command Add `i18n make-json` command Dec 4, 2018

@schlessera

This comment has been minimized.

Copy link
Member

schlessera commented Dec 4, 2018

Let's leave the discussed --source=<extension(s)> flag for a later PR, as I think it might block progress.

@swissspidy

This comment has been minimized.

Copy link
Collaborator

swissspidy commented Dec 4, 2018

Sounds good to me! Let's ship it :-)

@swissspidy swissspidy merged commit 9a8a46a into master Dec 4, 2018

2 checks passed

DEP All dependencies are resolved
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@delete-merged-branch delete-merged-branch bot deleted the po2json branch Dec 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment