#18722 closed defect (fixed)
Dojo can read incorrect locale value from Chrome
Reported by: | a06275 | Owned by: | bill |
---|---|---|---|
Priority: | undecided | Milestone: | 1.10.5 |
Component: | Loader | Version: | 1.10.4 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
Using Dojo heavily in an enterprise web-app, I am having problems with Date formatting that I've traced back to the locale specified in dojo.config. Specifically, I'm getting a locale of "en-us" rather than the correct "en-gb". Having dug further, I've discovered the cause of this.
In dojo/_base/config, the user's locale can be read from the browser using the navigator object. Specifically, it tests for ...
navigator.language || navigator.userLanguage
... however the language property in Chrome is actually set to the download locale, so English users will often download with a locale of en-US and hence Dojo loads into this locale rather than the preferences set by the user in their browser settings.
There is a blog post at https://alicoding.com/detect-browser-language-preference-in-firefox-and-chrome-using-javascript/ regarding this problem, and the suggested solution is to use another property found on the Chrome navigator object, specifically languages, which has a prioritised list of the user's chosen languages. The better test would therefore be ...
navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage)
... which would solve the problem of Dojo loading into the wrong locale.
Change History (7)
comment:1 Changed 5 years ago by
comment:2 Changed 5 years ago by
Milestone: | tbd → 1.10.5 |
---|---|
Owner: | changed from Rawld Gill to bill |
Status: | new → assigned |
comment:3 Changed 5 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Pushed in 31977b8870a1b3b3a618578450e63d211f594fdc and 31977b8870a1b3b3a618578450e63d211f594fdc.
comment:4 Changed 5 years ago by
Hmm, this change broke Android 6.0 (or at least in the emulator). Since we've already technically released 1.11.0 I filed #18818 to fix the regression.
Pull request created at https://github.com/dojo/dojo/pull/169