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

CSV export email messages for pt_BR, zh_CN, zh_TW fall back to en_US, instead of using user language #10149

Open
nagpai opened this issue Jan 14, 2025 · 8 comments · May be fixed by #10197
Open
Assignees
Labels
category: i18n The issue/PR is related to internationalization. focus: reporting priority: high The issue/PR is high priority—it affects lots of customers substantially, but not critically. type: bug The issue is a confirmed bug.

Comments

@nagpai
Copy link
Contributor

nagpai commented Jan 14, 2025

Email notifications for CSV exports for the following supported languages pt_BR, zh_CN, zh_TW fall back to English.

To Reproduce

  1. Browse to WP Admin -> Users -> Profile
  2. Change the profile language to any of the languages above.
  3. Run a CSV export of transactions, payouts or disputes, making sure you have more than a single pagination to trigger a server export
  4. Check the language of the email triggered, and the CSV contents. It should be in user language but is provided in US English.

Detailed observations here #10003 (review)

Additional context

@nagpai nagpai added category: i18n The issue/PR is related to internationalization. focus: reporting type: bug The issue is a confirmed bug. labels Jan 14, 2025
@haszari
Copy link
Contributor

haszari commented Jan 14, 2025

Some context about these codes:

We have a utility function convert_to_server_locale() that roughly converts the WordPress core locale type to the server supported dash-separated locales.

Another potential bug in that logic – what language would we use for emails to a site/merchant using Portuguese (Portugal)?

@Jinksi
Copy link
Member

Jinksi commented Jan 14, 2025

The server falls back to en_US if there is no matching locale found. This may be the reason for the inaccuracy, but we may need to investigate if there is any other cause.

I believe the bug causing this en_US fallback occurs before the request query params are prepared, in convert_to_server_locale().

@Jinksi
Copy link
Member

Jinksi commented Jan 14, 2025

what language would we use for emails to a site/merchant using Portuguese (Portugal)?

Transact-platform-server on WPCOM doesn't have complete Portuguese (Portugal) translations, so "English (US)" is used as a the default fallback.

It would be good to enumerate which translations we have available on server – filtering via translate.wordpress.com doesn't seem ideal. I know there is the following list in the client code, but is it accurate/maintained?

$supported = [
'ar', // Arabic.
'de', // German (Germany).
'es', // Spanish (Spain).
'fr', // French (France).
'he', // Hebrew (Israel).
'id', // Indonesian (Indonesia).
'it', // Italian (Italy).
'ja', // Japanese.
'ko', // Korean.
'nl', // Dutch (Netherlands).
'pt-br', // Portuguese (Brazil).
'ru', // Russian (Russia).
'sv', // Swedish (Sweden).
'tr', // Turkish (Turkey).
'zh-cn', // Simplified, Singapore).
'zh-tw', // Chinese Traditional (Taiwan).
];

@haszari haszari changed the title Reporting: localization of CSV export emails does not happen correctly in certain languages CSV export email messages for pt_BR, zh_CN, zh_TW fall back to en_US, instead of using user language Jan 17, 2025
@haszari haszari changed the title CSV export email messages for pt_BR, zh_CN, zh_TW fall back to en_US, instead of using user language CSV export email messages for pt_BR, zh_CN, zh_TW fall back to en_US, instead of using user language Jan 17, 2025
@haszari haszari added the priority: high The issue/PR is high priority—it affects lots of customers substantially, but not critically. label Jan 17, 2025
@haszari
Copy link
Contributor

haszari commented Jan 17, 2025

They may be the fallback language - English

Is this "sometimes" or does the bug consistently happen every time for these languages?

I'm assuming that it happens every time, in which case this is priority: high.

@Jinksi
Copy link
Member

Jinksi commented Jan 17, 2025

Is this "sometimes" or does the bug consistently happen every time for these languages?

In my testing using production transact-platform-server and Pressable, every time.

@haszari
Copy link
Contributor

haszari commented Jan 17, 2025

In my testing using production transact-platform-server and Pressable, every time.

Thanks for confirming! I strengthened the wording in reproduce steps 😁

@Jinksi Jinksi self-assigned this Jan 19, 2025
@Jinksi
Copy link
Member

Jinksi commented Jan 20, 2025

We have a utility function convert_to_server_locale() that roughly converts the WordPress core locale type to the server supported dash-separated locales.

It looks like there's an opportunity to remove a bunch of complexity here.

  1. convert_to_server_locale() is only used for the wcpaySettings.userLocale variable, so it might be better to move this logic client-side. userLocale is only used when preparing the locale query params for a request to download a CSV.
  2. This WP LocaleWPCOM-compatible language code is available in the package @automattic/languages, replacing the need for a WooPayments-specific convert_to_server_locale().

Example language entry and relevant fields from @automattic/languages:

{
  "langSlug": "pt-br",
  "name": "Português do Brasil",
  "wpLocale": "pt_BR",
}

So, rather than maintaining our own mapping, we can get the langSlug based on the current user's wpLocale (already available via WP data getCurrentUser()) and send it as the locale query param when making CSV download POST requests.

@Jinksi
Copy link
Member

Jinksi commented Jan 21, 2025

So, rather than maintaining our own mapping, we can get the langSlug based on the current user's wpLocale (already available via WP data getCurrentUser()) and send it as the locale query param when making CSV download POST requests.

Note: I've decided to reduce the complexity of this solution and move the language code conversion logic to PHP, within the REST API controllers in #10197.

I have not found a PHP package/resource with the same list of WP Locale → WPCOM Language. However, in reducing the hardcoded list to only the three that are region-specific, the maintenance burden is reduced. This approach is common across A8C (GH search), of which I found Jetpack's to be the simplest, which I've adapted and used in #10197.

@Jinksi Jinksi added this to the WooPayments 8.9.0 milestone Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: i18n The issue/PR is related to internationalization. focus: reporting priority: high The issue/PR is high priority—it affects lots of customers substantially, but not critically. type: bug The issue is a confirmed bug.
Projects
None yet
3 participants