June 4, 2007
In today’s global economy, it is now more important than ever for software to be written with localization in mind, and mobile applications are no exception. Thankfully, NetBeans Mobility Pack makes the task easier with built-in support for MIDP localization. In this article we will take a look at MIDP localization, and how NetBeans helps us implement localized applications.
A localized application has the ability to display text for the correct language based on the locale of the device. This includes text for labels, alerts, commands, buttons, etc. A localized application should be able to support new languages without making modifications to the application logic. In Java ME, this is achieved through MIDP localization.
The current locale of the device can be determined by querying the microedition.locale system property. For example:
String curLocale = System.getProperty("microedition.locale");
One approach to localization involves the creation of property bundle files containing name-value pairs which represent all the various pieces of text to be displayed in the application. NetBeans Mobility Pack provides an MIDP localization wizard to facilitate the maintenance and use of such property bundle files.

To start, right-click on the node for your MIDP project, select “New File/Folder…”, and then select “MIDP” > “Localization Support Class.” On the next dialog, simply accept the default values by clicking “Finish.”
You should now see a new class in the project tree named LocalizationSupport, as well as a messages.properties file. Open the messages.properties file by double-clicking on its node, and add the following line to define a localization key and value:
Title = Hello World
Now, let’s add a new locale. Right-click on the messages.properties node in the project tree, and select “Add Locale…” Choose a locale from the list; for this example, I selected “es_MX”. Now expand the messages.properties node, and you will see a new sub-node titled “es_MX – Spanish (Mexico)” beneath the “default language” node. Double-click the “es_MX” node to open the localized file. You should see that the “Title” property has been copied from the default language file. Change the value “Hello World” to “Hola Mundo”, and save the file.
Within your application, you can now do the following to retrieve the localized string:
String title = LocalizationSupport.getMessage("Title");
Last but not least, you may want to test your application for different locales. Luckily, it is possible to emulate a user-specified locale in the WTK emulator. Search for a file called “ktools.properties” in your wireless toolkit folder. By adding the line below to this file, the emulator will emulate the specified locale.
microedition.locale=es-MX
For more information about localization in Java ME, check out the resource below. Also, be sure to read the page titled “Adding Localization Support to a MIDP Application” in the NetBeans IDE Help.
Filed under Java ME Development