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 Exports: Simplify localization by setting export language to that in user profile settings #10003

Open
wants to merge 36 commits into
base: develop
Choose a base branch
from

Conversation

nagpai
Copy link
Contributor

@nagpai nagpai commented Dec 19, 2024

Fixes #9971

Caution

Please do not merge this PR. It is still under discussion.

Changes proposed in this Pull Request

  • Make CSV exports via server localized to the language set in WP Admin > Users > Profile > Language
  • Remove redundant code:
    • Language selection modal that appears when doing CSV export. That looked like this:

image

  • Language selections within Payments > Settings > Reporting ( the reporting section will be removed since it has no other options ) Appears like this if you select Spanish as site language:

Testing instructions

  • Check out develop branch and do these steps:

  • Make sure the site has more than 25 transactions or override code to trigger server export only

  • Change site language to non-english - Say Spanish or French ( from WP Admin > Settings > Site language )

  • Browse to Payments > Settings . Here you should see a section that translates to Reports. It should have an option to select the language of the CSV export, similar to the screenshot above. Do not change anything here

  • Browse to Payments > Transactions section ( menu items will appear in the language you chose )

  • Try doing a CSV export, it will show a modal similar to the screenshot above.

  • Now checkout this branch

  • You should no longer see a Reports section within Payments > Settings

  • Change the site language back to English.

  • Change the language in User > Profile > Language to a non English language.

  • Clicking export button for CSV, should no longer show a language selection modal

  • The exported file should show the correct language as per what was selected within Users > Profile > Language

  • If you test this on a Pressable site, you should see the email sent in the correct language too.

Notes


  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Post merge

@botwoo
Copy link
Collaborator

botwoo commented Dec 19, 2024

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 10003 or branch name update/9971-simplify-localization-csv-export in your-test.site/wp-admin/admin.php?page=jetpack-beta&plugin=woocommerce-payments

Option 2. Jurassic Ninja - available for logged-in A12s

🚀 Launch a JN site with this branch 🚀

ℹ️ Install this Tampermonkey script to get more options.


Build info:

  • Latest commit: 147621d
  • Build time: 2025-01-13 23:19:28 UTC

Note: the build is updated when a new commit is pushed to this PR.

Copy link
Contributor

github-actions bot commented Dec 19, 2024

Size Change: -2.52 kB (0%)

Total Size: 1.36 MB

