on 11-26-2012 9:37 AM
Hello everybody,
I'm currently trying to implement a language switcher in SAPUI5 but I have a few problems/needs for enhancements there.
The idea is to create a dropdownbox that'll let the user decide on the language he wants to see for the page.
I'm wondering if my current method of switching the language is really the best solution or if there are any better solutions to this?
My current code looks like this:
// Create a ListBox
var oListBox1 = new sap.ui.commons.ListBox("Languages", {
items: [new sap.ui.core.ListItem("Lang1", {
text: "German"
}), new sap.ui.core.ListItem("Lang2", {
text: "English"
})]
});
// Create a DropdownBox
var oDropdownBox2 = new sap.ui.commons.DropdownBox("DropdownBox2", {
tooltip: "Language",
"association:listBox": oListBox1,
value: "German"
});
oDropdownBox2.attachChange(function () {
// TODO Change locale here
if (oDropdownBox2.getValue() == "German") {
var oBundle = jQuery.sap.resources({
url: "res/i18n.properties",
locale: "de"
});
updateTexts(oBundle);
} else {
var oBundle = jQuery.sap.resources({
url: "res/i18n.properties",
locale: "en"
});
updateTexts(oBundle);
}
});
function updateTexts(oBundle) {
oLinkPassword.setText(oBundle.getText("LINK_PASSWORD"));
oTvPasswordInfo.setText(oBundle.getText("MSG_PASSWORD"));
oLinkPin.setText(oBundle.getText("LINK_PIN"));
oTvPinInfo.setText(oBundle.getText("MSG_PIN"));
oLinkRegister.setText(oBundle.getText("LINK_REGISTRATION"));
oLinkContact.setText(oBundle.getText("LINK_CONTACT"));
oLinkImpressum.setText(oBundle.getText("LINK_IMPRESSUM"));
oLinkThemeSwitch.setText(oBundle.getText("LINK_THEMESWITCH"));
oTvUser.setText(oBundle.getText("USER"));
oTvPassword.setText(oBundle.getText("PASSWORD"));
oBSend.setText(oBundle.getText("SEND_BUTTON"));
oTVSuccessMsg.setText(oBundle.getText("Checking..."));
oTVSuccessMsg.setText(oBundle.getText("LOGON_SUCCESS"));
oTVSuccessMsg.setText(oBundle.getText("LOGON_FAILED"));
}
Edit: Created a separate thread for the CSS problem (http://scn.sap.com/thread/3271946).
Message was edited by: Department Portals
There may also be a backend language consideration if any of the UI texts are sourced from the backend and have a language dependency.
I have encountered some issues with using the normal channels for language settings, e.g. the language you log in with is stored in a cookie and set s the backend language. After that it can be hard to get a different language accepted if one is sent in an OData request.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Department Portals,
in my application i resolved this problem with following class:
Simply instantiate it with:
var oMyResourceModel = new sap.ui.model.resource.ResourceModel({bundleUrl: "res/i18n.properties", bundleLocale: "en"});
Then you set the model to your view/core/element with a specific key:
sap.ui.getCore().setModel(oMyResourceModel, "myResourceKey");
Now all your bindings have to look like this:
var oButton = new sap.ui.commons.Button({
text: "{myResourceKey>my_button_text}"
]);
my_button_text should be contained in your i18n.properties file of course 😉
Now you are able to change the language with only instantiating a new ResourceModel and set it to your core/view/control or whatever :-).
I hope i could help you.
Kind regards,
Andreas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
my .properties files are in the "localization" folder which is in the project(your application name) folder.
So the path for my ResourceBundle is <project_name>/localization/<name>.properties.
You have to specify the relative path down from your "WebContent" folder.
Hope i could help you
Best Regards
Andy
Hi,
thanks for your fast answer!
seems to be a problem by submitting with the team provider, because the team provider submits to a bsp application, and there it reorders the folders. when i create a folder in WebContent, add the file there, it does not upload the file, and so i cannot reach in the application.
br alex
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.