florrain / locale

Browser locale negotiation for node.js
MIT License
257 stars 36 forks source link

best() returning traditional chinese when it should be returning simplified chinese #33

Open kellenwheaton opened 8 years ago

kellenwheaton commented 8 years ago

My supported locales are:

["en", "fr", "de", "zh-hant", "zh-hans"]

In Chrome my language settings are: screen shot 2016-02-19 at 4 05 40 pm My current accept-language header is:

zh-CN,zh;q=0.8,zh-TW;q=0.6,en;q=0.4,en-US;q=0.2

After the following code:

locales = new locale.Locales(req.headers["accept-language"]); bestLocale = (locales.best(supportedLocales) || "").toString();

bestLocale is "zh-hant", rather than "zh-hans", and traditional chinese is what's shown to the user. In the meantime I'm manually returning "zh-hans" when the first language in the header is zh-CN.

stuartf commented 8 years ago

I suspect this is because the code has no way of mapping zh-CN and zh-TW to zh-hant and zh-hans so it's actually matching zh from your browser and giving the first zh-* from your supported list.