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:

Monkey

1

2

3

4

5

6

7

<strings>

<stringid="AppName">Steps Carousel</string>

<stringid="TotalSteps">Total</string>

<stringid="ActiveSteps">Steps</string>

<stringid="StepsToDo">ToGo</string>

<stringid="GoalPercentage">Goal(%)</string>

</strings>

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:

Monkey

1

2

3

4

5

6

7

<strings>

<stringid="AppName">Steps Carousel</string>

<stringid="TotalSteps">Totaal</string>

<stringid="ActiveSteps">Stappen</string>

<stringid="StepsToDo">Te Gaan</string>

<stringid="GoalPercentage">Doel(%)</string>

</strings>

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:

Monkey

1

2

hidden varvalue=0.0f;

hidden varlabelResource=Rez.Strings.TotalSteps;

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:

Monkey

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

//The given info objectcontains all the current workout

//information.Calculateavalue andsave it locally inthismethod.

functioncompute(info){

varactivityMonitorInfo=Toybox.ActivityMonitor.getInfo();

if(timerRunning){

stepsRecorded=activityMonitorInfo.steps-stepsNonActive;

ticker++;

}

vartimerSlot=(ticker%20);//modulo the number of fields(4)*number of seconds toshow the field(5)

if(timerSlot<=4){//first slot?

labelResource=Rez.Strings.TotalSteps;

value=activityMonitorInfo.steps;

}elseif(timerSlot<=9){

labelResource=Rez.Strings.ActiveSteps;

value=stepsRecorded;

}elseif(timerSlot<=14){

labelResource=Rez.Strings.StepsToDo;

value=(activityMonitorInfo.stepGoal-activityMonitorInfo.steps);

if(value<0){

value=0;

}

}elseif(timerSlot<=19){

labelResource=Rez.Strings.GoalPercentage;

value=(activityMonitorInfo.steps*100.0)/activityMonitorInfo.stepGoal;

}else{

value=0;

}

}

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: