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

Enhance locale fallback mechanism #104

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

icnbrave
Copy link

The preferred fallback locale should depend on the current locale, different locale maybe have different preferred fallback locale. For example, for Traditional Chinese (zh-TW), the preferred fallback locale should be Simplified Chinese (zh-CN), if the key does not exist in Simplified Chinese, it will fallback to English (en-US). In this case, the fallbackLocale can be set to zh-CN; en-US.

@CLAassistant
Copy link

CLAassistant commented Nov 28, 2018

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@icnbrave
Copy link
Author

@cwtuan Many products of our company are using the framework to process i18n messages, and the current locale fallback mechanism does not comply with the globalization standard, could you help to process this PR?

@cwtuan
Copy link
Collaborator

cwtuan commented Dec 3, 2018

I wondering why the key defined in a locale file but not defined in another locale file?
Shouldn't you check the number of keys for different locale files in your deployment script?

@icnbrave
Copy link
Author

icnbrave commented Dec 5, 2018

@cwtuan During product development lifecycle, we should not be waiting for all of the translation for all locales are ready, and then release the product. So it is quite possible that the keys are not consistent for all locales. In this case, we want the locale fallback can take local user’s language preference into consideration. For example, if a product does not provide translation service for Traditional Chinese, but the translation for Simplified Chinese and English are ready, in this case, the product should provide Simplified Chinese GUI to Taiwan or Hong Kong users. Or even the Simplified Chinese not provided, the product should display English for them, rather than other foreign languages.

@icnbrave
Copy link
Author

@cwtuan any other advice to this PR?

src/index.js Outdated
@@ -48,7 +48,7 @@ class ReactIntlUniversal {
warningHandler: console.warn, // ability to accumulate missing messages using third party services like Sentry
escapeHtml: true, // disable escape html in variable mode
commonLocaleDataUrls: COMMON_LOCALE_DATA_URLS,
fallbackLocale: null, // Locale to use if a key is not found in the current locale
fallbackLocale: null, // Locales to use if a key is not found in the current locale, such as 'zh-CN;en' will use the key in locale 'zh-CN', if the specific key not exist in 'zh-CN', will fallback to 'en'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we add another parameters fallbackLocales with type of string[]? And make the original fallbackLocale deprecated.

Copy link
Author

Choose a reason for hiding this comment

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

Hi @cwtuan
Thanks a lot for your great advice. Here attached the modification according to your suggestion, please have a kind review again.

@michaelguild13
Copy link

bump

@@ -48,7 +48,8 @@ class ReactIntlUniversal {
warningHandler: console.warn, // ability to accumulate missing messages using third party services like Sentry
escapeHtml: true, // disable escape html in variable mode
commonLocaleDataUrls: COMMON_LOCALE_DATA_URLS,
fallbackLocale: null, // Locale to use if a key is not found in the current locale
fallbackLocale: '', /** @deprecated Locale to use if a key is not found in the current locale */
Copy link

@the-architect the-architect Apr 30, 2019

Choose a reason for hiding this comment

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

I would suggest not to deprecate this option. It seems that your use case is very specific and this config would require changes for an otherwise stable feature.

A suggestion: Your case could also be handled by using a comma separated fallbackLocale sequence like: 'zh-CN,en-US' which would require some extra effort for your case, but would keep the config simple for most users.

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