Gettext

GNU gettext is the GNU internationalization library. Normally it is used for the development of multilingual programs.

Work routine

Programmer

First, the source code is modified so that it calls the GNU gettext functions. This will in most programming languages ​​achieved by wrapping the string to be output by gettext. For clarity, this function is also under the name _ approachable, so that the following code example (in C) of

Printf (" My name is% s \ n", my_name ); in

Printf ( _ (" My name is% s \ n"), my_name ); would have to be changed. This is equivalent to

Printf ( gettext ( "My name is% s \ n"), my_name ); GNU gettext except in C now also in C , Objective -C, sh script, bash script, Python, Ruby, GNU CLISP, Emacs Lisp, librep, GNU Smalltalk, Java, GNU awk, Pascal, Delphi, prawns, wxWidgets ( with Help the wxLocale class), YCP ( YaST2 language ), Tcl, Perl, PHP and Pike available. The use of gettext in these systems is very similar to C. usually

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

#: Src / name.c: 36   msgid "My name is% s \ n"   msgid "" translator

The translator creates a. Po file (Portable Object) from the template with the msginit program and then creates the translations. msginit initializes the translation, so if you want to create an English translation, you would have msginit call as follows:

Msginit - locale = en - input = name.pot This call would create the en.po file, an entry in this file would look like this:

#: Src / name.c: 36   msgid "My name is% s \ n"   msgid "My name is% s \ n" The translator would then have (formerly KBabel ) replace the corresponding texts either manually or with a tool such as PoEdit or Lokalize. After work, the sample entry would look like:

#: Src / name.c: 36   msgid "My name is% s \ n"   msgid " My name is % s \ n" Finally, the. Po files are translated with msgfmt in binary. Mo files (Message Object). These can now be delivered with the software package. Thus, the library finds the file, it is now in a (eg in C using the function bindtextdomain (name, " / usr / share / locale " ) ) predefined directory copied. The object named name.mo (name is the domain name, eg the name of the software package, the first argument of bindtextdomain ()). The message object is then in / usr / share / locale /

It often is also recommended for German programmer to write the original texts in English, would otherwise have a translator German as well as the target language proficient. An alternative strategy is to use full sentences instead of short terms (eg, " form_submit " ), which on the one hand has the advantage that these generic " snippets " can be used in several places in the code, but in the localization file only once must be translated. To achieve the same effect with complete sentences, these signs for signs must be identical, which is quite error prone. On the other hand can avoid linguistic ambiguities that can occur, especially with short sentences or even single words through this preservation of context. If you want to, for example, the English word "Order" on the one hand for the sort order and the other as "order" use, you would have one-to-one translation difficulties, whereas you submit_order at a when using context-sensitive terms even a " order_by " and even a " " could use.

User

The user on a Unix (or Unix-like ) system defines the locale using the environment variables LC_ALL, LC_MESSAGES and LANG.

On Windows, the language is automatically used, which is set in the region.

The program gives the texts in the corresponding language, if one exists for them. Mo file. If no matching. Mo file exists, the program uses the language in which it is originally written, usually English.

18645
de