Adding Localization Support to a MIDP Application
See Also
Adding Localization support to your MIDlet is a four-step process:
- Create the java classes that initialize the localization support and message
property files. The messaged property stores the localization keys and their
values.
- Change the Internationalization String and Search formats.
- Add the localization keys and their values to the properties file.
- Add
getMessage()
methods to your MIDlet to identify elements to be localized.
To create the initial class and properties files:
- Select a Java ME MIDP project node (
)
and choose New > File/Folder.
- Under Categories, select MIDP. Under File Types, select
Localization Support Class. Click Next.
- Enter the values required for the New
Localization Support Class wizard.
The wizard creates two files:
- <Localization Supportfilename>.java. A
Java class with the code that initializes localization.
- <messages filename>.properties. A properties
file where message keys and their localized values are stored.
To Change the String and Search formats:
- Choose Tools > Options from the Main Menu.
- Click the Advanced Options button.
- Choose the Internationalization node in the Options menu tree.
- In the properties window:
- Change the value of the II8N String Format property to
LocalizationSupport.getMessage("{key}")
- Change the value of the II8N Search Format property to
(getString|getBundle|getMessage)[:space:]*\([:space:]*{hardString}|//NOI18N
To add localization keys and their values:
- Navigate to the
.properties
file and double-click on
its node.
This opens the file in the Source Editor.
- Use the Source Editor to add your keys and their
values into
the
.properties
file.
For example, LAB_NextButton = Next.
To add code to initiate localization:
- Enter the following string
in your MIDlet wherever you want a key localized:
LocalizationSupport.getMessage("Key");
For example, LocalizationSupport.getMessage("LAB_NextButton");
- You can use the NetBeans Internationalization
wizard to complete the key/value pairs. Choose Tools > Internationalization
> Internationalization Wizard and modify the values according to directions.
After all the strings have been added to the messages.properties
file, do
the following to add values for each new locale:
- Right-click on the file node in the Projects view and choose Add Locale.
- Choose a locale you want to support from the Predefined Locales list
box, or use the combo boxes at the top of the form to define a new locale.
- Expand the message.properties node in the Projects view, and double-click
on the newly-added locale.
- Translate all properties into the appropriate language.
The mobile application will use the microedition.locale
attribute
to determine which version of the messages.properties
file should
be used.
- To see an example of a localized project, Choose File > New Project.
Under Categories, expand the Samples node and choose Mobile. Under Projects,
choose Localization Support Example.
- See Also
- About Localization
Legal Notices