In this article I will tell you how to add support for various languages in the
program written in the previous article .
In our project we create a new package with the name “test.myfirstapp.lang” and create a file in it: Language.rrh
The name "Language" for the file is chosen arbitrarily for clarity. The .rrh extension means that the file is a language resource header.
')
When you create a Language.rrh, the file Language.rrc will automatically be created.
Language.rrc contains the body of the main language resource. There may be several files with the .rrc extension in the resource bundle. One for each supported language. The header file (.rrh) in the resource is present in only one instance.
Language resources are used to translate the interface of the program, its names and descriptions into other languages. In the application descriptor, you can specify a language resource that will be used to display the name of the program and its description.

If the program contains language resources, then when the system language changes on the device, the program language will automatically change if there is a corresponding resource for the current system language in the program.
If there is no corresponding resource in the program in the program, then the main string resource, the so-called “Root locale”, will be used.
There is one subtlety that I spent a lot of effort on identifying when I first started writing for BlackBerry.
At first, I could not even run the examples from the JDE suite. I didn’t change anything in them, I just installed JDE, opened examples in it, and started the compilation. After that, I received an error message about the assembly of the project, from which it was impossible to understand why.
The documentation about this anywhere said nothing. The support of Research In Motion, where I turned, met my question with sincere amazement, and I was told that everything should work, and they couldn’t attach mind, which is suddenly not even their exemplary projects. In short, they could not help me.
As a result, through trial and error, I came to the conclusion that for a correct compilation of a project containing language resources in the form of .rrh and .rrc files in the settings of the operating system for non-unicode programs, a language other than Russian should be installed. In my case, the options with English and German worked.
If “Russian” is set as the language for non-unicode programs, then when compiling the .rrc and .rrh files, files with incorrect characters in the names will be generated, which in turn will lead to a project verification error and an assembly error.
Later, this problem migrated from the Java Development Environment to the Eclipse JDE plugin, where it lives and survives today. And a newbie in programming for BlackBerry is completely unclear what is the matter and why even RIM examples are not compiled.
Let's return to our program. Open the “Language.rrh” file and in the window on the right, by clicking on the “Add key” button, create three key-value pairs.
NOTE_APP_TITLE - for the program name
NOTE_APP_DESCRIPTION - for a brief description of the program
NOTE_HELLO_WORLD - with welcome text
Now we have a primary language resource with three string values.
Now we add an additional file to the language resource to display the program interface in Russian.
The name of this additional file should begin the same way as the name of the main one, but in addition to it the language code is assigned.
In our case, the name of this file will be "Language_ru.rrc"
As a result, at the very bottom of the window with the contents of the language resource, an additional tab “ru” will appear next to the “Root” tab.

Having opened that, we will indicate the values for all keys in Russian.

When the project is compiled, the .rrc and .rrh files are converted into a regular java-interface, the name of which is formed from the name of the main language resource (in this case, “Language”) and the word “Resource”, and which must be implemented by the class that uses language resources . This generated interface is not visible in the project, but it is invisibly present there and must be implemented to get access to the constants declared inside this interface.
So, we make changes to the MyAppScreen class.
package test.myfirstapp.view; import test.myfirstapp.lang.LanguageResource; import net.rim.device.api.i18n.ResourceBundle; import net.rim.device.api.ui.component.LabelField; import net.rim.device.api.ui.container.MainScreen; public class MyAppScreen extends MainScreen implements LanguageResource { private static ResourceBundle resources = ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME); public MyAppScreen() {
By default, the simulator does not include Russian language support. Do this to see the modified program in work.
To add Russian language support to the device simulator (in this case, the Storm 9550 and API 5.0.0), open the
9550.xml file in the internal Eclipse folder “plugins \ net.rim.ejde.componentpack5.0.0_5.0.0.25 \ components \ simulator ”and add the line to it:
< Application > net.rim.blackberry.lang.ru </ Application >The figure below shows the changes in the simulator configuration xml file:

Everything, now you can run the application for execution.
The animation below shows the process of launching our program, first with English as the system language, after which the settings change the language to Russian and the program starts with Russian as the system language.

You can add other languages to the simulator. Below is a list of xml expressions that need to be added to the simulator configuration file to enable support for the corresponding language.
French :
< Application > net.rim.blackberry.lang.fr </ Application >German :
< Application > net.rim.blackberry.lang.de </ Application >Italian :
< Application > net.rim.blackberry.lang.it </ Application >Spanish :
< Application > net.rim.blackberry.lang.es </ Application >English (UK) :
< Application > net.rim.blackberry.lang.en_GB </ Application >English (United States) :
< Application > net.rim.blackberry.lang.en_US </ Application >English (Holland) :
< Application > net.rim.blackberry.lang.en_NL </ Application >Portuguese (Brazil) :
< Application > net.rim.blackberry.lang.pt_BR </ Application >Polish :
< Application > net.rim.blackberry.lang.pl </ Application >