GNU gettext

from Wikipedia, the free encyclopedia
GNU gettext

Official gnu.svg
Basic data

Maintainer Daiki Ueno
developer GNU gettext team
Current  version 0.21
( July 27, 2020 )
operating system Unix-like operating systems, Windows (see web links)
programming language C.
category Localization
License GPL : application and libgettextpo library, LGPL : libintl and libasprintf library
German speaking No
GNU gettext homepage

Gettext GNU is a GNU - program library for internationalization of software. Usually it is used to develop multilingual programs.

workflow

programmer

workflow

First, the source code is modified so that it calls the GNU gettext functions. In most programming languages ​​this is achieved by wrapping the strings gettextthat are to be output by. For the sake of clarity, this function can also be _addressed under the name , so that the following code example (in  C ) of

printf("Mein Name ist %s.\n", mein_name);

in

 printf(_("Mein Name ist %s.\n"), mein_name);

would have to be changed. This is synonymous with

 printf(gettext("Mein Name ist %s.\n"), mein_name);

In addition to C, GNU gettext is now also available in C ++ , Objective-C , sh script, Bash script, Python , Ruby , GNU CLISP , Emacs Lisp , librep, GNU Smalltalk , Java , GNU awk , Pascal , Delphi , Gambas , wxWidgets (with Help of the wxLocale class), YCP (the YaST2 language), Tcl , Perl , PHP and Pike available. The use of gettextin these systems is usually very similar to that of C.

With xgettext, the source files are analyzed in order to generate a .pot file ( Portable Object Template ) that contains a list of all translatable texts (strings). For the example above, the entry in the .pot file would look something like this:

#: src/name.c:36
msgid "Mein Name ist %s.\n"
msgstr ""

translator

The translator creates a .po file ( Portable Object ) from the template with the program msginitand then creates the translations. msginitinitializes the translation, so if you want to create an English translation you would have to msginitcall it as follows:

msginit --locale=en --input=name.pot

This call would create the en.po file; an entry in this file would e.g. B. look like this:

#: src/name.c:36
msgid "Mein Name ist %s.\n"
msgstr "Mein Name ist %s.\n"

The translator would then have to replace the corresponding texts either manually or with a tool such as poEdit or Lokalize (formerly KBabel ). After the work is done, the example entry would look like this:

#: src/name.c:36
msgid "Mein Name ist %s.\n"
msgstr "My name is %s.\n"

Finally, the .po files are also translated msgfmtinto binary .mo ( Machine Object ) or .gmo files ( GNU Machine Object ). These can now be delivered with the software package. So that the library can find the file, it is now copied into a predefined directory (e.g. in C using the function ). The object named name.mo ( name is the domain , e.g. the name of the program package, given as the first argument of ). The message object is then in . bindtextdomain(name,"/usr/share/locale")bindtextdomain()/usr/share/locale/<Sprachkürzel>/LC_MESSAGES/name.mo

It is often advisable for German programmers to write the original texts in English, otherwise a translator would have to master both German and the target language. An alternative strategy is to use short terms instead of whole sentences (e.g. "form_submit"), which has the advantage that these generic "snippets" can be used in several places in the code, but only once in the localization file need to be translated. In order to achieve the same effect with whole sentences, these characters would have to be identical, which is quite error-prone. On the other hand, this preservation of the context avoids linguistic ambiguities that can occur especially with short sentences or even single words. For example, if you want to use the English word “order” on the one hand for the sorting order and on the other hand as “order”, you would have difficulties with a one-to-one translation, whereas when using context-sensitive terms you would need an “order_by” and a “submit_order” “Could use.

user

The user on a Unix (or Unix-like) system defines the locale using the environment variables LC_ALL , LC_MESSAGESor LANGand LANGUAGE.

In Windows, the language that is set under "Region" is automatically used.

The program outputs the texts in the corresponding language, provided there is a .mo file for it. If no suitable .mo file is available, the program uses the language in which it was originally written, usually English.

See also

Web links

Wikibooks: Computer-based translation  - learning and teaching materials

Individual evidence

  1. Bruno Haible: GNU gettext 0.21 released . July 27, 2020 (accessed July 27, 2020).