on 06-22-2016 7:47 AM
Hi all,
I have currently an issue with switching the language of an SAPUI5 application after the user have successfully passed the login of the application server. When the application is called with the default parameter in the uri to set the language (http://sapr3entw.com:8082/sap/bc/ui5_ui5/sap/zpropla/?sap-language=en) the login mask shows the correct language.
After a successfull authorization the browser forwards to the orignal requested application without the neccessary language-parameter in the uri and the application is loaded in German instead of English. After the user is logged in and the the uri with the language parameter (?/sap-language=en) is called again the language will successfully switched to English.
In the developer guide (https://sapui5.hana.ondemand.com/#docs/guide/91f21f176f4d1014b6dd926db0e91070.html) I have seen that there is an existing order how the language is set within the application, but there is no information how to get/set the language of the current logged in user of the application server (selected language in the login mask).
Any ideas how to set the language of an SAPUI5 application according to the language set from the login?
Would be thankful for any hint.
Kind regards
Martin
Hi Martin,
You can use messageBundle concept here. Firstly get the selected language and store it in the Local storage for further use.
Now, after you logged in get the selected language and send that to the core.
if(localStorage.langu) //getting the language from login page.
{
var messageLanguage = localStorage.langu; //assigning it to a variable
}
else{
var messageLanguage = 'en'; // setting default language.
}
sap.ui.getCore().getConfiguration().setLanguage(messageLanguage); //setting the selected language to the core.
messagebundleLocal : messageLanguage; //assigning language to the message bundle.
Try this it worked for me.
Thanks,
Moulika
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Moulika,
thank you for describing your solution. You wrote in your second sentence that the language should be selected and stored in the local storage. But where do you get the language from? Do you mean that within the login screen the language should be stored in the local storage? Is the language set in the local storage per default?
Thanks,
Martin
Hi Martin,
Check this:
https://sapui5.hana.ondemand.com/#docs/guide/91f225ce6f4d1014b6dd926db0e91070.html
Example snippet:
var oModel = new sap.ui.model.resource.ResourceModel({
bundleUrl: "i18n/i18n.properties"
});
sap.ui.getCore().setModel(oModel, "i18n"); // global model is appropriate when having one translation file for the whole app
This will automatically use the current language; for other languages, you can also give a "bundleLocale" in the ResourceModel constructor.
You can now bind your text with
text : "{i18n>MY_BUTTON_TEXT}"
and in an XMLView you could now say:
<Button text="{i18n>MY_BUTTON_TEXT}" press="sayHello" />
Thanks & Best Regards,
Venkatesh Sora
Hi Moulika,
i have implmented your solution and it seems to work fine. In login.js (/SAP/PUBLIC/BC/UI2/logon/) i added a new function and call it within the submitLogin.
fioriLogin.handLanguageOver = function () {
if (typeof(Storage) !== "undefined") {
var select = document.getElementById("LANGUAGE_SELECT");
localStorage.setItem("lang", select[select.selectedIndex].value );
} else {
// No Web Storage support..
}
};
But i would suggest another solution: Next to forwarding the URI-hash (e.g. /#/project/participation) in login.js i would also append the URI-search (parameters - e.g. ?sap-language=en) after a succesfull login.
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.