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

Map i18next language code to ICU locale #35

Closed
jamesots-tq opened this issue Mar 3, 2021 · 6 comments
Closed

Map i18next language code to ICU locale #35

jamesots-tq opened this issue Mar 3, 2021 · 6 comments

Comments

@jamesots-tq
Copy link

🚀 Feature Proposal

I propose adding a way of mapping from the i18next language code to another code.

Motivation

There may be a case where multiple sets of translations are required for the same language. For example, if a web app is deployed to multiple companies, each company may need their own company-specific set of translations, even though they're still using the same underlying language and locale.

At the moment I'm partially getting around this by using multiple custom region suffices, with the appropriate language code. e.g. en-ab, en-en, en-xy. This ensures that the correct plural forms are used. Unfortunately it ends up causing the wrong date formats to use, as they are based on the second part of the code.

It would be useful to be able to have resource packs named with arbitrary names, e.g. bobswidgets, sparklythings, default, and then be able to have a function which maps those names to correct locales. Or perhaps to use the modified codes as before (en-ab, en-en, en-xy) and map them to real locales (en-gb).

Although I particularly need this for i18next-icu, it may actually make sense to implement it in the main i18next package.

@jamuhl
Copy link
Member

jamuhl commented Mar 3, 2021

not 100% what you're requesting...

locales codes are defined like in ICU:

  • en locale
  • en-US locale + region
  • en-US-x-custom locale + region + custom
  • zh-hant-CN locale + script + region

@jamesots
Copy link

jamesots commented Mar 3, 2021

Thank you. I wasn't aware of the x-custom part, which gives me exactly what I need.

@kachkaev
Copy link

kachkaev commented Mar 5, 2021

Maybe this is a somewhat unrelated question, but might be still worth asking in the same thread. Sorry if this is off-topic 🙏

Is it possible to map the rules of a completely different language id into a known one, e.g. English? I’d like to set up a new locale with id zz-ZZ, which would be a pseudo version of English.

When I go for new Pseudo({ languageToPseudo: "zz-ZZ" }), the UI renders as expected, i.e. I see [42 ααṗṗḽḛḛṡ] instead of 42 apples. However, each instance of an ICU string with plural produces this warning in the browser console:

i18next::pluralResolver: no plural rule found for: zz-ZZ 

Is there any way I can tell i18next-icu to treat zz exactly like en in terms of the pluralization rules?

Replacing zz-ZZ with en-ZZ help, but I’d still prefer zz-ZZ because there is a legacy i18n system which already uses zz-ZZ and it’s not worth ‘fixing’.

@jamuhl
Copy link
Member

jamuhl commented Mar 6, 2021

@kachkaev hm...only option I could think of is adding some parseLngForICU function here: https://github.com/i18next/i18next-icu/blob/master/src/index.js#L66

what do you think? Doable? Practical? PR welcome

@kachkaev
Copy link

kachkaev commented Mar 9, 2021

Thanks for your reply @jamuhl, the idea makes sense! I’ll submit a PR within a few weeks unless we decide to replace zz-ZZ with en-ZZ (or something like that). Being able to do so can let us specify several pseudo-locales (e.g. en-ZZ and es-ZZ) and won’t require any upstream changes. If something can be solved without widening APIs between systems, that’s better for everyone 🙂

@karoun
Copy link
Contributor

karoun commented Apr 2, 2023

@kachkaev hm...only option I could think of is adding some parseLngForICU function here: https://github.com/i18next/i18next-icu/blob/master/src/index.js#L66

what do you think? Doable? Practical? PR welcome

Our team had need of this too, so I made a PR: #63

adrai pushed a commit that referenced this issue Apr 3, 2023
* Adding function to parse language for ICU

* Adding missing semicolon
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

5 participants