04-09-2009 10:21 AM
Hi, I have wrote an application, which supports two languages: German and English. I have an problem with the next scenario:
1) the device language is set to English.
2) my application is open.
3) I minimize the application, go to the options->language and change it to German
4) I save changes and switch back to my application
5) the localized contents are shown in English anyway
6) first as I switch to another screen of the application, the localized contents are shown in German, as intended
7) after that all localized contents everywhere in the application are shown in German
Interesting is, that if I open an (custom) menu before I minimize the application in 3), the content of this menu is updated and is shown in German already in 5)
The question is: should I override UIApplication.activate() and try to detect the language setting change there and reopen the screen if the language changed or is there an more simple solution to this issue?
04-14-2009 04:50 AM
OK, this solution works:
public class MainController extends UiApplication{ private Locale currentLocale = Locale.getDefaultForSystem(); public void activate(){ if (currentLocale != Locale.getDefaultForSystem()) { currentLocale = Locale.getDefaultForSystem(); /* here I have the code, refreshing the active screen */ } } }
any better ideas anyone?
04-14-2009 05:12 AM
04-23-2009 12:23 PM
04-23-2009 01:51 PM
Some UI objects support localization by default (e.g., the MenuItem constructor and the setTitle method of MainScreen can take a bundle and a resource id). Many of the other UI elements don't support localization, but you can do it yourself without much effort.
public class MyScreen extends MainScreen {
private ButtonField button = new ButtonField();
public MyScreen() {
add(button);
}
protected void onDisplay() {
super.onDisplay();
update();
}
protected void onExposed() {
super.onExposed();
update();
}
private void update() {
button.setLabel(bundle.getString(BUTTON_NAME));
}
}
When your screen first gets pushed onto the stack (onDisplay) or when it gets redisplayed (onExposed), the update method will reset the label for the button.
You can also subclass the fields you use and implement the same three functions on the field.