}
// get the locale if stored in the browser
String localeStored = "";
if (Storage.isSupported()) {
Storage localStorage = Storage.getLocalStorage();
localeStored = localStorage.getItem("locale");
}
// select the right locale in the list if one is predefined
if (localeStored != null) {
for (int i = 0; i < languageSelector.getItemCount(); i++) {
if ( localeStored.equals(languageSelector.getValue(i))) {
languageSelector.setSelectedIndex(i);
}
}
// otherwise provide the default
} else {
for (int i = 0; i < languageSelector.getItemCount(); i++) {
if (languageSelector.getValue(i).equals("default")) {
languageSelector.setSelectedIndex(i);
}
}
}
sectionChangeLocale.add(titleCL);
sectionChangeLocale.add(instructionCL);
sectionChangeLocale.add(changeLocale);
account.add(sectionChangeLocale);
addWidgetRow(changeLocale, uiText.Language(), languageSelector);
languageSelector.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
String value = languageSelector.getValue(languageSelector.getSelectedIndex());
// store the new default value if possible or remove the value in case
// of default (English)
if (Storage.isSupported()) {
Storage localStorage = Storage.getLocalStorage();
if (value.equals("default")) {
localStorage.removeItem("locale");
} else {
localStorage.setItem("locale", value);
}
}
// construct the new url with the locale parameter