Skip to content

Module translation

PCSG edited this page Sep 3, 2017 · 4 revisions

Module translation

Each module can provide different GUI languages. SteemPi uses gettext to provide all its modules in different languages.

In computing, gettext is an internationalization and localization (i18n) system commonly used for writing multilingual programs on Unix-like computer operating systems. The most commonly used implementation of gettext is GNU gettext,[citation needed] released by the GNU Project in 1995.

Quote of Wikipedia

To translate a module now, you have to create a locale folder in your module folder. The folder structure looks as follows.


/yourModule
  /locale
    /de
      /LC_MESSAGES
        /yourModule.mo
        /yourModule.po 
    /en
      /LC_MESSAGES
        /yourModule.mo
        /yourModule.po

If you want to know more about the folder structure, there are many good tutorials about gettext. Since this is a larger topic and this has been dealt with on the Internet. We can not offer a detailed explanation here.

A very good tutorial can be found here for example: http://www.onlamp.com/pub/a/php/2002/06/13/php.html

Short overview of how to create and use translations

The direct folder under locale determines the language into which you want to write the translation. An LC_MESSAGES folder, which has the actual language files, must be placed under each language folder.

  • .po language file you are creating
  • .mo language file which is compiled

The po file must have the name of your module. For example, if your module is called feed, the language file is called feed.po.

The language file can be created and changed with any conventional editor.

nano module.po

A language file is structured as follows:

msgid "language variable"
msgstr "Translated text"

msgid "language variable"
msgstr "Second translated text"

If you have translated all your language variables, you need to compile the po file to a mo file. This is done with the following command:

msgfmt module.po -o module.mo

That's it already. You can use your variables in PHP in the following way:

<?php

echo dgettext(‘module’, ‘language variable’);

Clone this wiki locally