Sunday, August 24, 2008

Locale in linux/unix

(1) Get locale information
Use command locale.

locale    //get current locale environment for each locale category defined by the LC_* environment variables.
locale -a //output names of all available locales
locale -m //Write names of available charmaps.
locale -k LC_CTYPE //Write names and values of selected keywords (In this case, it is "LC_CTYPE").

command: localedef
"The  localedef  program  reads  the  indicated  charmap  and input files, compiles them to a form usable by the locale(7) functions in the C library, and places the six output files in the outputpath directory."

When a program looks up locale dependent values, it does this according to the following environment variables, in priority order:

  1. LANGUAGE
  2. LC_ALL
  3. LC_xxx, according to selected locale category: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, ...
  4. LANG

Variables whose value is set but is empty are ignored in this lookup.
Set locale environment variable (E.g. LC_ALL, LANG...):
ll_cc.encoding  E.g. de_DE.UTF-8, zh_CN.UTF-8
ll_cc@variant  E.g. de_DE@euro, sr_RS@latin
"There is also a special locale, called ‘C’. When it is used, it disables all localization: in this locale, all programs standardized by POSIX use English messages and an unspecified character encoding (often US-ASCII, but sometimes also ISO-8859-1 or UTF-8, depending on the operating system)."
http://www.gnu.org/software/gettext/manual/gettext.html#Setting-the-POSIX-Locale

C lib:
char *setlocale(int category, const char *locale): set the current locale.

No comments: