Tutorial: Connect IQ string resources

 .

Prerequisites



Why?

For people it’s usually more enjoyable if they can use a program in their mother tongue.

Create the main resource


Edit the main resources of the application by navigating to resources -> strings -> strings.xml. Right click and choose Open With -> Text Editor and provde the resource names and resource values:

Create the translated resources

For each language that we will support we now have to create values in the corresponding resources group.
In this tutorial we’re going to provide resources for the dutch language.

  • Copy the strings folder from the main resources to the language specific folder (resources-dut in our example) (CTRL+Click&Drag – Choose Copy Files and Folders)
  • Edit the strings.xml file (Right Click. Open With -> Text Editor) and provide the translations:

Alter the code to use the resources

The resources internal representation is a number (and not the actual text).
To show the actual text from the resource (in the current language) an extra function call is necessary.
We change the variable name from label to labelResource and initialize it with the resource value for the TotalSteps. We also change the variable name mValue to just be named as value: In the compute function we do a similar replace and change all the label statements to their resource equivalence, the final result of your replace will be that your compute function looks as follows: To display the actual label text, we call the Ui.loadResource() function on the labelResource in the onUpdate function, after your modifications the function will look as:

Test your data field

In the simulator:

  • Start the timer (Data Fields -> Timer -> Start Activity)
  • Change the language (Settings -> Language ->)

Source Code

You can download the full source code from here


In the next tutorial we’ll learn how to create a unit test project

Feedback

Did you like this article?Questions?
  • Post in the comments section below!

Leave a Reply