Skip to content

Admin Page: Move to Core translation functions -- PART 1 - #13527

Merged
kraftbj merged 6 commits into
masterfrom
update/react-plugin-use-wordpress-i18n
Jul 17, 2020
Merged

kraftbj merged 6 commits into
masterfrom
update/react-plugin-use-wordpress-i18n

Conversation

@akirk

@akirk akirk commented Sep 24, 2019 •

Copy link
Copy Markdown
Member

Changes proposed in this Pull Request:

This will need to happen in steps so reviews are easier. This is step 1.

We're aiming to move away from the i18n-calypso tooling to handle translations. Instead we'll rely on 2 things:

  • @wordpress/i18n for most translation work: __, _n, _x, and sprintf.
  • @wordpress/element and its createInterpolateElement to handle React elements in strings.

i18n-calypso will remain in use for a few exceptions for now:

  • moment
  • numberFormat

This first PR introduces those changes for the At A Glance dashboard.

Jetpack product discussion

Does this pull request change what data or activity we track or use?

  • N/A

Testing instructions:

Nothing should change at first sight:

  • Under Jetpack > Dashboard, check how things look like everywhere on the page when you've connected your site to WordPress.com, or when Development mode is active.
  • Try with different plugins and module active / inactive to get different card statues.
  • Try with outdated plugins to see different messages.
  • If you view source on the page, you should see a new section right before the React JS bundle is loaded: react-plugin-js-translations. There are no translations here for now, as no language pack is generated yet for this JS bundle. We'll need to push an Alpha first.

Proposed changelog entry for your changes:

  • TBD

Original PR description below (before the discussion in the comments below happened)

This is a demo PR that shows how we'll be able to remove all of our uses of translate() (from i18n-calypso) within the Jetpack Dashboard so that we can move over to using language pack JSONs for this.

This could be merged as is and would have the Akismet "At a glance" use translations loaded the standard WordPress/Gutenberg way (i.e. using wp_set_script_translations()). The downside of this is that this duplicates the translations JSON in the HTML source.

To bring this over the finish line we'll also need to change our build process so that the translatable strings are picked up from the JavaScript source. We currently only ship the uglified _inc/build/admin.js and not the JavaScript clean source. If we committed the unmodified source to SVN, the strings would be extracted for translation and provided inside language packs.

To avoid duplication, the convention in building the language packs is to have the source be placed under a src/ path, so that they won't be included in the language pack.

@akirk akirk added [Status] In Progress [Focus] i18n Internationalization / i18n, adaptation to different languages labels Sep 24, 2019
@akirk
akirk requested review from a team, simison and zinigor September 24, 2019 12:26
@matticbot

Copy link
Copy Markdown
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello akirk! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D33090-code before merging this PR. Thank you!

Comment thread _inc/client/at-a-glance/akismet.jsx Resolved
@jetpackbot

jetpackbot commented Sep 24, 2019 •

Copy link
Copy Markdown
Collaborator

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

E2E results is available here (for debugging purposes): https://jetpack-e2e-dashboard.herokuapp.com/pr-13527

Scheduled Jetpack release: August 4, 2020.
Scheduled code freeze: July 28, 2020

Generated by 🚫 dangerJS against 85f720e

@jeherve jeherve added the Enhancement Changes to an existing feature — removing, adding, or changing parts of it label Sep 24, 2019
@simison

simison commented Sep 24, 2019 •

Copy link
Copy Markdown
Member

We currently only ship the uglified _inc/build/admin.js and not the JavaScript clean source. If we committed the unmodified source to SVN, the strings would be extracted for translation and provided inside language packs.

I think minified JS is fine; wp i18n was smart enough to pick strings from the bundles produced from gutenberg-extensions (built to _inc/blocks). You could confirm locally running the CLI command?

If I've understood correct, .org's process also uses wp i18n.

@akirk

akirk commented Sep 24, 2019 •

Copy link
Copy Markdown
Member Author

I think minified JS is fine; wp i18n was smart enough to pick strings from the bundles produced from gutenberg-extensions (built to _inc/blocks). You could confirm locally running the CLI command?

Nice, I just verified that my translatable strings appear with a JS source in the POT file after running wp i18n make-pot . test.pot:

#: _inc/jetpack-strings.php:75
#: _inc/build/admin.js:543
msgid "Already have a key? {{a}}Activate Akismet{{/a}}"
msgstr ""

The reason I assumed we'd need to ship the true source was because I searched for other usages of __() from @wordpress/i18n in the source and, for example, found this:

import { __, sprintf } from '@wordpress/i18n';

<p>{ sprintf( __( 'You are searching for: "%s"' ), query ) }</p>

