We have recently added support for the Nokia Java SDK, which is an Eclipse based IDE for Java ME development. This post covers basics on how to get started with localizing your Java ME apps for multiple languages by using the Get Localization Sync plug-in and Nokia Java SDK.
Getting Started: Install Everything
If you don’t have the latest Nokia Java SDK, you can download it from http://www.developer.nokia.com/Develop/Series_40/.
Then you need the Get Localization Sync plug-in.
- Open your Nokia Java SDK
- Choose Help -> Install new software…
- Click ‘Add…’
- Enter a name for the repository, e.g. Get Localization
- Enter the repository location, which is http://getlocalization.sync.s3.amazonaws.com
- Click ‘Ok’
- Check ‘Get Localization Sync’ plugin
- Click ‘Next’ and follow instructions
If you are not aware of the concept of internalization or I18n, please refer to our earlier blog post Software Internalization for Dummies. Java ME is one of those frameworks that are shipped without a standard internalization framework. Fortunately Nokia provides internalization support within their SDK and it’s easy to set up.
When you create a new project, you have an option to ‘Enable Localization Support’ (see screenshot below). This feature allows you to localize your application strings easily.
TIP: If you already have a project and/or an existing app, you can enable the localization support by right-clicking your project and selecting ‘Mobile Tools for Java’ ⇒ ‘Enable Localization’.
So now you have everything set up, let’s see what the SDK created for us:
As you can see, there’s now two new files inside the package that we defined in the previous step.
L10nConstants.java – This is a generated Java file and will contain all the metadata of your localization data.
L10nResources.java – This is a utility class for loading the strings inside your UI.
Then we got the new editor called Localization Data. This editor is used to manage all your application strings. First you need to add your first ‘locale’ i.e. the language your application will be translated from. We recommend writing the initial version in English, as it’s easier to find translators to translate from English than other languages. Click the ‘Add locale’ button and it will add automatically en-US language for you. Make sure to check ‘Default locale’ on for this language (you can find this option to the right). You can also modify the language and country code here if you want but it’s not necessary if your app is in English.
Next you can add your first entry. Entry is a string you are using in your application, let’s say you have a ListBox element and you are setting a title for it like this:
listBox.setTitle("My Awesome App");
Now, what you want is to add this very same text as an entry to the localization file. Click ‘Add entry’ button in Localization Data editor and define key for this entry e.g. LISTBOX_TITLE and then the value ‘My Awesome App”‘ Hit save and now a few things happened:
1. Inside the res folder you can find a file called messages_en-US.properties. This is a master file which will be translated into another languages.
2. L10nConstants.java was generated and updated.
This means that you can now modify your code to use these new classes.
First of all, you need an instance of L10nResources, for example:
L10nResources res = L10nResources.getL10nResources(null);
Given parameter is null here but you could also define language code here e.g. “en-US” or “fi-FI”. It’s good for testing purposes so you don’t have to change e.g. your emulator language. Giving null means that it will try to use the same language the device is currently using.
Now we can actually load the string from resources instead of hardcoding it:
That’s it. Now the text is always loaded from resource files based on the phone language.
That was easy. Now it’s time to start translating your app and for that Get Localization is the perfect companion. It is a browser based service that will help you manage the files, translate them and even let you to manage your own translators if you wish. This part assumes that you are familiar with Get Localization already. If not, then please visit the frontpage, take a tour or if you have questions, create a support ticket in the ticketing system and someone will get back to you ASAP.
Configuring the Get Localization Sync Plug-In
First you need to configure your Get Localization Sync plugin. I hope you already installed it but if not, please refer to the section ‘Getting started: Install everything’. Now in Package Explorer, right-click your project name e.g. MyApp in Screenshot #2 and select ‘Properties’. Then find Get Localization Sync leaf in your properties and you should see the below screen:
The following fields are used:
Username – Your Get Localization username
Password – Your Get Localization password
Project – Your Get Localization project name (same that appears in project URL e.g. http://www.getlocalization.com/example/, where example is your project). If you don’t have project, please create one first at http://www.getlocalization.com/signup/
Default Platform – Platform you are developing on. IMPORTANT: You should choose “Java Properties (UTF-8)”
Pull file filter allows you to filter which files you wish to pull to your Eclipse project. For example just pull all the .properties files, you can use filter:
Replace rules can be used to alter file names when they’re pulled to project. Typically it’s not necessary but you can e.g. rename language codes in files in case they happen to be wrong.
Replace rules can be imported and exported so if you manage to do proper rules, please do share them with us. We’re happy to add them to our library.
Sending Files to Translation
Simply right-click the file in the res folder called messages_en-US.properties, then select ‘Get Localization Sync’ ⇒ ‘Send to translation’.
Syncing Translations Back to Project
When the files have been translated, you can sync them easily back to your project. Right-click ‘res’ folder and select ‘Get Localization Sync’ ⇒ ‘Sync translations to this folder’ and that is it.
Localizing Your Other Data
Metadata such as Store Description
It’s highly recommended to localize your store description and other meta data. You can add multiple files to Get Localization so it’s easiest to add the store description e.g. as a plain text file. You can do this via browser on Get Localization project (Files tab) or via the plug-in.
Dates and Times
Java ME does provide some help to localize dates and times. What you want to do is to provide them both in the same format based on user settings. These settings are already configured in the device and accessing them is easy.
You can get currently used date format using following piece of code:
String format = System.getProperty("com.nokia.mid.dateformat");
This method returns for example these values with following settings:
Gregorian calendar date in little endian format: dd-MM-yyyy
Gregorian calendar date in big endian format: yyyy/MM/dd
Gregorian calendar date in big endian format: yyyy-MM-dd
Note that the date separator can be often changed from the phone settings.
In a similar way you can also get the time format which the Nokia Series 40 or Asha device is configured to use.
String timeFormat = System.getProperty("com.nokia.mid.timeformat");
In this case the return values are a bit simpler:
HH:mm means 24 hours clock
hh:mm a means 12 hours clock