Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Eclipse Java ME (J2ME) Developer Guide
Previous Page Home Next Page

Add localization support to a MIDlet

In this section, you will learn how to use the localization support available in MTJ.

Enabling localization support

  1. In the Package Explorer view, right click the Project folder and select the Mobile tools for java > Enable Localization option.

    Enable Localization

  2. On the Localization wizard, select the appropriate information on where to generate the localization *.properties files and the package where Localization API classes will must be generated.

    Localization Wizard


If you have completed the above steps, the Package Explorer view will now contain 3 new files:

  • L10nConstants.java
  • L10nResources.java
  • Localization Data

The new MIDlet project

Adding new locales and entries

  1. In the Package Explorer view, double click the Localization Data file to open the Localization Data editor.
  2. On the Localization Data Section, click on the Add Locale button. This will add a new locale (The default locale is en-US).

    Localization Data Editor

  3. Save the Localization Data file.

    The L10nConstants.java file will be recreated with a new constant mapping the new added locale.


    L10nConstants.java File

    The file messages_en-US.properties will be created in the folder you specified in the Localization Wizard.


    messages_en-US.properties File


  4. Now, click on the Add Entry button. This will add a new entry to the selected Locale.

    Localization Data Editor

  5. Save the Localization Data file.

    The L10nConstants.java file will be recreated with a new constant mapping the new locale entry.


    L10nConstants.java File

    The file messages_en-US.properties will be will be update with the value you added through the editor.


    messages_en-US.properties File



Using the Localization API

  • The localization API consists of two classes the L10nResources and the L10nConstants.
    • L10nResources

    • L10nResources class manages localized resources by it's utility methods. A list of available methods is show below:

      public void setLocale(String locale) throws IOException;
          Sets the locale of the L10nResources instance.

      public String getString(String key, String[] params);
          Gets the value for the specified key. For every parameter on the params argument there must be an entry in the key value in the format {x} where x is the index of the value to be replaced on the formated string.

      public String getString(String key);
          Gets the value for the specified key.

      public byte[] getData(String key) throws IOException;
          Gets the binary data associated to the path set as value of the specified key.

    • L10nConstants

    • L10nConstants must NOT be changed by the developer since it is auto generated every time the Localization Data file changes.



 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire