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: Add AI Translations Banner #96733

Open
wants to merge 9 commits into
base: trunk
Choose a base branch
from
Open

Conversation

yuliyan
Copy link
Member

@yuliyan yuliyan commented Nov 25, 2024

Related to Automattic/i18n-issues#886

Proposed Changes

  • Display banner about the AI translated locales (Norwegian, Polish, Finish, Thai, Greek, or Hungarian) for users that:
    • Users that have their browser primary language set to one of the AI translated locales, and use English on their WordPress.com account.
    • Users that have their browser primary language set to one of the AI translated locales, and use any of the AI translated locales on their WordPress.com account.

Preview:
AbkHhvVThWuQyNRb

Why are these changes being made?

  • We'd like to notify users about the machine translated locales.

Testing Instructions

  • Apply code-D167396.
  • Set the primary language of your browser to one of the machine translated locales - Norwegian, Polish, Finish, Thai, Greek, or Hungarian.
  • Change your WordPress.com account language to English.
  • Visit the home screen - /home/.
  • Confirm the banner is being displayed.
  • Change your WordPress.com account language to one of the machine translated locales - Norwegian, Polish, Finish, Thai, Greek, or Hungarian.
  • Visit the home screen again - /home/.
  • Confirm the banner is displayed again but without the CTA.
  • Change your account to any other language and confirm the banner is no longer displayed.

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@matticbot
Copy link
Contributor

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • happy-blocks
  • help-center
  • notifications
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug add/ai-translations-banner on your sandbox.

@matticbot
Copy link
Contributor

matticbot commented Nov 25, 2024

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

App Entrypoints (~58 bytes added 📈 [gzipped])

name                 parsed_size           gzip_size
entry-login               +433 B  (+0.0%)      +58 B  (+0.0%)
entry-subscriptions        +75 B  (+0.0%)      +32 B  (+0.0%)
entry-stepper              +75 B  (+0.0%)      +32 B  (+0.0%)
entry-main                 +75 B  (+0.0%)      +32 B  (+0.0%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Sections (~552 bytes added 📈 [gzipped])

name             parsed_size           gzip_size
home                 +1679 B  (+0.1%)     +496 B  (+0.1%)
signup                +358 B  (+0.1%)      +25 B  (+0.0%)
jetpack-connect       +358 B  (+0.0%)      +31 B  (+0.0%)
accept-invite         +358 B  (+0.2%)      +25 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.

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.

@yuliyan yuliyan force-pushed the add/ai-translations-banner branch from 0f48c83 to bf633e6 Compare December 9, 2024 10:40
@yuliyan yuliyan marked this pull request as ready for review December 9, 2024 10:48
@yuliyan yuliyan requested a review from a team as a code owner December 9, 2024 10:48
@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 Dec 9, 2024
@d-alleyne
Copy link
Contributor

Confirmed that the AI Translation bar appears

User's Browser Language is set to Norwegian, but WP Account is set to English

NB

User's Browser and WP Account set to Norwegian

User account in Norwegian

packages/i18n-utils/src/utils.ts Outdated Show resolved Hide resolved
return;
}

const language = getLanguage( localeSuggestions?.[ 0 ]?.locale );
Copy link
Contributor

Choose a reason for hiding this comment

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

In my test case I've changed my WordPress.com locale to Polish and my browser languages were set to Norwegian, Thai and Polish. Going to /home I got a banner asking to switch to Norwegian without a CTA. I think that it would be more consistent to change the logic to:

  1. If user locale is English and localeSuggestions contains AI Translated Locale - show the banner for the first suggested locale with the CTA.
  2. If user locale is contained in AI Translated Locale - show the banner for the user locale without the CTA.
Screenshot 2024-12-11 at 00 18 25

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, it makes sense! I've updated the PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Works pretty well! I did find two more edge cases:

  1. When the Display interface in English checkbox is selected, the notification isn't being shown.
  2. If my UI locale is set to an AI Translated Locale, but locale-guess doesn't return any of the AI translated locales, the notification also won't be shown.

Copy link
Contributor

Choose a reason for hiding this comment

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

Here're some test cases I can think of:

  1. UI locale is English, browser locales contain one of the AI locales - show the prompt for top detected browser locale, with CTA.
  2. UI locale is English, browser locales don't contain any of the AI locales - don't show the prompt
  3. UI locale is AI locale without the 'show english' checkbox, browser locales contain the AI locale - show the prompt for user locale, without CTA.
  4. UI locale is AI locale without the 'show english' checkbox, browser locales contain other AI locale - show the prompt for user locale, without CTA.
  5. UI locale is AI locale without the 'show english' checkbox, browser locales contain no AI locales - show the prompt for user locale, without CTA.
  6. UI locale is AI locale with the 'show english' checkbox - same as 3-5?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. When the Display interface in English checkbox is selected, the notification isn't being shown.

Could you provide the exact steps you used for 1? I tested setting my UI to Polish with the Display Interface in English preference and the banner displayed as expected.

  1. If my UI locale is set to an AI Translated Locale, but locale-guess doesn't return any of the AI translated locales, the notification also won't be shown.

Updated the logic to handle the case.

Here're some test cases I can think of:

These all seem to test well. Did you experience anything unexpected?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you provide the exact steps you used for 1?

Can't reproduce it right now, so it might've a different case. I do see an issue with test case 7 (user locale is Norwegian with "show english" checkbox, browser locales are Thai, German, Dutch) where the notification shows a prompt for Thai with a CTA.

Updated the logic to handle the case.

Test case 5 fails for me. Steps to reproduce: sandbox public-api with code-D167396, set user locale to Norwegian Bokmal, set Chrome top browser languages to German / Dutch / Japanese, open the site home for a simple site. locale-guess API call returns de/ja/nl and the site home shows no notification and some card stuck in loading state. Tested both on calypso.live and locale instance.

Screenshot 2024-12-12 at 21 10 55

Lastly, are the clicks on support link and /me/account link being captured as track events?

Copy link
Member Author

Choose a reason for hiding this comment

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

Lastly, are the clicks on support link and /me/account link being captured as track events?

Yes, CTA clicks are tracked as well as dismissing the notice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can't reproduce it right now, so it might've a different case. I do see an issue with test case 7 (user locale is Norwegian with "show english" checkbox, browser locales are Thai, German, Dutch) where the notification shows a prompt for Thai with a CTA.

I switched to reading the locale from the user object, rather than reading it from i18n-calypso. With this change, we should now have the expected behavior with the "Display interface in English" checkbox.

Test case 5 fails for me. Steps to reproduce: sandbox public-api with code-D167396, set user locale to Norwegian Bokmal, set Chrome top browser languages to German / Dutch / Japanese, open the site home for a simple site. locale-guess API call returns de/ja/nl and the site home shows no notification and some card stuck in loading state. Tested both on calypso.live and locale instance.

I followed the steps for test case 5 and it works as expected. The infinite loading state of the card below that you mentioned is unrelated to the translations notice banner, but it makes me think that there might be some other problem on your end. Could you inspect the network request and see if anything is failing there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants