Time for action – translating UI texts

The next step is to actually translate the UI text. We will see how to extract the texts from the UI file and translate them.

  1. Go to the po folder using a terminal.
  2. Update the id.po file, which we duplicated from the first part of the action, by typing the following command:
    intltool-update id
  3. From the GNOME Activities menu, launch the Gtranslator program.
  4. During the first launch, we need to fill the profile. Provide a name to the profile and fill your name and e-mail address. The next window will ask you about the language properties that you are going to translate into. Make sure the language code is correct (refer to ISO-639). Enter UTF-8 and 8bit as the character set and transfer the encoding values respectively. Team email is the e-mail address used by the translators of this language. The Plural forms option determines how a word should use its plural form. In the Indonesian language, the number of plurals is two, and a word should use the plural form when the count of the object referred by the word is greater than one. Hence we choose the option nplurals=2; plural=(n>1). For the Indonesian language, it would look like this:
    Time for action – translating UI texts
  5. Click Continue, finish the setup of GTranslator, and go ahead and open the id.po file using its menu.
  6. After this file is opened, we are now ready to translate. Click on each text in the list and enter its translation in the Translated textbox. All formatting marks such as %x, %s, and others must not be modified or changed by translators except when it is requested to do so (for example, when adjusting the date format). The order of the appearance of these formats must not be changed as well.
  7. Translate the text by referring to the following translation table:

    Original text

    Translated text

    This is a label

    Ini adalah label

    Today's date is %x

    Tanggal hari ini adalah %x

    The price is %^=#6n

    Harganya %^=#6n

    The weight is %.3f %s

    Beratnya %.3f %s

    See you later

    Sampai jumpa

  8. Save the file.
  9. Rebuild our application.
  10. In the terminal, create a po folder inside the src folder. Inside the po folder, create an id folder. After that, create the LC_MESSAGES folder inside id. So, altogether we should have a new folder called src/po/id/LC_MESSAGES.
  11. Then rename the id.gmo file, which was produced after the rebuild, to hello-i18n.mo into the folder we created in the previous step. Notice the hello-i18n name must be exactly the same as the value of the GETTEXT_PACKAGE variable, which we set earlier.
  12. Go to the top folder of the project by using the terminal and run the application with the Indonesian language, as shown here:
    LANGUAGE=id LC_ALL=id_ID.utf8 src/hello-i18n
  13. The application window should look like the one shown in the following screenshot. Be amazed!
    Time for action – translating UI texts

This part is where the UI text is generated and translated. The resulting .po files are then taken to the translators' hand and then into the translation queue. This must be done whenever we update any text in the source code. This is exactly done by just entering the following command:

Note that this will only update the id.po file; any remaining files must be updated individually. What this command actually does is it extracts new text from the files stated in the POTFILES file and merges them with the existing id.po file. If there is an ambiguity, the translator would be notified in GTranslator by being shown the text in a fuzzy state. The translator can then fix this issue by providing a new translation for those fuzzy texts.

After all the strings inside the .po files are translated, all translated .po files must be returned back to the po folder. We then perform a build here. Actually, what the build does is it simply issues the following command:

This step converts id.po from a text form to id.gmo in a binary form. The application can only take the binary form, hence we need this step. The bindtextdomain function in the application sets the folder to the src/po/ folder whenever we are in the development mode. Actually, it will look for the binary .gmo files in the src/po/<language-code>/LC_MESSAGES folder. The language code is the code specified in the LANGUAGE environment variable. If this variable is not specified, it will look for the language code in the LANG, LC_MESSAGES, and at last LC_ALL variables consecutively.

The command we execute to run the application is as follows:

This sets the bindtextdomain function to look for the translation in src/po/id/LC_MESSAGES (because the LANGUAGE variable is set to id) and otherwise use id_ID.utf8 as the locale setting. The result is that the UI texts are translated to Indonesian, and the monetary, number, and measurement parameters are also set to Indonesian.

If you have another locale installed to try, here is a good chance. For example, try to set LC_MEASUREMENT to en_US.utf8 (United States), LC_MONETARY to de_DE.utf8 (German), and LC_TIME to ar_SA.utf8 (Saudi Arabia). Would you be able to get an output similar to the one shown in the following screenshot?

Have a go hero – installing another locale