Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n - Browser preference language should have priority over system language #1137

Closed
piejanssens opened this issue Sep 8, 2016 · 10 comments

Comments

@piejanssens
Copy link

window.navigator.language "nl-BE"
window.navigator.userLanguage "nl-BE"
window.navigator.browserLanguage "en-US"

A user with an explicit preference for "en-US" expects this language to be used over whatever system language/region settings he might have. However according to the following documentation this is not the case and the window.navigator.browserLanguage is only second to last considered for setting the language of the UI5 app:

https://help.sap.com/saphelp_uiaddon10/helpdata/en/91/f21f176f4d1014b6dd926db0e91070/content.html

We notice the same behavior in angular.js, is this a leftover from angular in UI5?

@codeworrior
Copy link
Member

The question may sound stupid, but what exactly do you mean with

A user with an explicit preference for "en-US"

As explained in the documentation that you linked above, the navigator.browserLanguage in IE reflects the language of the operating system. This might in many cases represent an "explicit preference" of the user, but it might also express the choice of a company administrator that doesn't care (or know) about user preferences. Not sure how UI5 should differentiate between the two cases.

From my perspective one can argue for both orders of precedence. So at the end it is a "go left or right" thing.

The language settings done in the browser are more obviously reflecting a user choice, but unfortunately, IE does not expose them via Javascript API (as also explained in the above documentation).

is this a leftover from angular in UI5?

Eh, no.

@piejanssens
Copy link
Author

OK

Well I tried setting a fixed language in the app (without the get parm method) but have not been able to succeeed:

  • In component.js init: sap.ui.getCore().getConfiguration().setLanguage("EN");
  • Bootstrap attribute: data-sap-ui-xx-supportedLanguages="en"
  • Bootstrap attribute: data-sap-ui-language="en"

@codeworrior
Copy link
Member

Your variants 1 and 3 should have worked, variant 2 has a different meaning. It restricts the backend requests for i18n texts to the given list of languages (so if you specify "en" there and your locale setting is en_GB, UI5 will ask the server only for messagebundle_en.roperties, but not for message bundle_en_GB.properties).

How did the variants 1 and 3 fail?

@piejanssens
Copy link
Author

@codeworrior If I use data-sap-ui-language="en", it should also propagade this language to the SAP Gateway system or not?

@codeworrior
Copy link
Member

codeworrior commented Sep 9, 2016

Yes, the OData models (v1,v2 and v4) should do so if no higher prioritised way of specifying the language is used (URL parameter would override the script tag attribute, a runtime call to sap.ui.getCore().getConfiguration().setLanguage() would override all other configs).

[Update] I should mention that "propagate" for the models means: set the "Accept-Language" header. The logon to the systems (and therefore the SY-LANGU) AFAIK depend only on the logon process. That logon process is not under UI5 control and uses what you specify in the logon page.

@piejanssens
Copy link
Author

piejanssens commented Sep 9, 2016

I think my issue is related to #639

Although I set the language to EN and it works (because EN is the only bundle I have) the data returned from the backend is still in another locale (because in the request I can see Accept-Language: nl-BE or others).

@Michadelic
Copy link
Contributor

Hello piejanssens,

can you please share your code and steps to reproduce with us? From the discussions above i can see that some steps were tried but i cannot give further advice without the actual app coding.

As you can see from the documentation, the language is determined in the following order:

"OpenUI5 has the notion of a current language. It is determined from the following sources of information. The sources are ordered increasingly by priority and the last available user language/locale wins:

  1. Hard-coded UI5 default locale ('en')
  2. Potentially configured browser language (window.navigator.browserLanguage); for Internet Explorer this is the language of the Operating System
  3. Potentially configured user language (window.navigator.userLanguage); for Internet Explorer this is the language in the Region settings
  4. General language information from the browser (window.navigator.language)
  5. Android: Language contained in the user agent string (window.navigator.userAgent)
  6. Locale configured in the application coding (jsdoc:symbols/sap.ui.core.Configuration)
  7. Locale configured via URL parameters"

https://openui5.hana.ondemand.com/#docs/guide/91f21f176f4d1014b6dd926db0e91070.html

Kind Regards,
Michael

@piejanssens
Copy link
Author

Hi @Michadelic,

It's pretty straightforward. I put data-sap-ui-language="en" in the bootstrap attributes:

<script id="sap-ui-bootstrap"
    src="resources/sap-ui-core.js" 
    data-sap-ui-libs="sap.m"
    data-sap-ui-xx-bindingSyntax="complex" 
    data-sap-ui-compatVersion="1.16"
    data-sap-ui-language="en" 
    data-sap-ui-resourceroots='{"com.piejanssens.customapp": "./"}'
    data-sap-ui-theme="custom_bluecrystal@/sap/public/bc/themes/~client-010">
</script>

For now I only have a single i18n file:
i18n.properties

Because the app is now hard coded to use 'EN' I expect to get this language passed to the backend in the sy-langu variable. However here I see another user language like 'F' or 'N'.

@Shtilianova
Copy link
Contributor

I've created a internal incident 1770165099. You can check its status on GitHub

@matz3
Copy link
Member

matz3 commented Apr 21, 2017

Hey @piejanssens
After reading through the comments it seems to me that this is not an UI5 problem and especially not an OpenUI5 problem.

As already mentioned by @codeworrior:

That logon process is not under UI5 control and uses what you specify in the logon page.

Therefore I am closing this one. Please use the SAP Support in case you still have issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants