Skip to Content
0
Former Member
Nov 26, 2012 at 09:37 AM

SAPUI5 Language switcher

391 Views

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

Attachments

all-elements.jpg (22.0 kB)