edit · print · PDF

Please note that all the SIEpedia's articles address specific issues or questions raised by IAC users, so they do not attempt to be rigorous or exhaustive, and may or may not be useful or applicable in different or more general contexts.


What is a "locale"?

  • "locale" is a subset of the user's environment that defines the user's language, country and any special variant preferences that the user wants to see in their user interface.
  • For instance, LC_TIME is a "locale" variable that defines how date and time are formatted, while LC_NUMERIC may be used to change the decimal separator (for instance point or coma).
  • Usually a locale identifier consists of at least a language identifier and a region identifier, plus, optionally, a codeset. For instance, the value es_MX.utf8 refers to the spanish language as spoken in Mexico, and using the UTF-8 character encoding; the value en_US.iso88591 is english as spoken in the United States, with the ISO-88591 encoding.

Locale variables

There are several locale variables, though some of them have a meaning we haven't figured out yet. :-(

  • LC_CTYPE Character classification and case conversion. Also indicates the language which should be used with XIM.
  • LC_NUMERIC Non-monetary numeric formats.
  • LC_TIME Date and time formats.
  • LC_COLLATE Collation order used for comparing and sorting.
  • LC_MONETARY Monetary formats.
  • LC_MESSAGES Formats of informative and diagnostic messages and interactive responses (also for graphical user interfaces).
  • LC_PAPER Paper format.

(We don't know what exactly the last 5 variables are for ...)

Special variables.

There are two variables that affect all of the above one, and it is important to understand the difference between them.

  • LANG: Its value is used to set the value of all LC_* variables which are not explicitely set (those already set are not changed). Also, any LC_* variable can be modified after setting LANG.
  • LC_ALL: Its value will override all the LC_* variable (but not LANG). After setting LC_ALL, modifications to any LC_* variables are not permitted.
  • In general, it is then recommended to leave LC_ALL unset, set instead LANG, and change individual LC_* variables to suit your needs.

How to check and modify the value of locale variables

  • The simplest way is to type locale in your shell.
  • Those variables whose values are within quotation marks are those which are not set explicitely, and inherit their values from LANG or LC_ALL. Those values without quotation marks have been set explicitely.
  • To set or modify a locale variable, use the setenv command, for instance:
    setenv LANG es_ES
  • A list of all available locales can be obtained by typing:
    locale -a
  • To change permanently your locale to (american) english, you may place in your .cshrc file the instructions:
    setenv LANG en_US
    setenv LC_ALL en_US

Why locale is important

  • The locale helps you to communicate with your operating system in the language and charset encoding you need or prefer. For instance, here at the IAC LANG is set as es_ES, so that, for instance, shell error messages are in spanish.
  • However, some programs may behave strangely, or not as you expect them to do, with some locales. A striking example is awk, which, under LC_NUMERIC=es_ES, assumes that the decimal separator is a coma, and then produces odd output when working on tabular data with a dot as decimal separator. Try this example:
# create a file with some numerical columns
echo "1027.54  999.367  28.345" > awktest.input
echo "49.54  1992.367  280.345345" >> awktest.input
unsetenv LC_ALL  # to make sure we can change other locale variables
setenv LC_NUMERIC en_US  
awk '{printf("%10.3f %10.3f \n",$2,$1)}' awktest.input
# change LC_NUMERIC to spanish locale
setenv LC_NUMERIC es_ES
awk '{printf("%10.3f %10.3f \n",$2,$1)}' awktest.input
# See what happens?
  • Other programs that we remember had problems with some locale settings were an older version of Acrobat Reader, and the Intel Fortran 90 Compiler.
  • Sometime, error messages such as "Warning: locale not supported by Xlib, locale set to C" may hint to some incompatibility between a program and the locale settings.
  • Another potential problem with the locale is described in the STSCI_PYTHON v2.5 installation instructions, where they write:
    "Problems runnning graphics tasks in Pyraf were reported on some operating systems (for example Ubuntu and Suse). The error message is TclError: expected floating point number but got "1.0". Although we do not understand the reasons for this we know it is caused by a default non-english locale on the system. One possible solution is to start pyraf by running: env LC_ALL=C pyraf"

If you wish to know more, please read http://users.suse.com/~mfabian/suse-cjk/locales.html

Section: Tutorials and Manuals

edit · print · PDF
Page last modified on October 02, 2012, at 12:54 PM