Posted May 31, 2012 by Rapid John in Developers
 
 

BlackBerry App Internationalisation

App Localisation
App Localisation

Did you know that you can internationalise your BlackBerry application using the JSR 238?

All commercial applications these days should be localised, and BlackBerry uses net.rim.device.api.i18n package to enable seamless localisation.

You can do the following to your BlackBerry application so that your app is ready for the International market:

  • Multiple language support
  • Localization of currency
  • Localization of addresses
  • Detecting which country the user is located in (in the event that you have certain content that you only have license to serve in certain geographies)

If your application is localised, it will be displayed in the local language out of the box. So if the default locale settings on one device are set to English and French on the other, the application will be displayed in the correct language on both devices without any need for interaction from the user.

Setting up a New BlackBerry Project

If you need a reminder, how to setup and configure a new BlackBerry project, refer to this link.

Here is sample code to show how to localise a simple application:

package com.rim.samples.local;

import net.rim.device.api.ui.MenuItem; import net.rim.device.api.ui.UiApplication; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.i18n.*;

public class Local extends UiApplication { public static void main(String[] args) { Local theApp = new Local();

theApp.enterEventDispatcher(); }

public Local() { pushScreen(new LocalScreen()); } }

final class LocalScreen extends MainScreen implements LocalDemoResource {

private static ResourceBundle _res = ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME); LabelField title; RichTextField rtf;

public LocalScreen() { super(); title = new LabelField(_res.getString(FIELD_TITLE), LabelField.ELLIPSIS| LabelField.USE_ALL_WIDTH); setTitle(title); rtf = new RichTextField(_res.getString(MESSAGE)); add(rtf); }

If you read the code carefully, you will notice that our LocalScreen class implements LocalDemoResource. Also new is the ResourceBundle variable _res which is used when creating our fields. To be able to use and explain them, we will first create our resource files.

Creating resource files

To be able to localise your application, you need to create .rrc and .rrh files. It is quite easy to create these files in Eclipse. Click on File->New->BlackBerry Resource File and browse to the location of your package. You will need to name your header file here — let’s call this file LocalDemo.rrh (make sure you include the extension). Pressing Finish on this screen will now allow you to implement LocalDemoResource interface.

If you called your .rrh file “exampleResource.rrh”, then the interface name would be exampleResource. Now we need to create resource files for each language:

For default language: LocalDemo.rrc
French: LocaLDemo_fr.rrc
Spanish: LocalDemo_es.rrc.

The parts of the name _fr and _es are default endings for those languages and cannot be changed.
If you did everything correctly, you should have 4 resource files just under your Local.java file. Now we need to edit these files. Double click on the LocalDemo.rrh file — this is the one which contains all the keys. Select the ‘Add Key’ Button and add the following fields:

CLOSE, ENGLISH, FIELD_TITLE, FRENCH, GOODBYE, MESSAGE, SPANISH.

You do not need to enter the values on this page. When you double-click on the LocalDemo.rcc file, it will open the screen where you can fill in the values. You can access the values for French and Spanish locales by clicking on the tab on the bottom of the window (marked fr or es), or by double-clicking on the file name.

As you can see, special characters used in these languages such as ‘ó’ in word “adios” or ‘ñ’ in “Español” were used. The system will use those characters and display them when needed. You can use any Unicode characters here, which means you can support languages such as Chinese or Arabic.

And that’s it! That’s all you have to do add multiple language support to your BlackBerry application. For more info and to see a full working demo, refer to this link

Did you enjoy this article? If so, we’d love to hear your thoughts on the Forums or on our Facebook page. Get more articles instantly on your BlackBerry smartphone with our Free BlackBerry 10 App.

Via BlackBerry DevBlog

Enjoy this article? Share it with others.

  • Facebook
  • Twitter
  • StumbleUpon
  • LinkedIn
  • Digg
  • Pinterest
  • Google Plus
  • Tumblr
  • Reddit
  • Instapaper
  • Delicious
  • Email
  • Print