Difference between revisions of "Locale"

From ArchWiki
Jump to navigation Jump to search
m (minor fixes)
m (English UTF-8 example: spaces)
Line 24: Line 24:
First uncomment the following locales in {{Filename|/etc/locale.gen}}:
First uncomment the following locales in {{Filename|/etc/locale.gen}}:
  en_US.UTF-8   UTF-8
  en_US.UTF-8 UTF-8
  en_US ISO-8859-1
  en_US ISO-8859-1
Then update the system as root:
Then update the system as root:

Revision as of 17:49, 16 September 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Locales are used in Linux to define which language the user uses. As the locales define the character sets being used as well, setting up the correct locale is especially important if the language contains non-ASCII characters.

Locale names are defined using the following format:


Enabling necessary locales

Before a locale can be used on the system, it has to be enabled first. To list all available locales, use:

$ locale -a

To enable a locale, uncomment the name of the locale in the file Template:Filename. This file contains all the available locales that can be used on the system. Revert the process to disable a locale. After the necessary locales are enabled, the system needs to be updated with the new locales:

# locale-gen

To display the locales now currently in use, use:

$ locale
Tip: Though it's most likely that just one language is used use on your computer, it can be helpful or even necessary to enable other locales as well. If you're running a multi-user system with users that don't speak en_US, their individual locale should at least be supported by your system.

English UTF-8 example

To setup an English UTF-8 conform system, the locale en_US.UTF-8 needs to be enabled. But for compatibility to programs that don't support UTF-8 yet, it's recommended to enable any other locale prefixed with en_US as well.

First uncomment the following locales in Template:Filename:

en_US.UTF-8 UTF-8
en_US ISO-8859-1

Then update the system as root:

# locale-gen

Setting system-wide locale

To define the system-wide locale used on the system, add the specified locale to the Template:Filename file:


The system wide locale will be updated after rebooting the system.

Setting per user locale

As we mentioned earlier, some users might want to define a different locale than the system-wide locale. To do this, export the variable Template:Codeline with the specified locale in the Template:Filename file. For example, to use the en_AU.UTF-8 locale:

export LANG=en_AU.UTF-8

The locales will be updated next time Template:Filename is sourced. To source it, either re-login or source it manually:

$ . ~/.bashrc

Setting collation

Collation, or sorting, is a little different. Sorting is a goofy beast and different locales do things differently. To get around potential issues, Arch used to set LC_COLLATE="C" in Template:Filename. However, this method is now deprecated. To enable this behavior, simply add the following to Template:Filename:

export LC_COLLATE="C"

Now the ls command will sort dotfiles first, followed by uppercase and lowercase filenames. Note that without a LC_COLLATE setting, locale aware apps sort by LC_ALL or LOCALE, but LC_COLLATE settings will be overridden if LC_ALL is set. To resolve this, add the following to your instead:

export LC_ALL=
export LC_COLLATE="C"

Setting starting weekday

In a lot of countries the first day of the week is Monday. To do change or add the following lines under the LC_TIME section in Template:Filename:

week            7;19971130;5
first_weekday   2
first_workday   2

And then update the system:

# locale-gen
Tip: If you experience some kind of problems with your system and would like to ask for help on the forum, mailing list or otherwise, please include the output from the misbehaving program with export LC_MESSAGES=C before posting. It will set the output messages (errors and warnings) to English, thus enabling more people to understand what the problem might be. This is not relevant if you are posting on a non-English forum.


My terminal doesn't support UTF-8

Unfortunately some terminals don't support UTF-8. In this case, you have to use a different terminal. Here are some terminals that have support for UTF-8:

  • gnome-terminal
  • gnustep-terminal
  • konsole
  • mlterm
  • urxvt (rxvt-unicode)
  • xfce-terminal
  • xterm

Xterm doesn't support UTF-8

xterm only supports UTF-8 if you run it as Template:Codeline or Template:Codeline.

Gnome-terminal doesn't support UTF-8

Append these two lines to the Template:Filename file:


Reboot your system, and gnome-terminal should work correctly.

More resources