JAVA - LWUIT :Localization problem
العربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
I have made a simple form with one textFeild and a command, I want to have two languages: Farsi and English so that I can use them according to my needs at runtime.
I made some translations using ResourceEditor and saved them under the name English.res and Farsi.res, then added them to my resources.
Now I have a problem calling Localization method, as I have no idea how to do that... I will post my code here, please correct me.
This is my code:
public class Midlet extends javax.microedition.midlet.MIDlet {
private Hashtable locale;
public void startApp() {
Display.init(this);
try {
Resources res = Resources.open("/Lang.res");
//Lang.res is resource file where these languages are stored
// using resoureEditor.
locale = res.getL10N("English.res", "en");
/* See text below. */
} catch (IOException ex) {
ex.printStackTrace();
}
Form main = new Form((String) locale.get("FORM"));
main.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
Label label = new Label((String) locale.get("NAME"));
TextField tf1 = new TextField("");
Button button = new Button((String) locale.get("OK"));
main.addComponent(label);
main.addComponent(tf1);
main.addComponent(button);
main.addCommand(new Command((String) locale.get("BACK")) {
public void actionPerformed(ActionEvent evt) {}
});
main.show();
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
}
And this is my English.res:
#Export locale from the Theme Creator
#Tue Aug 02 19:35:55 IRDT 2011
FORM=form
OK=ok
BACK=back
NAME=name
Are these two lines in the try block correct?
Resources res = Resources.open("/Lang.res");
locale = res.getL10N("English.res", "en");
Lang.res is resource file where these languages are stored using resoureEditor.
What else do I need to do?
I get an exception in the first line. en is the name of the needed language locale, matching to the value column in res file.
I'm still not sure if it's correct or not but, what is this first argument? Locale?
Answer |
i have solved my problem , the name i was passing to getL10N() methos was incorrect....now im getting languages for both persian and english. but the problem is that the Titiles and Commands are not showing in persian :( i mean FORM and BACK are not getting translated to persian , In English all of them are getting translated. even when i put their name as persian constants , they r not comming in the form.. do i need to write extra codes for title and command?? pls helppppppp me