ibm-js / ecma402

ECMA-402 JavaScript Internationalization API "shim"
Other
34 stars 21 forks source link

Use navigator.languages in BestFitSupportedLocale #70

Closed stevenatkin closed 9 years ago

stevenatkin commented 10 years ago

Let's see if we can use the navigator.languages list from Mozilla and Chrome. The navigator.languages list is the same as the list of languages in the HTTP Accept-Language header.

cjolif commented 10 years ago

If something like that is done, https://github.com/ibm-js/requirejs-dplugins/blob/master/i18n.js must then be changed accordingly so that we get similar locale resolution when loading resource bundles to avoid discrepancies.

We should also probably share the code that pick the default locales between ecma-402 and requirejs-dplugins so that any subsequent changes is shared across the two projects.

Note how that this change would make the behavior inconsistent across browsers which I'm not 100% sure his a good idea (knowing that is someone want to use navigator.languages he can already perfectly use it I suppose so it is not like if that was blocking them?)

clmath commented 10 years ago

As I am new in the g11n world, my biggest question here is how locales are prioritized between computed fallback (like fr-fr fall back to fr) and user specified fallback (if navigator.languages is ['fr-fr', 'pt']).

With the previous example (navigator.languages = ['fr-fr', 'pt']), if only fr and pt are available, which locale should be chosen ?

Is there a specification about that ?

pdardailler commented 10 years ago

No specification, but a best current practice (becoming a de facto standard), BCP 47, that you can find at http://tools.ietf.org/html/bcp47. Look for Lookup.

clmath commented 10 years ago

Ok, so if I understand the BCP correctly, in the previous example the locale should be fr right ?

pdardailler commented 10 years ago

Correct. However, there are some special cases that are not as straightforward, such as Portuguese or Chinese, or as soon as you have a different script.

clmath commented 10 years ago

Ok, I think I am lacking some expertise here so I'll let @JCEmmons look into this.