Filename Size Change
release/woocommerce-payments/dist/index-rtl.css 39.3 kB -143 B (0%)
release/woocommerce-payments/dist/index.css 39.3 kB -157 B (0%)
release/woocommerce-payments/dist/index.js 301 kB -1.65 kB (-1%)
release/woocommerce-payments/dist/multi-currency-switcher-block.js 60.9 kB -55 B (0%)
release/woocommerce-payments/dist/multi-currency.js 57.6 kB -29 B (0%)
release/woocommerce-payments/dist/order.js 42.3 kB -35 B (0%)
release/woocommerce-payments/dist/payment-gateways.js 38.7 kB -38 B (0%)
release/woocommerce-payments/dist/settings-rtl.css 11.6 kB -63 B (-1%)
release/woocommerce-payments/dist/settings.css 11.5 kB -44 B (0%)
release/woocommerce-payments/dist/settings.js 224 kB -306 B (0%)
ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.37 kB
release/woocommerce-payments/assets/css/admin.rtl.css 1.37 kB
release/woocommerce-payments/assets/css/success.css 182 B
release/woocommerce-payments/assets/css/success.rtl.css 184 B
release/woocommerce-payments/dist/blocks-checkout-rtl.css 2.64 kB
release/woocommerce-payments/dist/blocks-checkout.css 2.64 kB
release/woocommerce-payments/dist/blocks-checkout.js 55.6 kB
release/woocommerce-payments/dist/cart-block.js 17.2 kB
release/woocommerce-payments/dist/cart.js 5.73 kB
release/woocommerce-payments/dist/checkout-rtl.css 1.13 kB
release/woocommerce-payments/dist/checkout.css 1.13 kB
release/woocommerce-payments/dist/checkout.js 33.6 kB
release/woocommerce-payments/dist/express-checkout-rtl.css 229 B
release/woocommerce-payments/dist/express-checkout.css 229 B
release/woocommerce-payments/dist/express-checkout.js 15.7 kB
release/woocommerce-payments/dist/frontend-tracks.js 854 B
release/woocommerce-payments/dist/multi-currency-analytics.js 1.08 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 4.47 kB
release/woocommerce-payments/dist/multi-currency.css 4.47 kB
release/woocommerce-payments/dist/order-rtl.css 730 B
release/woocommerce-payments/dist/order.css 730 B
release/woocommerce-payments/dist/payment-gateways-rtl.css 1.33 kB
release/woocommerce-payments/dist/payment-gateways.css 1.33 kB
release/woocommerce-payments/dist/plugins-page-rtl.css 386 B
release/woocommerce-payments/dist/plugins-page.css 386 B
release/woocommerce-payments/dist/plugins-page.js 20.1 kB
release/woocommerce-payments/dist/product-details-rtl.css 433 B
release/woocommerce-payments/dist/product-details.css 436 B
release/woocommerce-payments/dist/product-details.js 12.5 kB
release/woocommerce-payments/dist/subscription-edit-page.js 703 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 524 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 524 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 20.2 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 730 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 19.3 kB
release/woocommerce-payments/dist/tokenized-express-checkout-rtl.css 229 B
release/woocommerce-payments/dist/tokenized-express-checkout.css 229 B
release/woocommerce-payments/dist/tokenized-express-checkout.js 16.6 kB
release/woocommerce-payments/dist/tos-rtl.css 235 B
release/woocommerce-payments/dist/tos.css 235 B
release/woocommerce-payments/dist/tos.js 21.8 kB
release/woocommerce-payments/dist/woopay-direct-checkout.js 6.13 kB
release/woocommerce-payments/dist/woopay-express-button.js 25 kB
release/woocommerce-payments/dist/woopay-rtl.css 4.31 kB
release/woocommerce-payments/dist/woopay.css 4.28 kB
release/woocommerce-payments/dist/woopay.js 71 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 625 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 814 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.46 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/jetpack-script-data.js 772 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.02 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/script-data.js 69 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/babel.config.js 163 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.css 2.47 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.js 14.2 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.rtl.css 2.47 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.css 10 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.js 28.4 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.rtl.css 10 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.js 280 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.rtl.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.css 625 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.js 333 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.rtl.css 626 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-users.js 424 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-ajax.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 585 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.css 215 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.css 721 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.js 412 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-users.js 632 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.04 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-empty-state.css 294 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 408 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.59 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 301 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 746 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 574 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 414 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 543 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 9.4 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.78 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.84 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 545 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.52 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.2 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.7 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 507 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 358 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 428 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 782 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.09 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.26 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 391 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.04 kB

compressed-size-action

@nagpai nagpai changed the title WIP - Update/9971 simplify localization csv export CSV Exports: Simplify localization by setting export language to that in site settings. Dec 20, 2024
@nagpai nagpai changed the title CSV Exports: Simplify localization by setting export language to that in site settings. CSV Exports: Simplify localization by setting export language to that in site settings Dec 20, 2024
@nagpai nagpai marked this pull request as ready for review December 26, 2024 11:35
@nagpai nagpai requested a review from a team December 26, 2024 11:36
@nagpai nagpai changed the title CSV Exports: Simplify localization by setting export language to that in site settings CSV Exports: Simplify localization by setting export language to that in user profile settings Jan 2, 2025
@Jinksi Jinksi self-requested a review January 7, 2025 00:32
Copy link
Member

@Jinksi Jinksi left a comment

Choose a reason for hiding this comment

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

@nagpai I've conducted some testing of this and found that the server-generated CSV is not being translated to the expected language when using this branch:

  1. Using Pressable site with production transact-platform-server
  2. Change site language to Español
  3. Change user language to Nederlands
  4. develop
    • Download client-side CSV – exported CSV used user profile language
    • Download server-export CSV
      • Modal shown
      • Exported CSV only showed English or site language – expected to see user profile language as an option ⚠️
      • Email also localised to site language when selected via modal or Payments → Settings.
  • This branch
    • Download client-side CSV – exported CSV used user profile language
    • Download server-export CSV
      • Modal not shown ✅
      • Exported CSV shown in English ⚠️ expected site or user profile language
      • Email also in English ⚠️ expected site or user profile language
      • Note that the locale query params in the browser request to /transactions/download are locale=nl_NL&_locale=user
      • Language selection item in Payments → Settings is no longer shown ✅

I haven't explored the cause yet but will investigate why the locale is not being respected, suspecting a transact-server cause.

@nagpai
Copy link
Contributor Author

nagpai commented Jan 7, 2025

@Jinksi Thanks for the test and detailed description of the results 🙌🏼

Exported CSV only showed English or site language – expected to see user profile language as an option ⚠️

This is expected, since it uses existing code that considers site language, and not user profile language.

I haven't explored the cause yet but will investigate why the locale is not being respected, suspecting a transact-server cause.

The client seems to send the params correctly via the query. The expected locale is also seen correctly in the API request via the network tab in browser tools.

I will also spend some time checking the server today. Top of my mind - I will check if the server takes the full locale - nl_NL or nl only. And if falls back to English if the nl locale is not found. I found that the earlier source of locale - wcpaySettings.locale.code sent only the first two characters. I am not sure if that causes an error while fetching WordPress translations.

I have also noted some unusual behavior - paJDYF-g5h-p2#comment-27516 that I saw when I tested with a pressable hosted site. The translation worked under certain situations, and in some others it did not.

@Jinksi
Copy link
Member

Jinksi commented Jan 7, 2025

This is expected, since it uses existing code that considers site language, and not user profile language.

Yes, my ⚠️ there was not a comment on the PR implementation, but the inconsistency with the current develop implementation – client-side UI and CSV export is presented in the user profile language, but the server-generated CSV export modal only shows the option for English or site language.

The changes in this PR should fix this by presenting server-generated CSV exports in the user profile language ✅ (clarifying for my own sake, since there are many language variables at play!)

@Jinksi
Copy link
Member

Jinksi commented Jan 7, 2025

I've followed the execution stack locally all the way from Transactions_Controller ::export_transactions to Email_Service::send_email, and the locale nl_NL seems to be passed through correctly on your PR branch.

My server logstash.log is full of these errors though: maybe breaking translations?

PHP Notice:  Function _load_textdomain_just_in_time was called <strong>incorrectly</strong>. Translation loading for the <code>wp-mail-logging</code> domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the <code>init</code> action or later. Please see <a href="https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6114

I've also installed nl_NL with wp language core install nl_NL, but I assume this is only WP language files – not the email translation files.

@nagpai
Copy link
Contributor Author

nagpai commented Jan 7, 2025

My server logstash.log is full of these errors though: maybe breaking translations?

That is a possibility @Jinksi . The error you have noted may be related to a known issue - paJDYF-fWD-p2 that got introduced in WP 6.7 .

Thanks for bringing the attention to the CLI command. I think we will need to use wp language plugin install woocommerce-payments nl_NL

@Jinksi
Copy link
Member

Jinksi commented Jan 7, 2025

My server logstash.log is full of these errors though: maybe breaking translations?

This was fixed on my local by upgrading WP Mail Logging to 1.14.0. Still, no luck translating with my local server, thanks for the tip on installing woocommerce-payments nl_NL.

@Jinksi
Copy link
Member

Jinksi commented Jan 8, 2025

@nagpai I've tested this against my WPCOM sandbox, I see that Nederlands translations work for emails and CSVs on develop. ✅

On this branch, however, Nederlands translations do NOT work for the sent email or CSV export file. ⚠️

I believe this is because the query param is 2 chars on develop (locale=nl) but the longer code on this branch (locale=nl_NL).

