Locales are used in GNU/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:
- 1 Enabling necessary locales
- 2 Setting system-wide locale
- 3 Setting fallback locales
- 4 Setting per user locale
- 5 Setting collation
- 6 Setting the first day of the week
- 7 Troubleshooting
- 8 See also
1 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 /etc/locale.gen. 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:
To display the locales now currently in use, use:
1.1 US English example
First uncomment the following locales in /etc/locale.gen:
Then update the system as root:
2 Setting system-wide locale
To define the system-wide locale used on the system, set LANG in locale.conf:
An advanced example configuration would be:
# Enable UTF-8 with Australian settings. LANG="en_AU.UTF-8" # Keep the default sort order (e.g. files starting with a '.' # should appear at the start of a directory listing.) LC_COLLATE="C" # Set the short date to YYYY-MM-DD (test with "date +%c") LC_TIME="en_DK.UTF-8"
To use them, the locales need to be specified in locale.gen and generated using the locale-gen command:
en_AU.UTF-8 UTF-8 en_DK.UTF-8 UTF-8 en_US.UTF-8 UTF-8
They will take effect after rebooting the system and will be set for individual sessions at login.
3 Setting fallback locales
Programs which use gettext for translations respect the LANGUAGE option in addition to the usual variables. This allows users to specify a list of locales that will be used in that order. If a translation for the preferred locale is unavailable, another from a similar locale will be used instead of the default. For example, an Australian user might want to fall back to British rather than US spelling:
LANG="en_AU.UTF-8" export LANGUAGE="en_AU:en_GB:en"
4 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 LANG with the specified locale in the ~/.bashrc file. For example, to use the en_AU.UTF-8 locale:
The locales will be updated next time ~/.bashrc is sourced. To update, either re-login or source it manually:
$ source ~/.bashrc
5 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, Parabola used to set LC_COLLATE="C" in /etc/profile. However, this method is now deprecated. To enable this behavior, simply add the following to /etc/locale.conf:
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 LANG, but LC_COLLATE settings will be overridden if LC_ALL is set. If this is a problem, ensure that LC_ALL is not set by adding the following to /etc/profile instead:
Note that LC_ALL is the only LC variable which cannot be set in /etc/locale.conf.
6 Setting the first day of the week
In many countries the first day of the week is Monday. To adjust this, change or add the following lines in the LC_TIME section in /usr/share/i18n/locales/<your_locale>:
week 7;19971130;5 first_weekday 2 first_workday 2
And then update the system:
7.1 My terminal doesn't support UTF-8
Unfortunately some terminals do not support UTF-8. In this case, you have to use a different terminal. Here are some terminals that have support for UTF-8:
- vte-based terminals
7.1.1 Xterm doesn't support UTF-8
xterm only supports UTF-8 if you run it as uxterm or xterm -u8.
7.1.2 GNOME Terminal or rxvt-unicode doesn't support UTF-8
You need to launch these applications from a UTF-8 locale or they will drop UTF-8 support. Enable the en_US.UTF-8 locale (or your local UTF-8 alternative) per the instructions above and set it as the default locale, then reboot.