-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Adding SDK POT file generation for Gutenberg blocks. #30303
Conversation
…e it's an SDK run.
Thanks for the review, @simison ! I have changed the variable name to use camelCase, as well as made the plugin only be used on SDK runs to avoid generating useless POT files when building normally. |
]; | ||
|
||
// The output directory is set when SDK runs, so we only set the POT generator override in that case. | ||
if ( outputDir ) { |
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.
Even with the comment, I would still prefer the code to tell this story better by renaming the variable something less generic. Not a biggie tho if you decide to leave it like this!
Consider someone who doesn't know anything about SDK reading this line.
Maybe hasSdkOutputDir
?
Just noting that I'm observing strings from both beta and production blocks ending up to the same file — suppose that's the goal so that we can get blocks earlier for translating than they're shipped. Full list of prod + beta blocks: wp-calypso/client/gutenberg/extensions/presets/jetpack/index.json Lines 2 to 17 in 3f05571
|
The babel plugin works great! I get the pot file when building Jetpack preset with One thing that doesn't work right now is when running
That would place files in git-ignored folder I get:
You can build any block in extensions directry this way, not just presets:
Suppose current setup where pot files is built only with
...but since the SDK and That would require setting the wp-calypso/bin/sdk/gutenberg.js Line 105 in 3f05571
I would also consider having filename something else than "extensions" — maybe just "translations" or the foldername "jetpack" for preset or block name for the rest? Another aspect is that there is also I was also thinking if we should have pot-generation turned on only as opt-in via separate CLI argument, instead of generate on each run. It doesn't seem to slow the build at all and it's nice not to think of CLI arguments, so current way seems good! |
@@ -13,6 +13,9 @@ const path = require( 'path' ); | |||
const yargsModule = require( 'yargs' ); | |||
const webpack = require( 'webpack' ); | |||
|
|||
// This environment variable will be used by the Babel plugin that makes POT files, see babel.config.js. | |||
process.env.CALYPSO_SDK_OUTPUT_DIR = yargsModule.argv.outputDir; |
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.
To express #30303 (comment) in a bit more compact way, how about we move this to bin/sdk/gutenberg.js
and change it to:
const output = outputDir || path.join( inputDir, 'build' );
process.env.CALYPSO_SDK_OUTPUT_DIR = output;
]; | ||
|
||
// The output directory is set when SDK runs, so we only set the POT generator override in that case. | ||
if ( outputDir ) { |
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.
Another (maybe easier to read since code stays in one place?) way to structure this would be by using lodash.compact
:
plugins: compact( [
outputDir && [
'@wordpress/babel-plugin-makepot',
{
...
}
],
[
'@wordpress/import-jsx-pragma',
{
scopeVariable: 'createElement',
source: '@wordpress/element',
isDefault: false,
},
],
[
'@babel/transform-react-jsx',
{
pragma: 'createElement',
},
],
] )
You can see similar pattern here:
Lines 312 to 313 in ecf929d
plugins: _.compact( [ | |
! codeSplit && new webpack.optimize.LimitChunkCountPlugin( { maxChunks: 1 } ), |
...but that's just up to code-stylistic choices. :-)
It would be nice if we were able to create You can find my efforts here: https://github.com/Automattic/wp-calypso/compare/try/sdk-gutenberg-pot-generation-per-webpack-entry It's close but I think there is a fundamental problem with both specifying a Maybe some webpack+babel wizards can help us here? |
Why would it be nice? :-)
Sure, I can have a look tomorrow (utc+3) |
I think we should aim to ship all translations to WordPress.or as soon as possible, even if the feature isn't live for everyone yet; that gives translators some time to translate everything so that when the feature actually goes live, it is already translated. As such, I am okay with having only one .pot file that contains all the strings. |
Let's drop the requirement for separate pot files for now and concentrate shipping this with one file? We can always revisit in follow up PRs if it seems like we need those files separately. |
Yes, I'm fine with doing just one POT file, my angle was just not to have the SDK having to make the decision which translations to include in what file. |
|
…1225) <!--- Provide a general summary of your changes in the Title above --> #### Changes proposed in this Pull Request: * Adapts JSON language files to be usable in WordPress client-side i18n. * Rebuilds JSON language files. * Adds a mechanism to integrate POT files that result from [block building](Automattic/wp-calypso#30303) into `jetpack-strings.php`. The whole PHP file generation pipeline now consists of one i18n-calypso run, one msgcat run, and one msgexec run that executes a bash script for every translation. * Paves the way for legacy i18n support and makes initial steps to move towards wp.i18n. #### Testing instructions: Currently blocks don't have any strings translated yet in the JSON files because the strings themselves are not present in the code. After merging this code we should be able to re-run language builds and get translated strings in blocks. * Make sure the existing i18n works properly, including existing wp-admin Settings translations. #### Proposed changelog entry for your changes: * Adapted existing Jetpack translations to be used in WordPress i18n mechanisms. Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>
…1225) <!--- Provide a general summary of your changes in the Title above --> * Adapts JSON language files to be usable in WordPress client-side i18n. * Rebuilds JSON language files. * Adds a mechanism to integrate POT files that result from [block building](Automattic/wp-calypso#30303) into `jetpack-strings.php`. The whole PHP file generation pipeline now consists of one i18n-calypso run, one msgcat run, and one msgexec run that executes a bash script for every translation. * Paves the way for legacy i18n support and makes initial steps to move towards wp.i18n. Currently blocks don't have any strings translated yet in the JSON files because the strings themselves are not present in the code. After merging this code we should be able to re-run language builds and get translated strings in blocks. * Make sure the existing i18n works properly, including existing wp-admin Settings translations. * Adapted existing Jetpack translations to be used in WordPress i18n mechanisms. Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>
This issue has been marked as stale and will be closed in seven days. This happened because:
You can keep the issue open by adding a comment. If you do, please provide additional context and explain why you’d like it to remain open. You can also close the issue yourself — if you do, please add a brief explanation. |
Let's close this, since Gutenberg blocks get i18n from WordPress.org repository. |
Fixes #30048
Changes proposed in this Pull Request
babel-plugin-makepot
plugin to the extensions folder for Gutenberg blocks. This is needed to be able to translate blocks in third party code.Testing instructions
node bin/sdk-cli.js gutenberg client/gutenberg/extensions/presets/jetpack/ --output-dir /some/folder/you/want/blocks/to/be/put
editor.js
and all other files for Gutenberg blocks you haveextensions.pot
file generated, and it contains strings from the JSX files.Now that I look at this PR, I can see that there might be a better approach, one that does not add the makepot plugin to everything, but relies on an environment variable (or other switch) that will be set when SDK runs. I'd appreciate any ideas here.