Localizing Applications


In the mobile development world, there are many different ways of handling localization or translation of your product into different languages. The official support within the NetBeans Mobility Pack is based on the concept of using bundled message.property files. The messages file, and a small support class that uses it, can be generated for you automatically by the Localization Support Class template:

  1. In the Projects window, right-click the package you would like to contain your LocalizationSupport class and choose New | Localization Support Class. If that option is not available directly in the menu, choose File/Folder to display the full array of templates.

    Alternatively, select File | New File (Ctrl-N) from the main menu.

  2. Select the MIDP node in the Categories list box and then Localization Support Class in the File Types list, and click Next.

  3. Optionally, fill in the following fields in the Name and Location panel of the wizard:

    Class Name: The generated class' name.

    Messages Bundle Name: The name of the message bundle.

    Package: The package in which to create the files.

    Default String Value: The value that is used if a property is not found in the message bundle.

    Error Message: The error message that is displayed when there is a problem loading the message bundle.

  4. Click Finish to create the files in the locations displayed in the Created Class File and Created Bundle File fields.

The automatically generated support class should now appear in your project and can be modified as desired. The following process outlines how an existing application can be localized using the support class:

  1. All hard-coded text strings from your application should be added to the created message.properties file using the following format:

    PROPERTY_NAME=My Translatable Text String

  2. The strings in your source files should then be replaced with code like this:

    LocalizationSupport.getMessage(" PROPERTY_NAME")

  3. Once all strings have been added to message.properties file, right-click its node in the Projects window and choose Add Locale.

  4. Select a locale that 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.

  5. Click OK.

  6. Expand the message.properties node in the Projects window and doubleclick the newly added locale.

  7. Translate all properties into the appropriate language.

  8. Repeat these last five steps until all supported languages have been added.

This technique uses the microedition.locale property of the phone to determine which version of the message.properties file should be used. If the region is not found, the default bundle is used.

If you prefer, you can force a particular region to be used by calling the following code before using LocalizationSupport.getMessage():

LocalizationSupport.initLocalizationSupport("en_US")


In this case, the en_US version of the message.properties file is always used. Forcing a region is useful when you are planning on supporting only one language per distribution JAR file. The Filtering panel should be used to ensure that only the used properties file is bundled with the application.



NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net