This string is not translatable: https://translate.wordpress.org/projects/wp-plugins/jetpack/dev/de/default/?filters%5Bterm%5D=You+are+searching+for&filters%5Buser_login%5D=&filters%5Bstatus%5D=current_or_waiting_or_fuzzy_or_untranslated&filter=Filter&sort%5Bby%5D=priority&sort%5Bhow%5D=desc

The reason for why this was not picked up is the missing jetpack textdomain, if I change it to

<p>{ sprintf( __( 'You are searching for: "%s"', 'jetpack' ), query ) }</p>

It's picked up properly. So we need to keep this in mind when converting.

@akirk

akirk commented Sep 24, 2019

Copy link
Copy Markdown
Member Author

I think it'd be interesting to write a code mod for this?

@simison

simison commented Sep 24, 2019 •

Copy link
Copy Markdown
Member

Noting that WordPress/gutenberg#16374 uses <s instead of {{s and seems actually pretty close being merged as experimental API.

@stale

stale Bot commented Dec 23, 2019

Copy link
Copy Markdown

This PR has been marked as stale. This happened because:

  • It has been inactive in the past 3 months.
  • It hasn’t been labeled `[Pri] Blocker`, `[Pri] High`.

No further action is needed. But it's worth checking if this PR has clear testing instructions, is it up to date with master, and it is still valid. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.

@stale stale Bot added the [Status] Stale label Dec 23, 2019
@zinigor zinigor added this to the 8.2 milestone Dec 23, 2019
@zinigor

zinigor commented Dec 23, 2019

Copy link
Copy Markdown
Contributor

Let's look at this for the next milestone.

@zinigor zinigor self-assigned this Dec 23, 2019
@jeherve jeherve removed this from the 8.2 milestone Jan 24, 2020
@simison

simison commented Feb 20, 2020

Copy link
Copy Markdown
Member

This could now be updated to use __experimentalCreateInterpolateElement available in @wordpress/i18n (WordPress/gutenberg#17376) since Gutenberg 7.0

@simison

simison commented Apr 27, 2020 •

Copy link
Copy Markdown
Member

@wordpress/i18n now has stable createInterpolateElement.

WP 5.4 is shipped too — time to move to wp-i18n fully @jeherve @kraftbj @akirk ? :-)

@ocean90

ocean90 commented May 5, 2020

Copy link
Copy Markdown

We currently only ship the uglified _inc/build/admin.js and not the JavaScript clean source. If we committed the unmodified source to SVN, the strings would be extracted for translation and provided inside language packs.

Worth to mention that source maps are also supported. This was recently tested with BuddyPress.

@jeherve jeherve added this to the 8.7 milestone May 26, 2020
@kraftbj
kraftbj removed request for a team and zinigor June 1, 2020 19:42
@jeherve jeherve added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Jul 17, 2020
@kraftbj kraftbj added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Jul 17, 2020
@kraftbj
kraftbj merged commit 049822e into master Jul 17, 2020
@kraftbj
kraftbj deleted the update/react-plugin-use-wordpress-i18n branch July 17, 2020 16:53
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Jul 17, 2020
jeherve added a commit that referenced this pull request Jul 17, 2020
…onents

This is part 2, follow-up of #13527

Updating i18n in all components
jeherve added a commit that referenced this pull request Jul 17, 2020
… & Settings

This is part 3, follow-up of #13527

Updating i18n in all components
jeherve added a commit that referenced this pull request Jul 17, 2020
…ings

This is part 4, follow-up of #13527

Focussing on the Security tab, the Privacy tab, and the search functionality
jeherve added a commit that referenced this pull request Jul 17, 2020
…p wizard

This is part 5, follow-up of #13527

Updating all the Setup wizard elements
jeherve added a commit that referenced this pull request Jul 17, 2020
…ings, state

This is part 5, follow-up of #13527

This updates everything that's left:

- Sharing settings
- Traffic settings
- Writing settings
- State
kraftbj pushed a commit that referenced this pull request Jul 17, 2020
This is part 2, follow-up of #13527

Updating i18n in all components
kraftbj pushed a commit that referenced this pull request Jul 17, 2020
This is part 3, follow-up of #13527

Updating i18n in all components
kraftbj pushed a commit that referenced this pull request Jul 17, 2020
This is part 5, follow-up of #13527

Updating all the Setup wizard elements
kraftbj pushed a commit that referenced this pull request Jul 17, 2020
This is part 5, follow-up of #13527

This updates everything that's left:

- Sharing settings
- Traffic settings
- Writing settings
- State
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Admin Page React-powered dashboard under the Jetpack menu Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Focus] i18n Internationalization / i18n, adaptation to different languages [Pri] Normal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants