JAVA - LWUIT :Localization problem

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?

This question and answers originated from www.stackoverflow.com
Question by (8/2/2011 4:09:32 PM)

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

Answer by

Find More Answers
Related Topics  java  java-me  localization  internationalization  lwuit
Related Questions
  • LWUIT : arabic font problem

    Hi how can i add arabic Characters to bitmap font and show in application ? how can i do it on localization section ? when i use system font it`s shows seprated and reserved on some phones , i want …
  • LWUIT : Form Problem

    i have started using LWUIT which sounds interesting , i have made a form and has simply added an image to its background , my problem is that the image is getting streched and looks bad :D is there …
  • LWUIT: Layout calculation problem

    I have a rather large application written with LWUIT. With only a few screens that have the problem. The problem: When the page loads, everything looks fine. but when you scroll you can't scro…
  • LWUIT 1.5 Table - horizontal spanning problem

    I am wondering if this is a bug or just my faulty code. I've been trying to render table with some horizontal spanning. This is how it should look like: In LWUIT 1.4 everything worked correct…
  • LWUIT ComboBox popup theming problem

    I want to customize the look of the ComboBox pop-up list in LWUIT. Nonetheless when I tried to change the ComboBox , ComboBoxFocus , ComboBoxItem , ComboBoxList , ComboBoxPopup components in LWUIT T…
  • LWUIT Dialog problem with dispose()

    I am making a dialog with a command. This command must close the dialog and go back to the previous form, but it is not working as expected. When I press the command, it closes the dialog but the fo…
  • LWUIT List index problem and Is a bug of LWUIT List?

    I write j2me application that display list with labels and I add images to the labels and show it. I handle event for List with Action Listener. When I press label in List, event is handle by Action…
  • LWUIT HtmlComponent Lines don't get wrapped + Parser Problem

    I think I'm facing a simple layout problem. I'm embedding a HTMLComponent on a Form via LWUIT, this HTMLComponent displays a local HTML file. The result has no line wrapping but endless scrolling i…
  • LWUIT Scrolling

    Here is another question regarding JavaMe and LWUIT. I need to manually scroll textarea with help of methods or etc. TextArea contains methods responsible only for obtaining current position of s…
  • LWUIT assistance

    import com.sun.lwuit.Button; import com.sun.lwuit.Command; import com.sun.lwuit.Display; import com.sun.lwuit.Label; import com.sun.lwuit.events.ActionEvent; import com.sun.lwuit.events.ActionListen…