#16663 closed defect (fixed)
dojo/i18n fails when dojo.locale undefined
Reported by: | bill | Owned by: | bill |
---|---|---|---|
Priority: | blocker | Milestone: | 1.9.1 |
Component: | Internationalization | Version: | 1.8.3 |
Keywords: | Cc: | Rawld Gill, Adam Peller | |
Blocked By: | Blocking: |
Description
dojo/i18n depends on dojo.locale having a non-null value, starting on this line:
targetLocale = localeSpecified || dojo.locale
The app can set/override the locale in data-dojo-config, but it's unusual, and IIUC certainly not required.
If the app does not explicitly set dojo.locale, it normally gets its default setting from dojo/_base/sniff:
dojo.locale = dojo.locale || (has("ie") ? navigator.userLanguage : navigator.language).toLowerCase();
But, dojo/_base/sniff isn't required by dojo/i18n.
For server side environments, the locale is specified in the config itself, ex for rhino:
locale:String(java.util.Locale.getDefault().toString().replace('_', '-').toLowerCase()),
So my thinking is that rather than dojo/i18n pulling in the deprecated dojo/_base/sniff module, dojo/_base/config should set a default value for locale if it isn't defined.
Change History (9)
comment:1 Changed 7 years ago by
Cc: | Rawld Gill Adam Peller added |
---|---|
Milestone: | tbd → 1.9 |
Owner: | changed from Adam Peller to bill |
Status: | new → assigned |
comment:3 Changed 7 years ago by
Milestone: | 1.9 |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
This is not fixed at all. All you’ve done is made it so that someone not using the Dojo loader on the server-side will experience a crash as dojo/_base/config attempts to naively access the navigator
object.
targetLocale = localeSpecified || dojo.locale || ""
fixes the issue, so in the case of no locale, it should just use the root bundle.
comment:4 Changed 7 years ago by
Milestone: | → 1.9.1 |
---|---|
Priority: | undecided → blocker |
Status: | reopened → open |
comment:5 Changed 7 years ago by
Actually, the problem described in this ticket is fixed. https://github.com/wkeese/dojo proves that the code now works when dojo.locale is not defined, and that it works for non dojo loaders.
Simply removing the navigator reference is no good. That would make dojo run in English no matter what the browser's/machine's locale is.
As for the server side, the idea is that when running on node, _base/configNode.js runs first, which defines the locale, and then the if branch in config.js never runs:
if(!result.locale){ // Default locale for browsers. result.locale = (navigator.language || navigator.userLanguage).toLowerCase(); }
I'm not sure of the details of how to load configNode.js when running under another loader.
comment:6 Changed 7 years ago by
The problem in the summary of this ticket is “dojo/i18n fails when dojo.locale undefined”. dojo/i18n still fails when dojo.locale is undefined, you just reduced the chance of it being undefined. :)
comment:7 Changed 7 years ago by
Resolution: | → fixed |
---|---|
Status: | open → closed |
fix locale and dojo/i18n issues on node, fixes #16663
- avoid exception in dojo/_base/config when navigator isn't defined
- make dojo/i18n handle case when dojo.locale is undefined Changeset: 1f53266a1cacdd59b546f20eb1f1b478df87cea2
comment:8 Changed 7 years ago by
fix locale and dojo/i18n issues on node, fixes #16663
- avoid exception in dojo/_base/config when navigator isn't defined
- make dojo/i18n handle case when dojo.locale is undefined Changeset: 5fe0f69ba1a1a3baf96343418ad395fde4a81f5d
I'm going to check in a fix, Rawld please review.