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

Add Jetpack and Layout Grid translations #4359

Merged
merged 11 commits into from
Dec 27, 2021

Conversation

fluiddot
Copy link
Contributor

@fluiddot fluiddot commented Dec 9, 2021

Fixes #2615

Description

This PR adds the translation files for localizing Jetpack blocks and the Layout Grid block (block experiments).

I'd like to note that, although this PR adds the missing translations, it's only the first part of the process of the incorporation process, as these changes don't bring the logic for updating them.

Translation files

For this purpose, a new folder located at src/i18n-translations has been created and contains the translations for each project. These files have been generated as part of a different PR (#4366), where optimized translation files will be produced including only the strings used by the native version of the editor.

NOTE: In the future, this folder won't be necessary as translations will be generated on the fly via a new command and when producing the JS bundle.

POT files

For the strings that are not part of the web version and therefore not included in the plugin's GlotPress project, we have to include them in the localization strings files (bundle/ios/GutenbergNativeTranslations.swift / bundle/android/strings.xml), exactly the same as we do for the Gutenberg strings.

This implied adding new NPM commands to generate the required POT files and updating the scripts we use for generating the localization strings files (po2swift.js / po2android.js), so they support multiple POT files as now we'll have one file each Gutenberg, Jetpack, and Layout Grid projects.

NOTE: I'm working on a new command to unify the POT files generation into a single one, so eventually, we won't need to add extra commands when adding translations of new plugins.

Localization strings files

The strings added to bundle/ios/GutenbergNativeTranslations.swift and bundle/android/strings.xml files are strings coming from Jetpack and Layout Grid plugins that require translation as they're only referenced in .native.js files.

To test

Verify that localization strings files are not modified

  • Run command: npm run genstrings
  • Observe that neither bundle/ios/GutenbergNativeTranslations.swift and bundle/android/strings.xml are modified.

Verify that Jetpack translations are present

  1. Change the device's language to non-English.
  2. Open the app.
  3. Insert a Jetpack block (i.e.: Contact Info or Story blocks)
  4. Observe that strings related to the block are translated to the selected language.
  5. If any string remains untranslated, verify that is included in the localization strings files (bundle/ios/GutenbergNativeTranslations.swift / bundle/android/strings.xml).

Verify that Layout Grid translations are present

  1. Change the device's language to non-English.
  2. Open the app.
  3. Insert the Layout Grid block
  4. Observe that strings related to the block are translated to the selected language.
  5. If any string remains untranslated, verify that is included in the localization strings files (bundle/ios/GutenbergNativeTranslations.swift / bundle/android/strings.xml).

NOTE: I noticed that some strings of the Layout Grid block are not translated, looks like this is caused because they're not retrieved by the correct domain (reference) hence, they're not being included in the GlotPress project. We'll address this in a separate PR.

Click here to display screenshot

PR submission checklist:

  • I have considered adding unit tests where possible.
  • I have considered if this change warrants user-facing release notes more info and have added them to RELEASE-NOTES.txt if necessary.

@fluiddot fluiddot self-assigned this Dec 9, 2021
Comment on lines +77 to +82
"makepot:android:gutenberg": "npm run wp -- i18n make-pot ./gutenberg/packages --include=*.native.js,*.android.js --exclude=test/*,e2e-tests/*,build/*,build-module/*,build-style/* --skip-php --subtract=./gutenberg.pot --ignore-domain gutenberg-android.pot",
"makepot:android:jetpack": "npm run wp -- i18n make-pot ./jetpack/projects/plugins/jetpack/extensions --include=*.native.js,*.android.js --exclude=test/*,e2e-tests/*,build/*,build-module/*,build-style/* --skip-php --subtract=./jetpack.pot --ignore-domain jetpack-android.pot",
"makepot:android:layout-grid": "npm run wp -- i18n make-pot ./block-experiments/blocks/layout-grid --include=*.native.js,*.android.js --exclude=test/*,e2e-tests/*,build/*,build-module/*,build-style/* --skip-php --subtract=./layout-grid.pot --ignore-domain layout-grid-android.pot",
"makepot:ios:gutenberg": "npm run wp -- i18n make-pot ./gutenberg/packages --include=*.native.js,*.ios.js --exclude=test/*,e2e-tests/*,build/*,build-module/*,build-style/* --skip-php --subtract=./gutenberg.pot --ignore-domain gutenberg-ios.pot",
"makepot:ios:jetpack": "npm run wp -- i18n make-pot ./jetpack/projects/plugins/jetpack/extensions --include=*.native.js,*.ios.js --exclude=test/*,e2e-tests/*,build/*,build-module/*,build-style/* --skip-php --subtract=./jetpack.pot --ignore-domain jetpack-ios.pot",
"makepot:ios:layout-grid": "npm run wp -- i18n make-pot ./block-experiments/blocks/layout-grid --include=*.native.js,*.ios.js --exclude=test/*,e2e-tests/*,build/*,build-module/*,build-style/* --skip-php --subtract=./layout-grid.pot --ignore-domain layout-grid-ios.pot",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generate POT files for each plugin including Gutenberg. This approach won't scale easily as we add more plugins, so I'll provide in a new PR a way to unify the POT files creation in a single command.

Comment on lines +86 to +87
"makepot:jetpack": "npm run wp -- i18n make-pot ./jetpack/projects/plugins/jetpack/extensions --exclude=test/*,e2e-tests/*,build/*,build-module/*,build-style/*,*.native.js,*.ios.js,*.android.js,bundle/* --ignore-domain jetpack.pot",
"makepot:layout-grid": "npm run wp -- i18n make-pot ./block-experiments/blocks/layout-grid --exclude=test/*,e2e-tests/*,build/*,build-module/*,build-style/*,*.native.js,*.ios.js,*.android.js,bundle/* --ignore-domain layout-grid.pot",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to Gutenberg, we need to generate these POT files for each plugin to subtract strings on makepot:<platform>:<plugin> above commands.

Comment on lines +90 to +91
"genstrings:android": "npm run makepot:android:gutenberg && npm run makepot:android:jetpack && npm run makepot:android:layout-grid && ./bin/po2android.js bundle/android/strings.xml gutenberg-android.pot jetpack-android.pot layout-grid-android.pot",
"genstrings:ios": "npm run makepot:ios:gutenberg && npm run makepot:ios:jetpack && npm run makepot:ios:layout-grid && ./bin/po2swift.js bundle/ios/GutenbergNativeTranslations.swift gutenberg-ios.pot jetpack-ios.pot layout-grid-ios.pot",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we do for Gutenberg, we have also to include the POT files generated for each plugin (Jetpack + Layout Grid) when generating the localization strings files.

Comment on lines +125 to +126
const potFilesContent = potFiles.map( (file) => fs.readFileSync( file ) );
const xmlOutput = po2Android( potFilesContent );
Copy link
Contributor Author

@fluiddot fluiddot Dec 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the po2android and po2ios scripts support multiple POT files, they basically merge all strings into a single object that is later on used for generating the localization strings files.

return { ...result, ...po.translations[ '' ] };


export default function setupBlockExperiments( capabilities ) {
const LAYOUT_GRID_LOCALE_DOMAIN = 'layout-grid';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The domain for the Layout Grid block is layout-grid, here you can see an example.

@@ -26,6 +28,8 @@ const supportedJetpackBlocks = {
},
};

const JETPACK_LOCALE_DOMAIN = 'jetpack';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The domain for Jetpack is jetpack, here you can see an example.

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Dec 15, 2021

Wanna run full suite of Android and iOS UI tests? Click here and 'Approve' CI job!

@fluiddot fluiddot marked this pull request as ready for review December 15, 2021 12:11
@mchowning
Copy link
Contributor

I've got a bit of a task backlog right now, so I won't be able to get to this until next week. Could you take a look at this @jhnstn ?

@fluiddot fluiddot requested a review from jhnstn December 16, 2021 18:43
@fluiddot fluiddot mentioned this pull request Dec 17, 2021
2 tasks
Copy link
Member

@jhnstn jhnstn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good.
I verified that none of the strings were changed via genstrings command.
I did notice that 'ADD IMAGE' is not translated in the Jetpack story block:

Screen Shot 2021-12-23 at 11 27 03 AM
I did find the string in bundle/android/strings.xml as is noted in the test steps

@fluiddot fluiddot deleted the add/jetpack-layout-grid-translations branch December 27, 2021 15:11
@mkevins mkevins mentioned this pull request Jan 7, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strings from Jetpack are not included in the bundle
3 participants