Skip to content

Enhance locale fallback mechanism#104

Open
icnbrave wants to merge 3 commits into
alibaba:masterfrom
icnbrave:locale-fallback-enhanced
Open

Enhance locale fallback mechanism#104
icnbrave wants to merge 3 commits into
alibaba:masterfrom
icnbrave:locale-fallback-enhanced

Conversation

@icnbrave
Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Author

@cwtuan any other advice to this PR?

Comment thread src/index.js Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

bump

Comment thread src/index.js
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
Copy Markdown

@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