https://wiki.archlinux.org/api.php?action=feedcontributions&user=Keeeghom&feedformat=atomArchWiki - User contributions [en]2024-03-29T09:56:45ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Locale&diff=550399Locale2018-10-23T19:25:29Z<p>Keeeghom: mentioned /etc/default/locale as a possible culprit of a problem</p>
<hr />
<div>[[Category:Localization]]<br />
[[ar:Locale]]<br />
[[cs:Locale]]<br />
[[de:Locale]]<br />
[[es:Locale]]<br />
[[fr:Locale]]<br />
[[it:Locale]]<br />
[[ja:ロケール]]<br />
[[ko:Locale]]<br />
[[nl:Locale]]<br />
[[pt:Locale]]<br />
[[ru:Locale]]<br />
[[zh-hans:Locale]]<br />
{{Related articles start}}<br />
{{Related|Environment variables}}<br />
{{Related articles end}}<br />
Locales are used by {{Pkg|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.<br />
<br />
== Generating locales ==<br />
<br />
Locale names are typically of the form {{ic|language[_territory][.codeset][@modifier]}}, where ''language'' is an [[w:List_of_ISO_639-1_codes|ISO 639 language code]], ''territory'' is an [[w:ISO_3166-1#Current_codes|ISO 3166 country code]], and ''codeset'' is a [[w:Character_encoding|character set]] or encoding identifier like [[w:ISO/IEC_8859-1|ISO-8859-1]] or [[w:UTF-8|UTF-8]]. See {{man|3|setlocale}}.<br />
<br />
For a list of enabled locales, run:<br />
<br />
$ locale -a<br />
<br />
Before a locale can be enabled on the system, it must be generated. This can be achieved by uncommenting applicable entries in {{ic|/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]].<br />
<br />
For example, uncomment {{ic|en_US.UTF-8 UTF-8}} for American-English:<br />
<br />
{{hc|/etc/locale.gen|<br />
...<br />
#en_SG ISO-8859-1<br />
en_US.UTF-8 UTF-8<br />
#en_US ISO-8859-1<br />
...<br />
}}<br />
<br />
Save the file, and generate the locale:<br />
<br />
# locale-gen<br />
<br />
{{Note|1=<nowiki></nowiki><br />
* {{ic|locale-gen}} also runs with every update of {{Pkg|glibc}}. [https://projects.archlinux.org/svntogit/packages.git/tree/trunk/glibc.install?h=packages/glibc#n5]<br />
* {{ic|UTF-8}} is recommended over other character sets. [http://utf8everywhere.org/]}}<br />
<br />
== Setting the locale ==<br />
<br />
To display the currently set locale and its related environmental settings, type:<br />
<br />
$ locale<br />
<br />
The locale to be used, chosen among the previously generated ones, is set in {{ic|locale.conf}} files. Each of these files must contain a new-line separated list of [[environment variable]] assignments, having the same format as output by ''locale''.<br />
<br />
To list available locales which have been previously generated, run:<br />
<br />
$ localedef --list-archive<br />
<br />
Alternatively, using {{man|1|localectl}}:<br />
<br />
$ localectl list-locales<br />
<br />
=== Setting the system locale ===<br />
<br />
To set the system locale, write the {{ic|LANG}} variable to {{ic|/etc/locale.conf}}, where {{ic|''en_US.UTF-8''}} belongs to the '''first column''' of an uncommented entry in {{ic|/etc/locale.gen}}:<br />
<br />
{{hc|1=/etc/locale.conf|2=<br />
LANG=''en_US.UTF-8''<br />
}}<br />
<br />
Alternatively, run:<br />
<br />
# localectl set-locale LANG=''en_US.UTF-8''<br />
<br />
See [[#Variables]] and {{man|5|locale.conf}} for details.<br />
<br />
=== Overriding system locale per user session ===<br />
<br />
The system-wide locale can be overridden in each user session by creating or editing {{ic|~/.config/locale.conf}} (or, in general, {{ic|$XDG_CONFIG_HOME/locale.conf}} or {{ic|$HOME/.config/locale.conf}}).<br />
<br />
The precedence of these {{ic|locale.conf}} files is defined in {{ic|/etc/profile.d/locale.sh}}.<br />
<br />
{{Tip|<br />
* This can also allow keeping the logs in {{ic|/var/log}} in English while using the local language in the user environment.<br />
* You can create a {{ic|/etc/skel/.config/locale.conf}} file so that any new users added using ''useradd'' and the {{ic|-m}} option will have {{ic|~/.config/locale.conf}} automatically generated.}}<br />
<br />
=== Make locale changes immediate ===<br />
<br />
Once system and user {{ic|locale.conf}} 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 {{ic|LANG}} and source {{ic|/etc/profile.d/locale.sh}}:<br />
<br />
$ unset LANG<br />
$ source /etc/profile.d/locale.sh<br />
<br />
{{Note|The {{ic|LANG}} variable has to be unset first, otherwise {{ic|locale.sh}} will not update the values from {{ic|locale.conf}}. Only new and changed variables will be updated; variables removed from {{ic|locale.conf}} will still be set in the session.}}<br />
<br />
=== Other uses ===<br />
<br />
Locale variables can also be defined with the standard methods as explained in [[Environment variables]].<br />
<br />
For example, in order to test or debug a particular application during development, it could be launched with something like:<br />
<br />
$ LANG=C ./my_application.sh<br />
<br />
Similarly, to set the locale for all processes run from the current shell (for example, during system installation):<br />
<br />
$ export LANG=C<br />
<br />
== Variables ==<br />
<br />
{{ic|locale.conf}} files support the following environment variables:<br />
<br />
* [[#LANG: default locale|LANG]]<br />
* [[#LANGUAGE: fallback locales|LANGUAGE]]<br />
* {{ic|LC_ADDRESS}}<br />
* [[#LC_COLLATE: collation|LC_COLLATE]]<br />
* {{ic|LC_CTYPE}}<br />
* {{ic|LC_IDENTIFICATION}}<br />
* {{ic|LC_MEASUREMENT}}<br />
* {{ic|LC_MESSAGES}}<br />
* {{ic|LC_MONETARY}}<br />
* {{ic|LC_NAME}}<br />
* {{ic|LC_NUMERIC}}<br />
* {{ic|LC_PAPER}}<br />
* {{ic|LC_TELEPHONE}}<br />
* [[#LC_TIME: date and time format|LC_TIME]]<br />
<br />
Full meaning of the above {{ic|LC_*}} variables can be found on manpage {{man|7|locale}}, whereas details of their definition are described on {{man|5|locale}}.<br />
<br />
=== LANG: default locale ===<br />
<br />
The locale set for this variable will be used for all the {{ic|LC_*}} variables that are not explicitly set.<br />
<br />
=== LANGUAGE: fallback locales ===<br />
<br />
Programs which use {{Pkg|gettext}} for translations respect the {{Ic|LANGUAGE}} option in addition to the usual variables. This allows users to specify a [http://www.gnu.org/software/gettext/manual/gettext.html#The-LANGUAGE-variable 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:<br />
<br />
{{hc|locale.conf|2=<br />
LANG=en_AU.UTF-8<br />
LANGUAGE=en_AU:en_GB:en<br />
}}<br />
<br />
=== LC_TIME: date and time format ===<br />
<br />
If {{ic|LC_TIME}} is set to {{ic|en_US.UTF-8}}, 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:<br />
<br />
{{hc|locale.conf|2=<br />
LC_TIME=en_DK.UTF-8<br />
}}<br />
<br />
{{Note|Programs do not necessarily respect this variable to format the date. For example, {{man|1|date}} uses its own parameters to do so.}}<br />
<br />
=== LC_COLLATE: collation ===<br />
<br />
This variable governs the collation rules used for sorting and regular expressions.<br />
<br />
Setting the value to {{ic|C}} can for example make the ''ls'' command sort dotfiles first, followed by uppercase and lowercase filenames:<br />
<br />
{{hc|locale.conf|2=<br />
LC_COLLATE=C<br />
}}<br />
<br />
See also [http://superuser.com/a/448294/175967].<br />
<br />
To get around potential issues, Arch used to set {{ic|1=LC_COLLATE=C}} in {{ic|/etc/profile}}, but this method is now deprecated.<br />
<br />
=== LC_ALL: troubleshooting ===<br />
<br />
The locale set for this variable will always override {{ic|LANG}} and all the other {{ic|LC_*}} variables, whether they are set or not. <br />
<br />
{{ic|LC_ALL}} is the only {{ic|LC_*}} variable, which '''cannot''' be set in {{ic|locale.conf}} files: it is meant to be used only for testing or troubleshooting purposes, for example in {{ic|/etc/profile}}.<br />
<br />
== Troubleshooting ==<br />
<br />
=== My terminal does not support UTF-8 ===<br />
<br />
The following lists some (not all) terminals that support UTF-8:<br />
<br />
* gnustep-terminal<br />
* konsole<br />
* [[mlterm]]<br />
* [[rxvt-unicode]]<br />
* [[st]]<br />
* [[termite]]<br />
* [[List_of_applications/Utilities#VTE-based|VTE-based terminals]]<br />
* [[xterm]] - Run with the argument {{ic|-u8}} or configure resource {{ic|xterm*utf8: 2}}.<br />
<br />
==== Gnome-terminal or rxvt-unicode ====<br />
<br />
You need to launch these applications from a UTF-8 locale or they will drop UTF-8 support. Enable the {{ic|en_US.UTF-8}} locale (or your local UTF-8 alternative) per the instructions above and set it as the default locale, then reboot.<br />
<br />
=== My system is still using wrong language ===<br />
<br />
It is possible that the environment variables are redefined in other files than {{ic|locale.conf}}, for example {{ic|~/.pam_environment}}. See [[Environment variables#Defining variables]] for details.<br />
<br />
If you're using a desktop environment, such as [[GNOME]], its language settings may be overriding the settings in {{ic|locale.conf}}.<br />
<br />
[[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, [https://bbs.archlinux.org/viewtopic.php?pid=1435219#p1435219 deleting the file at] {{ic|~/.config/plasma-localerc}} (previously: {{ic|~/.config/plasma-locale-settings.sh}}) should resolve the issue.<br />
<br />
It is also possible, that configuration is set from {{ic|/etc/default/locale}}.<br />
<br />
== See also ==<br />
<br />
* [[Gentoo:Localization/Guide]]<br />
* [http://www.gentoo-wiki.info/Locales Gentoo Wiki Archives: Locales]{{Dead link|2018|06|07}}<br />
* [http://demo.icu-project.org/icu-bin/locexp?_=en_US&x=col ICU's interactive collation testing]<br />
* [http://www.openi18n.org/ Free Standards Group Open Internationalisation Initiative]<br />
* [http://pubs.opengroup.org/onlinepubs/007908799/xbd/locale.html ''The Single UNIX Specification'' definition of Locale] by The Open Group<br />
* [https://help.ubuntu.com/community/EnvironmentVariables#Locale_setting_variables Locale environment variables]</div>Keeeghom