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

Fallback bug #460

Closed
xareelee opened this issue Jun 19, 2017 · 7 comments
Closed

Fallback bug #460

xareelee opened this issue Jun 19, 2017 · 7 comments

Comments

@xareelee
Copy link

xareelee commented Jun 19, 2017

I forward this issue from AlexanderZaytsev/react-native-i18n#96 (comment).


The fallback strategy has a bug. The Chinese mandarin language (zh/中, how to pronounce) use a character system (Han/漢, how to write) which is divided into two kinds of symbol styles: Traditional Chinese characters (zh-Hant, where t stands for Traditional) and Simplified Chinese characters (zh-Hans, where s stands for Simplified).

For example, a user uses Traditional Chinese characters and lives in Taiwan, his language and locale should be zh-Hant-TW, and the priority of the i18n fallback strategy should be:

  1. zh-Hant-TW: Traditional Chinese characters used in Taiwan
  2. zh-Hant: general Traditional Chinese characters
  3. zh: general Chinese characters

The current fallback strategy of i18n-js has a bug. If it doesn't find zh-Hant-TW, it will only look for zh, not zh-Hant first.

I want to provide zh-Hant for all Traditional Chinese and zh-Hans for all Simplified Chinese no matter what the locale is, but it can't currently work. Devices provide lang+locale and i18n-js fallbacks to zh directly in this scenario.

Fallback strategy:

  • Expected: zh-Hant-TW -> zh-Hant -> zh -> default language
  • Current: zh-Hant-TW -> zh -> default language
// general Chinese
zh

// Traditional Chinese 
zh-Hant

// Simplified Chinese
zh-Hans

// Traditional Chinese + Locale
zh-Hant-TW
zh-Hant-SG
zh-Hant-HK
zh-Hant-CN

// Simplified Chinese + Locale
zh-Hans-TW
zh-Hans-SG
zh-Hans-HK
zh-Hans-CN
@PikachuEXE
Copy link

Do you know how ruby's i18n works for this case?
I guess the fallback logic is from ruby.
If it handles that already, we can try to copy from that.
If not let's think about a way to make your case work.

@xareelee
Copy link
Author

@PikachuEXE, I have no idea.

I reported this issue because I'm using react-native-i18n which depends on this library and I encountered this issue.

I'm not sure whether anyone else encountered this issue in i18n-js too.

I want to provide zh-hant and zh-hans for Traditional and Simplified Chinese in all locales, respectively, not to provide zh for all general Chinese.

@PikachuEXE
Copy link

OK let me check the logic from Ruby's I18n and see how it handle this case
Maybe we can copy the logic it :P

Let me get back to you later

@nerdmed
Copy link

nerdmed commented Jun 22, 2017

@xareelee @PikachuEXE thanks a lot. Same here i am also using it with react-native-i18n and for me it does not work even though we just want to support the simplified chinese "zh-Hans". Would be awesome to fix the logic here.

See: AlexanderZaytsev/react-native-i18n#93 (comment)

@flexsurfer
Copy link

https://github.com/fnando/i18n-js/blob/master/app/assets/javascripts/i18n.js#L273 here it takes only first element "zh" from 3 elements ["zh","hans","tw"], logic here should be changed, it should add "zh" and "zh-hans".

@nerdmed
Copy link

nerdmed commented Jun 27, 2017

yes. i think there is a more semantic way to achieve what is done there. Anyone here that is interested and has already worked with this lib? I think it makes sense to improve this part with a PR?

@PikachuEXE
Copy link

Please take a look at #465 to see if it works

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

No branches or pull requests

4 participants