gettext: Triggering

1 
1 4.2 Triggering ‘gettext’ Operations
1 ===================================
1 
1    The initialization of locale data should be done with more or less
1 the same code in every program, as demonstrated below:
1 
1      int
1      main (int argc, char *argv[])
1      {
1        …
1        setlocale (LC_ALL, "");
1        bindtextdomain (PACKAGE, LOCALEDIR);
1        textdomain (PACKAGE);
1        …
1      }
1 
1    PACKAGE and LOCALEDIR should be provided either by ‘config.h’ or by
1 the Makefile.  For now consult the ‘gettext’ or ‘hello’ sources for more
1 information.
1 
1    The use of ‘LC_ALL’ might not be appropriate for you.  ‘LC_ALL’
1 includes all locale categories and especially ‘LC_CTYPE’.  This latter
1 category is responsible for determining character classes with the
1 ‘isalnum’ etc.  functions from ‘ctype.h’ which could especially for
1 programs, which process some kind of input language, be wrong.  For
1 example this would mean that a source code using the ç (c-cedilla
1 character) is runnable in France but not in the U.S.
1 
1    Some systems also have problems with parsing numbers using the
1 ‘scanf’ functions if an other but the ‘LC_ALL’ locale category is used.
1 The standards say that additional formats but the one known in the ‘"C"’
1 locale might be recognized.  But some systems seem to reject numbers in
1 the ‘"C"’ locale format.  In some situation, it might also be a problem
1 with the notation itself which makes it impossible to recognize whether
1 the number is in the ‘"C"’ locale or the local format.  This can happen
1 if thousands separator characters are used.  Some locales define this
1 character according to the national conventions to ‘'.'’ which is the
1 same character used in the ‘"C"’ locale to denote the decimal point.
1 
1    So it is sometimes necessary to replace the ‘LC_ALL’ line in the code
1 above by a sequence of ‘setlocale’ lines
1 
1      {
1        …
1        setlocale (LC_CTYPE, "");
1        setlocale (LC_MESSAGES, "");
1        …
1      }
1 
1 On all POSIX conformant systems the locale categories ‘LC_CTYPE’,
1 ‘LC_MESSAGES’, ‘LC_COLLATE’, ‘LC_MONETARY’, ‘LC_NUMERIC’, and ‘LC_TIME’
1 are available.  On some systems which are only ISO C compliant,
1 ‘LC_MESSAGES’ is missing, but a substitute for it is defined in GNU
1 gettext’s ‘<libintl.h>’ and in GNU gnulib’s ‘<locale.h>’.
1 
1    Note that changing the ‘LC_CTYPE’ also affects the functions declared
1 in the ‘<ctype.h>’ standard header and some functions declared in the
1 ‘<string.h>’ and ‘<stdlib.h>’ standard headers.  If this is not
1 desirable in your application (for example in a compiler’s parser), you
1 can use a set of substitute functions which hardwire the C locale, such
1 as found in the modules ‘c-ctype’, ‘c-strcase’, ‘c-strcasestr’,
1 ‘c-strtod’, ‘c-strtold’ in the GNU gnulib source distribution.
1 
1    It is also possible to switch the locale forth and back between the
1 environment dependent locale and the C locale, but this approach is
1 normally avoided because a ‘setlocale’ call is expensive, because it is
1 tedious to determine the places where a locale switch is needed in a
1 large program’s source, and because switching a locale is not
1 multithread-safe.
1