i18n - detectLanguage(): Order of navigator.languages[0] and navigator.language
See original GitHub issueAccording to the documentation [1], calling configuration.getLanguage()
detects the language in the following order:
- URL parameter
- Explicite application coding
navigator.userAgent
(on Android)navigator.language
navigator.userLanguage
(on IE)navigator.browserLanguage
(on IE) (btw. 5 and 6 seem to be swapped in the doc [2] atsap-ui-language
)"en"
which is also reflected in this line of code.
Chrome on Windows and Chrome OS, and other similar browsers (such as Opera) offer a feature to change the displayed language of the browser, independent to the system language and the order of the languages.
Chrome on Mac OS and Linux uses the system language for the browser language, also independent to the order of the languages in the setting.
Chrome reports its displayed browser language as
navigator.language
.
E.g.: In case of the above displayed picture (without URL parameter and explicite coding)
sap.ui.getCore().getConfiguration().getLanguage()
returns"de"
whereasnavigator.language
, which should have been the detection factor, returns"en-US"
because the functiondetectLanguage
prioritizesnavigator.languages[0]
overnavigator.language
.
On Firefox, this is no problem because navigator.languages[0]
is always equal to navigator.language
.
My question
Why is navigator.languages[0]
higher prioritized than navigator.language
? Is this the intended behavior? If so, wouldn’t it be appropriate to include navigator.languages[0]
to the prioritization list in the mentioned documentations? Otherwise, I assume that getLanguage()
returns navigator.language
which is not the case.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Sorry, this took a bit longer than expected.
The use of
navigator.languages[0]
now has been documented in Identifying the Language Code / Locale and the inconsistencies between that page and the description of thelanguage
parameter in Configuration Options and URL Parameters has been resolved.All documentation changes are so far only visible in openui5nightly.
Hi @codeworrior, Sorry for the misunderstanding. Yes, the wikipedia.org page is shown in the first language (de) regardless of my browser UI language (en-US). Thank you for the explanations. I’d be happy enough if the documentation gets updated accordingly in order to avoid confusions for other devs.