gettext
The facilities in GNU gettext focus on messages; strings printed
by a program, either directly or via formatting with printf or
sprintf.1
When using GNU gettext, each application has its own
text domain. This is a unique name, such as `kpilot' or `gawk',
that identifies the application.
A complete application may have multiple components—programs written
in C or C++, as well as scripts written in sh or awk.
All of the components use the same text domain.
To make the discussion concrete, assume we're writing an application named guide. Internationalization consists of the following steps, in this order:
"`-F': option required" is a good candidate for translation.
A table with strings of option names is not (e.g., gawk's
--profile option should remain the same, no matter what the local
language).
"guide") to the gettext library,
by calling the textdomain function.
gettext
to use .mo files in a different directory than the standard
one by using the bindtextdomain function.
gettext. The returned string is the translated string
if available, or the original string if not.
In C (or C++), the string marking and dynamic translation lookup
are accomplished by wrapping each string in a call to gettext:
printf(gettext("Don't Panic!\n"));
The tools that extract messages from source code pull out all
strings enclosed in calls to gettext.
The GNU gettext developers, recognizing that typing
`gettext' over and over again is both painful and ugly to look
at, use the macro `_' (an underscore) to make things easier:
/* In the standard header file: */
#define _(str) gettext(str)
/* In the program text: */
printf(_("Don't Panic!\n"));
This reduces the typing overhead to just three extra characters per string
and is considerably easier to read as well.
There are locale categories
for different types of locale-related information.
The defined locale categories that gettext knows about are:
LC_MESSAGESgettext
operations, but it is possible to supply a different one explicitly,
if necessary. (It is almost never necessary to supply a different category.)
LC_COLLATELC_CTYPE/[[:alnum:]]/
(see Regexp Operators).
LC_MONETARYLC_NUMERICLC_RESPONSELC_TIMELC_ALLgettext.)
[1] For some operating systems, the gawk
port doesn't support GNU gettext. This applies most notably to
the PC operating systems. As such, these features are not available
if you are using one of those operating systems. Sorry.
[2] Americans
use a comma every three decimal places and a period for the decimal
point, while many Europeans do exactly the opposite:
1,234.56 versus 1.234,56.