The function `gettext` is designed to allow the translation of the entire operating system GNU / Linux. Precisely for this reason it is 100% compatible with a large number of programming languages ​​and scripting languages: C, C + +, C #, Bash, Python, GNU clsip, Emacs Lisp, GNU Smalltalk, Java, GNU awk, Pascal, WxWidgets, YCP , Tcl, PHP, Pike, and others.

First let's see how to use `gettext` within the source code. The implementing rules vary depending on the programming language used for your project, but the syntax is almost always the same, at least for popular programming languages: the function simply contains the message string to be translated. It should be noted that almost always uses the short form, which simply corresponds to an underscore. In this way, the following code in C:

printf(gettext("My name is %s\n"), mio_nome);

becomes:

printf(_("My name is %s\n"), mio_nome);

Later, the command xgettext will filter the code to find the function gettext just inserted, to create the template file. Pot on the basis of the extracted strings from source. An example of a file. Pot for a code containing the above lines is as follows:

#: include/myname.php:36
msgid "My name is %s\n"
msgstr ""

To start the translation is used in the program `` msginit. Moving the file. Little `to` msginit is possible to generate a new file containing the skeleton of the new. Bit in the target language. For example, to translate the file into Italian en_EN.po just run the following command:

locale = en_US-msginit-input = en_EN.po

The program will create the file it_IT.po, whose contents will be similar to the following:

#: include/myname.php:36
msgid "My name is %s\n"
msgstr "My name is %s\n"

At this point, the translator does not have to do is translate the string following the msgstr. The translation can be done with any editor directly from the command line, or using specific programs like poEdit . The result will look like the following:

#: include/myname.php:36
msgid "My name is %s\n"
msgstr "Mi chiamo %s\n"

Once the translation files. Po should be compiled into the binary file. Mo through the `msgfmt`:

msgfmt it_IT.po

Share this content:
  • del.icio.us
  • Google Bookmarks
  • Digg
  • Facebook
  • Technorati
  • MySpace
  • Twitter