gettext: Language Implementors

1 
1 15.1 The Language Implementor’s View
1 ====================================
1 
1    All programming and scripting languages that have the notion of
1 strings are eligible to supporting ‘gettext’.  Supporting ‘gettext’
1 means the following:
1 
1   1. You should add to the language a syntax for translatable strings.
1      In principle, a function call of ‘gettext’ would do, but a
1      shorthand syntax helps keeping the legibility of internationalized
1      programs.  For example, in C we use the syntax ‘_("string")’, and
1      in GNU awk we use the shorthand ‘_"string"’.
1 
1   2. You should arrange that evaluation of such a translatable string at
1      runtime calls the ‘gettext’ function, or performs equivalent
1      processing.
1 
1   3. Similarly, you should make the functions ‘ngettext’, ‘dcgettext’,
1      ‘dcngettext’ available from within the language.  These functions
1      are less often used, but are nevertheless necessary for particular
1      purposes: ‘ngettext’ for correct plural handling, and ‘dcgettext’
1      and ‘dcngettext’ for obeying other locale-related environment
1      variables than ‘LC_MESSAGES’, such as ‘LC_TIME’ or ‘LC_MONETARY’.
1      For these latter functions, you need to make the ‘LC_*’ constants,
1      available in the C header ‘<locale.h>’, referenceable from within
1      the language, usually either as enumeration values or as strings.
1 
1   4. You should allow the programmer to designate a message domain,
1      either by making the ‘textdomain’ function available from within
1      the language, or by introducing a magic variable called
1      ‘TEXTDOMAIN’.  Similarly, you should allow the programmer to
1      designate where to search for message catalogs, by providing access
1      to the ‘bindtextdomain’ function.
1 
1   5. You should either perform a ‘setlocale (LC_ALL, "")’ call during
1      the startup of your language runtime, or allow the programmer to do
1      so.  Remember that gettext will act as a no-op if the ‘LC_MESSAGES’
1      and ‘LC_CTYPE’ locale categories are not both set.
1 
1   6. A programmer should have a way to extract translatable strings from
1      a program into a PO file.  The GNU ‘xgettext’ program is being
1      extended to support very different programming languages.  Please
1      contact the GNU ‘gettext’ maintainers to help them doing this.  If
1      the string extractor is best integrated into your language’s
1      parser, GNU ‘xgettext’ can function as a front end to your string
1      extractor.
1 
1   7. The language’s library should have a string formatting facility
1      where the arguments of a format string are denoted by a positional
1      number or a name.  This is needed because for some languages and
1      some messages with more than one substitutable argument, the
1      translation will need to output the substituted arguments in
1      different order.  ⇒c-format Flag.
1 
1   8. If the language has more than one implementation, and not all of
1      the implementations use ‘gettext’, but the programs should be
1      portable across implementations, you should provide a no-i18n
1      emulation, that makes the other implementations accept programs
1      written for yours, without actually translating the strings.
1 
1   9. To help the programmer in the task of marking translatable strings,
11      which is sometimes performed using the Emacs PO mode (⇒
      Marking), you are welcome to contact the GNU ‘gettext’
1      maintainers, so they can add support for your language to
1      ‘po-mode.el’.
1 
1    On the implementation side, three approaches are possible, with
1 different effects on portability and copyright:
1 
1    • You may integrate the GNU ‘gettext’’s ‘intl/’ directory in your
1      package, as described in ⇒Maintainers.  This allows you to
1      have internationalization on all kinds of platforms.  Note that
1      when you then distribute your package, it legally falls under the
1      GNU General Public License, and the GNU project will be glad about
1      your contribution to the Free Software pool.
1 
1    • You may link against GNU ‘gettext’ functions if they are found in
1      the C library.  For example, an autoconf test for ‘gettext()’ and
1      ‘ngettext()’ will detect this situation.  For the moment, this test
1      will succeed on GNU systems and not on other platforms.  No severe
1      copyright restrictions apply.
1 
1    • You may emulate or reimplement the GNU ‘gettext’ functionality.
1      This has the advantage of full portability and no copyright
1      restrictions, but also the drawback that you have to reimplement
1      the GNU ‘gettext’ features (such as the ‘LANGUAGE’ environment
1      variable, the locale aliases database, the automatic charset
1      conversion, and plural handling).
1