Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#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 6 years ago by bill

Cc: Rawld Gill Adam Peller added
Milestone: tbd1.9
Owner: changed from Adam Peller to bill
Status: newassigned

I'm going to check in a fix, Rawld please review.

comment:2 Changed 6 years ago by bill

Resolution: fixed
Status: assignedclosed

In [30525]:

Define default locale for browsers in config.js, same way it's done for node, rhino, etc. in configNode.js, configRhino.js, etc. Fixes #16663 !strict.

comment:3 Changed 6 years ago by Colin Snover

Milestone: 1.9
Resolution: fixed
Status: closedreopened

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.

Last edited 6 years ago by Colin Snover (previous) (diff)

comment:4 Changed 6 years ago by Colin Snover

Milestone: 1.9.1
Priority: undecidedblocker
Status: reopenedopen

comment:5 Changed 6 years ago by bill

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 6 years ago by Colin Snover

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 6 years ago by Bill Keese

Resolution: fixed
Status: openclosed

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 6 years ago by Bill Keese

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

comment:9 Changed 6 years ago by Bill Keese <bill@…>

In 1f53266a1cacdd59b546f20eb1f1b478df87cea2/dojo:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 
Note: See TracTickets for help on using tickets.