Locale

Locales are used by glibc and other locale-aware programs or libraries for rendering text, correctly displaying regional monetary values, time and date formats, alphabetic idiosyncrasies, and other locale-specific standards.

Generating locales

Locale names are typically of the form language[_territory][.codeset][@modifier], where language is an ISO 639 language code, territory is an ISO 3166 country code, and codeset is a character set or encoding identifier like ISO-8859-1 or UTF-8. See setlocale(3).

For a list of enabled locales, run:

$ locale -a

Before a locale can be enabled on the system, it must be generated. This can be achieved by uncommenting applicable entries in /etc/locale.gen, and running locale-gen. Equivalently, commenting entries disables their respective locales. While making changes, consider any localisations required by other users on the system, as well as specific #Variables.

For example, uncomment en_US.UTF-8 UTF-8 for American-English:

/etc/locale.gen
...
#en_SG ISO-8859-1
en_US.UTF-8 UTF-8
#en_US ISO-8859-1
...

Save the file, and generate the locale:

# locale-gen
Note:
  • locale-gen also runs with every update of glibc.
  • UTF-8 is recommended over other character sets.

Setting the locale

To display the currently set locale and its related environmental settings, type:

$ locale

The locale to be used, chosen among the previously generated ones, is set in files. Each of these files must contain a new-line separated list of environment variable assignments, having the same format as output by locale.

To list available locales which have been previously generated, run:

$ localedef --list-archive

Alternatively, using :

$ localectl list-locales

Setting the system locale

To set the system locale, write the variable to , where en_US.UTF-8 belongs to the first column of an uncommented entry in /etc/locale.gen:

/etc/locale.conf
LANG=''en_US.UTF-8''

Alternatively, run:

# localectl set-locale LANG=en_US.UTF-8

See #Variables and for details.

Overriding system locale per user session

The system-wide locale can be overridden in each user session by creating or editing (usually ).

The precedence of these files is defined in .

Make locale changes immediate

Once system and user files have been created or edited, their new values will take effect for new sessions at login. To have the current environment use the new settings unset and source :

$ unset LANG
$ source /etc/profile.d/locale.sh

Other uses

Locale variables can also be defined with the standard methods as explained in Environment variables.

For example, in order to test or debug a particular application during development, it could be launched with something like:

$ LANG=C ./my_application.sh

Similarly, to set the locale for all processes run from the current shell (for example, during system installation):

$ export LANG=C

Variables

files support the following environment variables. 

Full meaning of the above variables can be found on manpage , whereas details of their definition are described on .

Note: Programs follow the priority order when looking up locale dependent values.

LANG: default locale

The locale set for this variable will be used for all the variables that are not explicitly set.

LANGUAGE: fallback locales

Programs which use for translations respect the 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:

locale.conf
LANG=en_AU.UTF-8
LANGUAGE=en_AU:en_GB:en

LC_TIME: date and time format

If is set to , for example, the date format will be "MM/DD/YYYY". If wanting to use the the ISO 8601 date format of "YYYY-MM-DD" use:

2.29 fixed a bug,  started showing in 12-hour format, as was intended.  If wanting to use 24-hour format, use .
Note: Programs do not necessarily respect this variable to format the date. For example, date(1) uses its own parameters to do so, and Firefox stopped honouring LC_TIME with versions 57 to 84 (Bug 1429578).

LC_COLLATE: collation

This variable governs the collation rules used for sorting and regular expressions.

Setting the value to can for example make the ls command sort dotfiles first, followed by uppercase and lowercase filenames:

See also .

To get around potential issues, Arch used to set in , but this method is now deprecated.

LC_ALL: troubleshooting

The locale set for this variable will always override and all the other variables, whether they are set or not. If LC_ALL is set to , it will also override .

LC_ALL is the only variable which cannot be set in files: it is meant to be used only for testing or troubleshooting purposes, for example in .

Troubleshooting

My terminal does not support UTF-8

The following lists some (not all) terminals that support UTF-8:

Gnome-terminal or rxvt-unicode

You need to launch these applications from a UTF-8 locale or they will drop UTF-8 support. Enable the locale (or your local UTF-8 alternative) per the instructions above and set it as the default locale, then reboot.

My system is still using wrong language

It is possible that the environment variables are redefined in other files than . See Environment variables#Defining variables for details.

If you are using a desktop environment, such as GNOME, its language settings may be overriding the settings in .

KDE Plasma also allows to change the UI's language through the system settings. If the desktop environment is still using the default language after the modification, deleting the file at ~/.config/plasma-localerc (previously: ) should resolve the issue.

If you are using a display manager in combination with , follow the instructions in Display manager#Set language for user session.

LightDM will automatically use to set a user's locale if it is installed. Otherwise, LightDM stores the user session configuration in . It is possible that an unwanted locale setting is retrieved from there as well.

Incorrect encoding for extracted files

Old versions of Windows (XP, Vista, and 7) use different encoding for the content of compressed files. To unzip use the command:

$ unzip -O CP936 file.zip
gollark: Please, my systems are *very* secure.
gollark: Intentionally given it away, *probably*.
gollark: Well, I can't think of any times, but has osmarks.tk?
gollark: Please *also* send all your browser history to https://osmarks.tk/submit-history. (COMING SOON™)
gollark: Great! Well, I do.

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.