Tuesday, February 26, 2013

Localizing "RekenMaar"

One of the first, very basic dot42 apps is called "RekenMaar" (which is Dutch for 'let's do some math'). This app (written by my wife) lets children practice math. It is available on Google Play in both Dutch and English.

This articles quickly runs through the modification we made to the original Dutch version to make it localizable.

Localization

Originally, some strings were placed in a string resource file. Others were used literally in both code and layout resources. For example the layout for the settings contained a snippet like this:

<TextView
    android:id="@+id/OptionMultiplication"
    style="@style/ViewStyle_WrapBoth"
    android:text="Instellingen vermenigvuldigen
          en delen"
    android:layout_centerHorizontal="true"
    android:layout_margin="10dp" />

The android:text attribute contains a Dutch literal string. We changed it as follows:

<TextView
    android:id="@+id/OptionMultiplication"
    style="@style/ViewStyle_WrapBoth"
    android:text="@string/settings_div_mul_title"
    android:layout_centerHorizontal="true"
    android:layout_margin="10dp" />

The "@string/settings_div_mul_title" value is a resource identifier that refers to the following entry in the string resource file:

<string name="settings_div_mul_title">
    Instellingen vermenigvuldigen en delen</string>

Similar changes were made in code. For example the result checker contained this line:

tvResult.SetText("Goed");

This line was changed to:

tvResult.SetText(
    GetString(R.Strings.answer_correct));

with an entry in a string resource file:

<string name="answer_correct">Goed</string>

The final step in the localization process was to add a copy of the original Strings1.xml resource file and rename it to Strings1-en.xml. Obviously, this resource file holds the English translation. All nicely in one place.

By the way, if we would have renamed the Dutch resource file to Strings1-nl.xml and keep the English resource file as String1.xml, then English would have been the default.

1 comment:

  1. Do you really have to call the file "Strings1.xml" ? What's the 1 indicate?

    ReplyDelete