(PS more detailed steps to get these emails working on sandbox are listed in https://github.com/Automattic/transact-platform-server/pull/7096)

@nagpai
Copy link
Contributor Author

nagpai commented Jan 8, 2025

Mystery solved ( I hope ) - It looks like the server uses a shorter language code that is different from the WordPress Locale code. I found a past PR where a utility function was added to convert this - #8190

@Jinksi
Copy link
Member

Jinksi commented Jan 8, 2025

shorter language code that is different from the WordPress Locale code

Interesting... separate scope from this PR, but I wonder if this is a bug? For example, it would convert the "Australian English" locale to simply "English", resulting in different spelling being applied to certain words (a low-impact example).

@@ -121,10 +121,6 @@ export const getDepositScheduleInterval = ( state ) => {
return getSettings( state ).deposit_schedule_interval || '';
};

Copy link
Member

Choose a reason for hiding this comment

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

Note that it looks like a bunch of code related to the now-redundant reporting_export_language can also be removed from https://github.com/Automattic/woocommerce-payments/blob/2af6f1aed5923631f49a72f1f98cad7a3c2256ad/includes/admin/class-wc-rest-payments-settings-controller.php.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a nice catch! More 🪚 cuts!
I have removed it here edaaef9

Copy link
Member

@Jinksi Jinksi left a comment

Choose a reason for hiding this comment

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

I've taken a look through the code changes and left some suggestions, mainly related to extra type annotations 🎁

👍 Consistent implementation across reporting views 🙌
👍 Lots of code removed, a win for maintenance 💥

Next, I'd like to test this with the transact-platform-server supported locales (and unsupported) to ensure no regressions.

$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).
];

@@ -188,6 +185,9 @@ declare global {
adminUrl: string;
countries: Record< string, string >;
homeUrl: string;
locale: {
userLocale: string;
};
Copy link
Member

Choose a reason for hiding this comment

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

💭 Since it's present in the wcSettings global browser variable, it can't hurt to let future devs know that it exists.

Another gift to future devs could be explanatory descriptions of what these are. 🎁

Suggested change
};
locale: {
/**
* The locale of the current user profile.
*
* @example 'en_AU' // English (Australia)
*/
userLocale: string;
/**
* The locale of the current site, as set in WP Settings General.
*
* @example 'nl_NL' // Dutch (Netherlands)
*/
siteLocale: string;
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great suggestion! I have added it here 319c867

Comment on lines 126 to 129
userLocale: {
code: string;
english_name: string;
native_name: string;
Copy link
Member

Choose a reason for hiding this comment

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

Another good opportunity to gift extra information to future devs 🎁

This is particularly helpful for code, because it is specific to the transact-platform-server, not WP-standard locale as one might expect.

Suggested change
userLocale: {
code: string;
english_name: string;
native_name: string;
userLocale: {
/**
* The locale of the current user profile, represented as a locale code supported by transact-platform-server.
*
* @example 'sv' // Swedish
*
* @see WC_Payments_Utils::convert_to_server_locale
*/
code: string;
/**
* The English name of the locale.
*
* @example 'Swedish'
*/
english_name: string;
/**
* The native name of the locale.
*
* @example 'Svenska'
*/
native_name: string;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added the comments. This will be certainly helpful for future developers - 7b4f520

Significance: minor
Type: update

Simplify localization of CSV exports to use global site language settings from WP Admin
Copy link
Member

Choose a reason for hiding this comment

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

💭 An idea for updating this changelog entry, to mention a bit more of the "why".

Suggested change
Simplify localization of CSV exports to use global site language settings from WP Admin
Simplify localization of CSV exports to use user language settings from WP Admin, allowing the CSV export to match the localization of the data presented in the UI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. I have updated it here ca2a2fa

@Jinksi Jinksi requested a review from a team January 9, 2025 06:15
@haszari
Copy link
Contributor

haszari commented Jan 9, 2025

Mystery solved ( I hope ) - It looks like the server uses a shorter language code that is different from the WordPress Locale code. I found a past PR where a utility function was added to convert this - #8190

Interesting... separate scope from this PR, but I wonder if this is a bug? For example, it would convert the "Australian English" locale to simply "English", resulting in different spelling being applied to certain words (a low-impact example).

I believe this is because the query param is 2 chars on develop (locale=nl) but the longer code on this branch (locale=nl_NL).

Clarifying some context about these codes …

It sounds like we might be using country code as a shorthand for language, and we should probably use language codes (e.g. en_UK, nl_NL).

@Jinksi Jinksi self-requested a review January 9, 2025 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reporting: Simplify CSV export localization
4 participants