Gettext
gettext is the library GNU of internationalization (i18n). It is usually used to write programs mulitilingues.
Process
Programmer
The source code is initially modified to use the calls to function GNU gettext. For the majority of the languages, this is done while inserting the chains intended for the user in the function gettext. To save input time and to clarify the code, alias of substitution _ is usually used for this function so that the code C:
printf (" My name is %s.\n", my_name);
becomes
printf (_ (" My name is %s. \ n"), my_name);
gettext then uses the chain provided as key of search for translations and returns the chain of origin if no translation is available, unlike systems like catgets or of the use of Loadstring under Microsoft Windows, where an identity of programming is used (often an entirety).
In addition to C, function GNU gettext is implemented in: C++, Objectifies C, HS script, bash script, Python, GNU CLISP, Emacs Lisp, librep, GNU Smalltalk, Java, GNU awk, Pascal, wxWidgets (by wxLocale), YCP (YaST2 language), Tcl, Perl, Pike, and R. In the majority of the cases, its use is connected there with that of C.
xgettext is applied to the sources to produce a file .pot, or model, which contains a list of all the translatable chains extracted the code. For the example above, an entry of the file .pot would resemble this:
#: src/name.c: 36 msgid " My name is %s.\n" msgstr " "
Comments for the translators
If the developer wishes to give to the translator an indication for a specific chain, it can do it in the source code using a label (TAG) intended for xgettext, to enable him to filter these indications and to put them in the file .pot. These indications were shown by Kbabel and PoEdit.
printf (_ (" My name is %s. \ n"), my_name); // TRANSLATORS: Please let %s ace it is, because it is exchanged by the program. // Thank you for contributing to this project.
In this example, the label is // and must be provided to xgettext to enable him to extract the comments for the translators during construction from the file .pot. Other characters can be used as labels since they are used in a coherent way in all the code.
xgettext - c=//
With the comments, the file .pot would resemble this:
#. TRANSLATORS: Please let %s ace it is, because it is exchanged by the program. #. Thank you for contributing to this project. #: src/name.c: 36 msgid " My name is %s.\n" msgstr " "
Translator
The translator derives a file .po from the model by using the program msginit then fills out the translations. msginit initializes the translations so that to create a translation in French, for example, it is necessary to carry out:
msginit --locale=fr --input=name.pot
This generates fr.po. An example of entry would be:
#: src/name.c: 36 msgid " My name is %s.\n" msgstr " My name is %s.\n"
The translator must correct them, with the hand or using a tool for translation like PoEdit. This made, the entry would take the following form:
#: src/name.c: 36 msgid " My name is %s.\n" msgstr " I am called %s. \ n"
Finally, the files .po are compiled in binary files .mo with msgfmt. They are then ready to be distributed in the software package.
User
The user, on systems of the Unix type, adjusts the variable of environment LANG and the program then posts the chains in the selected language, if a file .mo is present.
External bonds
-
the official site
- official documentation
| Random links: | Yo-Yo Ma | Treaty of Cusset | Crveni Grad | Line Livron - Aspres | Arirang, Korean traditional song | Salim_Kéchiouche |