Opened 8 years ago

Closed 7 years ago

#14687 closed defect (invalid)

dijit widgets do not respect browser language settings when html lang is set

Reported by: Paul Christopher Owned by: Adam Peller
Priority: undecided Milestone: tbd
Component: Dijit - Form Version: 1.7.1
Keywords: Cc: Douglas Hays
Blocked By: Blocking:

Description

Description The browser's language settings are e.g. "DE". dojo.local also is set to "DE" (which seems to be correct, since no language is specified in data-dojo-config). However all the widgets are still in English. That's because the html file has a <html lang="en"> tag. Apparently this causes the dijit widgets to listen to this setting. If you remove the lang="en" setting from the html tag, it works again. They will be in the browser's language again.

Steps to reproduce the issue Change your locale of your browser to something else than "en" (e.g by using the Quick Locale Switcher Plugin for Firefox).Run the attached test file testLocale.html. Watch the results. The browser language and dojo.locale will be in the set language, but the dijit widgets will still be in English. Now remove the lang-attrib form the html tag. Everything will be in sync now.

Discussion I tried to load some additional texts with require(["dojo/i18n!myApp/nls/myResources", function(resources).., but could not get it work. For some reason, I was unable to load the resources and I don't know how to configre the loader. :-( But I think these locale resources are loaded according to the dojo.locale variable. I.e. dijit widgets and own widgets might be in different languages because of this bug? However this all needs further testing...

Attachments (5)

testLocale.html (1.0 KB) - added by Paul Christopher 8 years ago.
testLocale2.html (1.4 KB) - added by Paul Christopher 8 years ago.
screenshot1.png (10.6 KB) - added by Paul Christopher 8 years ago.
screenshot2.png (10.7 KB) - added by Paul Christopher 8 years ago.
testi18n.zip (4.4 KB) - added by Paul Christopher 8 years ago.

Download all attachments as: .zip

Change History (27)

Changed 8 years ago by Paul Christopher

Attachment: testLocale.html added

comment:1 Changed 8 years ago by bill

Owner: changed from Adam Peller to Paul Christopher
Status: newpending

I don't get it, are you saying that we should always ignore lang settings on any/all DOMNodes? If so, what's the point of the lang attribute? (And, to be clear, doesn't the browser always have a language setting?)

The current code is working as intended, that the lang attribute overrides the browser's default language setting.

BTW, in 2.0 I plan to get rid of per-widget lang settings, or separate lang settings for different sections of the page, and just have one global setting. But even then the same argument applies, that <html lang="en"> should override the default browser setting.

comment:2 Changed 8 years ago by Paul Christopher

Status: pendingnew

Yes, so the <html lang="en">-attribute overrules the browser's settings ('de') to 'en', but why does dojo.locale still say 'de' and not 'en' then? That's confusing for me... I would have expect that dojo.locale tells me the current globale mode of operation which should be "en"?

Or to put it in other words: The whole html document is marked as lang="en" and dojo runs within this global context which overrules the browser's settings. But why does dojo.locale still report "de"?

comment:3 Changed 8 years ago by bill

Owner: changed from Paul Christopher to Adam Peller
Status: newassigned

Not sure, Adam?

Perhaps it's not recommended to set a lang=... on <html>. The feature is more intended for setting lang=... on subnodes where the lang is different than the page default setting. (But like I said, even that feature is questionable and I want to remove it for 2.0.)

comment:4 Changed 8 years ago by Adam Peller

I agree this behavior is not well defined. At this time, dojo.locale is simply defined as navigator.language unless the Dojo config says otherwise.

comment:5 Changed 8 years ago by Paul Christopher

As far as I know - from the point of view of accessibility - it is a must / best-pratice to tell screenreader users/ search engines the language of the current html document. And that is done via <html lang="en">.

Moreover there should be a way for a programmer to get to know the current mode of operation if he wants to do something like this

if (dojo.locale === 'en') {

your stuff

} else {

other stuff

}

But I'm not a real Dojo expert...

comment:6 Changed 8 years ago by Adam Peller

Paul, you raise some interesting issues.

Dijit has a feature (you can blame me for) where we tried to emulate what I understood the lang attribute to be, such that widgets would honor lang "overrides" for individual widgets -- something I suspect is not used very often, if ever. Dojo itself, which may operate with or without Dijit, makes no assumptions about the document, or that there even is a document (e.g. Rhino or server-side environments) so dojo.locale is discovered only with navigator.language and any optional configuration setting. I suspect that resource loading, in general, would honor exactly the setting as given by dojo.locale, 'de' in your case. It's only Dijit widgets which get this inherited lang attribute which try to behave differently. Furthermore, unless you do something special in the bootstrap to indicate that Dojo must load the locale given by the lang override, I don't think Dojo will go and fetch the resources. Because the root strings are all in English, I suspect what you're seeing is working by accident.

@bill plans to drop the lang attribute override in 2.0, so I'm not sure this is worth addressing. However, your a11y comment makes me wonder if there is reason why we should give it another thought.

comment:7 Changed 8 years ago by bill

Note that everything works as expected if you set <html lang=...>, just as long as you set dojo.locale to the same thing. Maybe we should just document it that way?

comment:8 Changed 8 years ago by Adam Peller

That seems consistent with the other part that may not be documented -- that dojo.config.extraLocale must be set if lang is set to anything else elsewhere in the document.

comment:9 Changed 8 years ago by Paul Christopher

But something has to be broken, too. It is not just a documentation bug.

Take testLocale2.html. The file is marked as <html lang="en">. Switch your browser to "de". Run the file.

  • The alert box will report dojo/_base/kernel.locale which is "de"
  • Now enter "4444444" in the first field. The tooltip will complain in English "This value is out of range".
  • Hover with your mouse over the above input field so as to display the title attribute. It is in German!! "Bitte halten Sie sich an das vorgegebene Format" ("Please adhere to the given pattern/ format"). See screenshot1.png. German and English at the same time!

Thus: Something seems be broken IMHO.

I tried to load a translated resource bundle. Alas, I failed because I was unalbe to configure the loader properly. Can you do it for me?? All in all, I wonder in which language these resources would be? German? English?

And something else:

  • Enter 44 in field 1. Press "Submit". Why does the tooltip look so strange and why is it in German and not in English?

Changed 8 years ago by Paul Christopher

Attachment: testLocale2.html added

Changed 8 years ago by Paul Christopher

Attachment: screenshot1.png added

Changed 8 years ago by Paul Christopher

Attachment: screenshot2.png added

comment:10 Changed 8 years ago by Adam Peller

The extraLocale and lang settings were designed for the edge case where you *do* want to display two languages at the same time, e.g. setting lang to en on one widget and de on another. It's an edge case used very rarely. By setting lang on the html attribute, all of the Dijit code *should* be picking up the locale according to html lang (if they don't, it may be a bug) but other routines in Dojo, called directly, would use the locale according to dojo.locale, making for a confusing mix. Like Bill said, the feature will likely be dropped in 2.0

For now, if you're going to set the locale on the HTML element, just set Dojo's locale to match:

data-dojo-config="async:true, parseOnLoad:true,locale:'en'"

To provide service in different languages, your server would have to substitute both values when generating the page.

comment:11 Changed 8 years ago by Paul Christopher

Setting the locale to 'en' does not change the behaviour of the tooltip/ title attribute in the above test case. It is still in German. Is it just a missing translation? Or something else?

Why does the tooltip look so strange, i.e. why does the tooltip look totally different compared to the normal dijit error tooltips?

comment:12 Changed 8 years ago by Adam Peller

If you set the locale to 'en', German resources should not come into play at all. Where does that string get defined?

comment:13 in reply to:  11 Changed 8 years ago by bill

Cc: Douglas Hays added

Replying to Paul Christopher:

Why does the tooltip look so strange, i.e. why does the tooltip look totally different compared to the normal dijit error tooltips?

Presumably that's a native browser tooltip rather than a dijit.Tooltip, but I don't know why it's showing up, especially since you've set type=text on the field. Doug?

comment:14 Changed 8 years ago by Paul Christopher

No, I mean the tooltip you can see in screenshot02.png!! It tells me that I have entered a number, that does not fit the specified pattern. I agree the browser title tooltip is strange, too.

comment:15 Changed 8 years ago by Adam Peller

Please upload your current html

comment:16 Changed 8 years ago by bill

BTW I tried testLocale2.html and followed Paul's instructions above. I see how the first TextBox gets both a browser title tooltip and dijit.Tooltip, although they both appear in English for me even when I set my browser's locale to German (de-de). This is on Firefox on the mac. On Chrome I get no browser title tooltip.

Also, I couldn't reproduce that weird looking tooltip in screenshot02.png.

comment:17 Changed 8 years ago by Paul Christopher

Using Firefox 10 on Win7, I just need to enter 44 in field 1 and hit "Submit" to get that weired looking tooltip. And I always get the tooltip in German even when I set Firefox to 'en' and provide locale:'en' in data-dojo-config.

I have experienced the following behaviour: I have a html page with <html lang=en> set in the header (like above). However the page uses a custom widget that support i18n translations (as explained in http://dojotoolkit.org/reference-guide/quickstart/internationalization/resource-bundling.html#quickstart-internationalization-resource-bundling). Changing the browser's locale does change the language of my widget! That's contrary to the above test case: dijit widget in testLocale2.html always stay in English...

comment:18 Changed 8 years ago by Adam Peller

We'll need an exact test case.

comment:19 Changed 8 years ago by Paul Christopher

Please try the attached test case test18n.zip. The html page contains a language setting on head level, i.e. a <html lang="en"> setting. The locale is not defined via data-dojo-config (however, as you pointed out above, this should be normally done)

Now extract the zip archive, put a copy of dojo into it and run it. Set your broser language to "en". Both the dijit number widget as well as the custom widget are in English.

Now change the browser language to German "de" (Tested with Firefox and Quick Local Switcher Plugin). Rerun the code. The custom widget will be in German. The dijit controll however will still be in English.

Changed 8 years ago by Paul Christopher

Attachment: testi18n.zip added

comment:20 Changed 8 years ago by Adam Peller

Component: InternationalizationDijit - Form

Ok, I think this clears up my confusion. I thought you were describing the situation *with* the data-dojo-config locale set to 'en'. Yes, without the matching config and lang attribute, I think Bill and I acknowledge that strange things may happen. Such a configuration is not well tested and may not be supported in the future. Setting the locale in data-dojo-config is suggested.

So this particular bug is that Dijit's validation text box may not be using the lang attribute consistently.

Last edited 8 years ago by Adam Peller (previous) (diff)

comment:21 Changed 8 years ago by bill

Looks like everything is working correctly to me. Dijit is obeying the <html lang="en"> setting, according to it's spec.

Your custom widget is using "dojo/i18n!./nls/TimeoutWidget" to load it's messages and since there's no data-dojo-config setting for language, dojo/i18n! uses the browser default of "de".

Last edited 8 years ago by bill (previous) (diff)

comment:22 Changed 7 years ago by bill

Resolution: invalid
Status: assignedclosed
Note: See TracTickets for help on using tickets.