| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
15.1 The Language Implementor’s View
All programming and scripting languages that have the notion of strings
are eligible to supporting gettext. Supporting gettext
means the following:
-
You should add to the language a syntax for translatable strings. In
principle, a function call of
gettextwould do, but a shorthand syntax helps keeping the legibility of internationalized programs. For example, in C we use the syntax_("string"), and in GNU awk we use the shorthand_"string". -
You should arrange that evaluation of such a translatable string at
runtime calls the
gettextfunction, or performs equivalent processing. -
Similarly, you should make the functions
ngettext,dcgettext,dcngettextavailable from within the language. These functions are less often used, but are nevertheless necessary for particular purposes:ngettextfor correct plural handling, anddcgettextanddcngettextfor obeying other locale-related environment variables thanLC_MESSAGES, such asLC_TIMEorLC_MONETARY. For these latter functions, you need to make theLC_*constants, available in the C header<locale.h>, referenceable from within the language, usually either as enumeration values or as strings. -
You should allow the programmer to designate a message domain, either by
making the
textdomainfunction available from within the language, or by introducing a magic variable calledTEXTDOMAIN. Similarly, you should allow the programmer to designate where to search for message catalogs, by providing access to thebindtextdomainfunction. -
You should either perform a
setlocale (LC_ALL, "")call during the startup of your language runtime, or allow the programmer to do so. Remember that gettext will act as a no-op if theLC_MESSAGESandLC_CTYPElocale categories are not both set. -
A programmer should have a way to extract translatable strings from a
program into a PO file. The GNU
xgettextprogram is being extended to support very different programming languages. Please contact the GNUgettextmaintainers to help them doing this. If the string extractor is best integrated into your language’s parser, GNUxgettextcan function as a front end to your string extractor. - The language’s library should have a string formatting facility where the arguments of a format string are denoted by a positional number or a name. This is needed because for some languages and some messages with more than one substitutable argument, the translation will need to output the substituted arguments in different order. See section Special Comments preceding Keywords.
-
If the language has more than one implementation, and not all of the
implementations use
gettext, but the programs should be portable across implementations, you should provide a no-i18n emulation, that makes the other implementations accept programs written for yours, without actually translating the strings. -
To help the programmer in the task of marking translatable strings,
which is sometimes performed using the Emacs PO mode (see section Marking Translatable Strings),
you are welcome to
contact the GNU
gettextmaintainers, so they can add support for your language to ‘po-mode.el’.
On the implementation side, three approaches are possible, with different effects on portability and copyright:
-
You may integrate the GNU
gettext’s ‘intl/’ directory in your package, as described in The Maintainer’s View. This allows you to have internationalization on all kinds of platforms. Note that when you then distribute your package, it legally falls under the GNU General Public License, and the GNU project will be glad about your contribution to the Free Software pool. -
You may link against GNU
gettextfunctions if they are found in the C library. For example, an autoconf test forgettext()andngettext()will detect this situation. For the moment, this test will succeed on GNU systems and not on other platforms. No severe copyright restrictions apply. -
You may emulate or reimplement the GNU
gettextfunctionality. This has the advantage of full portability and no copyright restrictions, but also the drawback that you have to reimplement the GNUgettextfeatures (such as theLANGUAGEenvironment variable, the locale aliases database, the automatic charset conversion, and plural handling).
| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on August 27, 2013 using texi2html 5.0.
