Go to the first, previous, next, last section, table of contents.


Triggering gettext Operations

The initialization of locale data should be done with more or less the same code in every program, as demonstrated below:

int
main (argc, argv)
     int argc;
     char argv;
{
  ...
  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEDIR);
  textdomain (PACKAGE);
  ...
}

PACKAGE and LOCALEDIR should be provided either by `config.h' or by the Makefile. For now consult the gettext sources for more information.

The use of LC_ALL might not be appropriate for you. LC_ALL includes all locale categories and especially LC_CTYPE. This later category is responsible for determining character classes with the isalnum etc. functions from `ctype.h' which could especially for programs, which process some kind of input language, be wrong. For example this would mean that a source code using the @,{c} (c-cedilla character) is runnable in France but not in the U.S.

Some systems also have problems with parsing number using the scanf functions if an other but the LC_ALL locale is used. The standards say that additional formats but the one known in the "C" locale might be recognized. But some systems seem to reject numbers in the "C" locale format. In some situation, it might also be a problem with the notation itself which makes it impossible to recognize whether the number is in the "C" locale or the local format. This can happen if thousands separator characters are used. Some locales define this character accordfing to the national conventions to '.' which is the same character used in the "C" locale to denote the decimal point.

So it is sometimes necessary to replace the LC_ALL line in the code above by a sequence of setlocale lines

{
  ...
  setlocale (LC_TIME, "");
  setlocale (LC_MESSAGES, "");
  ...
}

or to switch for and back to the character class in question. On all POSIX conformant systems the locale categories LC_CTYPE, LC_COLLATE, LC_MONETARY, LC_NUMERIC, and LC_TIME are available. On some modern systems there is also a locale LC_MESSAGES which is called on some old, XPG2 compliant systems LC_RESPONSES.


Go to the first, previous, next, last section, table of contents.