pwa-studio
pwa-studio copied to clipboard
Fix convert locale from Magento standard to react-intl BCP 47 language code
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch @magento/[email protected]
for the project I'm working on.
Function toReactIntl
in node_modules/@magento/venia-ui/lib/util/formatLocale.js which Convert locale from Magento standard to react-intl BCP 47 language code, don't work as expected.
/**
* Convert locale from Magento standard to react-intl BCP 47 language code
*
* @param {string} string
* @returns {string} A string (e.g. `fr-FR`).
*/
export const toReactIntl = string => {
return string.replace('_', '-');
};
According to MDN
replace(substr, newSubstr) substr: A String that is to be replaced by newSubstr. It is treated as a literal string and is not interpreted as a regular expression. Only the first occurrence will be replaced.
Locale code like zh_Hant_HK
if use toReactIntl()
will result in zh-Hant_HK
So I change string.replace('_', '-')
into string.replaceAll('_', '-')
Here is the diff that solved my problem:
index b10550a..216c978 100644
--- a/node_modules/@magento/venia-ui/lib/util/formatLocale.js
+++ b/node_modules/@magento/venia-ui/lib/util/formatLocale.js
@@ -15,5 +15,5 @@ export const fromReactIntl = string => {
* @returns {string} A string (e.g. `fr-FR`).
*/
export const toReactIntl = string => {
- return string.replace('_', '-');
+ return string.replaceAll('_', '-');
};
This issue body was partially generated by patch-package.
Hi @ngtankhoa. Thank you for your report. To help us process this issue please make sure that you provided sufficient information.
Please, add a comment to assign the issue: @magento I am working on this
- Join Magento Community Engineering Slack and ask your questions in #github channel.
@magento export issue to JIRA project PWA as Bug
:white_check_mark: Jira issue https://jira.corp.magento.com/browse/PWA-2866 is successfully created for this GitHub issue.
Feel free to open a pull request to make this contribution!
Hi @ngtankhoa,
Please share how will it impact venia functionality also if you can please help with steps to reproduce.