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

i18n: Fix translations on the Use my domain screen #57064

Merged
merged 7 commits into from
Oct 29, 2021

Conversation

sdnunca
Copy link
Contributor

@sdnunca sdnunca commented Oct 15, 2021

Changes proposed in this Pull Request

  • Adds dynamic getters to the translated properties of optionInfo objects so that __ is called every time they are accessed, to make sure the text is refreshed when translations are loaded.

Testing instructions

  1. Change your user language to a non-English language.
  2. Go to https://wordpress.com/domains/add/use-my-domain/{site-URL}
  3. Enter a test domain name, such as example.com.
  4. Make sure the mapping options are translated:

image

Related to #325-gh-Automattic/i18n-issues

@sdnunca sdnunca requested a review from a team as a code owner October 15, 2021 13:29
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Oct 15, 2021
@github-actions
Copy link

github-actions bot commented Oct 15, 2021

@matticbot
Copy link
Contributor

matticbot commented Oct 15, 2021

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Sections (~71 bytes added 📈 [gzipped])

name     parsed_size           gzip_size
domains       +642 B  (+0.0%)      +71 B  (+0.0%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Async-loaded Components (~40 bytes added 📈 [gzipped])

name                             parsed_size           gzip_size
async-load-signup-steps-domains       +306 B  (+0.1%)      +40 B  (+0.0%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

Copy link
Member

@yuliyan yuliyan left a comment

Choose a reason for hiding this comment

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

The Use a domain I own title on the initial screen and the Suggested setup title, when you select the Connection your domain option, still appear untranslated.

topText: __( 'Manage your domain directly on WordPress.com' ),
learnMoreLink: INCOMING_DOMAIN_TRANSFER,
benefits: [
transferSupported,
Copy link
Member

Choose a reason for hiding this comment

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

I suppose, these were extracted as separate constants for better readability?

@delputnam
Copy link
Contributor

@sdnunca Thanks for the PR. Is this the recommended way to ensure that the correct text is rendered after the translated strings are loaded?

It feels redundant to have to list all of the strings twice. Is there a better way we (@Automattic/nomado) could have handled this to avoid this issue?

@rafaelgallani
Copy link
Contributor

@sdnunca Thanks for the PR!
I was working on it as a part of #56366, so I had already addressed the points commented by @yuliyan.
I'll cherry-pick and change them a bit to make them similar to your commits and push them to your branch 😄

@sdnunca
Copy link
Contributor Author

sdnunca commented Oct 20, 2021

@delputnam The redundant strings felt weird to me as well. I've updated the PR to use getters directly when creating the object.

@rafaelgalani Thank you so much for your work on this. Apologies for the inconvenience, I was not aware you're already looking into this.

@yuliyan Do you see any potential issues with using getters this way? I've double checked to make sure the strings are still extracted correctly and it seems fine.

@yuliyan
Copy link
Member

yuliyan commented Oct 20, 2021

@yuliyan Do you see any potential issues with using getters this way? I've double checked to make sure the strings are still extracted correctly and it seems fine.

@sdnunca, IIRC, initially I got some build errors with the getter syntax and had to switch to Object.defineProperty with the duplicated strings, but that doesn't seem to be applicable anymore. I don't think there'll be any problems, so it looks like a nice improvement!

@rafaelgallani rafaelgallani force-pushed the fix/translations-on-use-my-domain-page branch from 6fa2478 to bf1c5f8 Compare October 27, 2021 19:17
@rafaelgallani
Copy link
Contributor

Rebasing on trunk

@rafaelgallani
Copy link
Contributor

rafaelgallani commented Oct 27, 2021

@yuliyan Could you please take one last look at it again? I'll merge this PR since some other developments we're doing depend on it.
I just rebased it with the latest trunk changes. I tested it again and it looks good to me both code and translation-wise. 😄

Copy link
Member

@yuliyan yuliyan left a comment

Choose a reason for hiding this comment

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

@rafaelgalani, I'm getting reference errors when I go to domains/add/use-my-domain/, likely due to used undefined __ dependency in use-my-domain/index.js.

@@ -304,7 +305,7 @@ function UseMyDomain( {
/* translators: %s - the name of the domain the user will add to their site */
return sprintf( __( 'Use a domain I own: %s' ), domainName );
}
}, [ domainName, mode, inputMode ] );
}, [ domainName, mode, inputMode, __ ] );
Copy link
Member

Choose a reason for hiding this comment

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

I think you forgot to call useI18n hook and as a result __ is not defined in the scope.

Copy link
Contributor

@rafaelgallani rafaelgallani Oct 28, 2021

Choose a reason for hiding this comment

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

That's weird - even weirder that this is not even coming from this PR, anyway, just added it, thanks 😄

/**
* Define properties with translatable strings getters.
*/
Object.defineProperties( stepsHeading, {
Copy link
Member

Choose a reason for hiding this comment

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

Object.defineProperties here could probably be avoided if you use the getter syntax, similar to how it's been done in use-my-domain/utilities/option-info.js

@@ -23,15 +36,15 @@ export const connectADomainStepsDefinition = {
[ stepSlug.SUGGESTED_LOGIN ]: {
mode: modeType.SUGGESTED,
step: stepType.LOG_IN_TO_PROVIDER,
name: __( 'Log in to provider' ),
name: labels[ stepSlug.SUGGESTED_LOGIN ](),
Copy link
Member

@yuliyan yuliyan Oct 28, 2021

Choose a reason for hiding this comment

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

I don't think this would work - labels[ stepSlug.SUGGESTED_LOGIN ] will only be called once during the initial property definition, whereas it's expected __ to be always executed when property is accessed.
I missed the Object.defineProperties loop at the bottom. However, I think this can also be simplified using the getter syntax.

@rafaelgallani
Copy link
Contributor

@yuliyan Done! Thanks for your review. Can you please take one last look? 😄
I re-tested it and it all looks good - everything correctly translated.

@yuliyan yuliyan self-requested a review October 29, 2021 12:45
Copy link
Member

@yuliyan yuliyan left a comment

Choose a reason for hiding this comment

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

Tested again and it seems to be working fine. I couldn't spot any issues, so it LGTM 🚀

@rafaelgallani
Copy link
Contributor

@yuliyan Thank you! Merging 🚀

@rafaelgallani rafaelgallani merged commit f8c7fe5 into trunk Oct 29, 2021
@rafaelgallani rafaelgallani deleted the fix/translations-on-use-my-domain-page branch October 29, 2021 15:21
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Oct 29, 2021
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.

5 participants