Configure Locales in Ubuntu

From Thomas-Krenn-Wiki
Jump to: navigation, search

This article will describe how locales (language settings) can be configured for Ubuntu from the command line. There is a similar article for Debian: Perl warning Setting locale failed in Debian. The following information has been tested under Ubuntu 11.10.

Displaying the Current Settings

$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Displaying the Available Locales

$ locale -a
C
C.UTF-8
de_AT.utf8
de_BE.utf8
de_CH.utf8
de_DE.utf8
de_LI.utf8
de_LU.utf8
en_AG
en_AG.utf8
...
POSIX

If a locale does not appear in the list, it will have to be additionally installed.

# locale-gen fr_FR.UTF-8
Generating locales...
  fr_FR.UTF-8... done
Generation complete.

The following file contains a list of all available locales: /usr/share/i18n/SUPPORTED

Adjusting Locales

The default settings are stored in the /etc/default/locale file.

$ cat /etc/default/locale 
LANG=en_US.UTF-8

This file can either be adjusted manually or updated using the tool, update-locale.

# update-locale LANG=de_DE.UTF-8

You will find a list of all LC_* environment variables at [1].

This becomes useful for example, when a system should be operated in German, however the error and system messages should be displayed in English. This is often helpful, when searching for errors. In this case, the following settings can be made to /etc/default/locale:

LANG=de_DE.UTF-8
LC_MESSAGES=POSIX

The LC_MESSAGES variable also influences the language of the user interface or the window manager.[2] Date and number specifications are not affected by a change from LC_MESSAGES.

No locale set

It may occur that no locales are set on systems.

This can be recognized by the fact that /etc/default/locale does not exist.

Furthermore, the locale -a command returns following:

 locale -a
 C
 C.UTF-8
 POSIX

In this case, proceed as follows:

  1. Generate locale
    • sudo locale-gen de_DE.UTF-8
  2. Set locale, this generates also the /etc/default/locale file.
    • update-locale LANG=de_DE.UTF-8
  3. Then restart the system or open a new terminal.

References

  1. Ubuntu Community Documentation: Locale (help.ubuntu.com)
  2. Region & Language (wiki.gnome.org)

Related articles

Activate Hibernate in Ubuntu 12.04
Manual Installation of Oracle Java JRE 6 or SE 7 in Ubuntu
Thomas-Krenn Ubuntu Repository