Linux how to set locale

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.

Contents

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:

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:

Save the file, and generate the locale:

Setting the locale

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

The locale to be used, chosen among the previously generated ones, is set in 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.

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

Setting the system locale

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

Overriding system locale per user session

The system-wide locale can be overridden in each user session by creating or editing $XDG_CONFIG_HOME/locale.conf (usually

The precedence of these locale.conf files is defined in /etc/profile.d/locale.sh .

/.config/locale.conf automatically generated.

Make locale changes immediate

Once system and user 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 LANG and 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:

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

Variables

locale.conf files support the following environment variables.

Full meaning of the above LC_* variables can be found on manpage locale(7) , whereas details of their definition are described on locale(5) .

LANG: default locale

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

LANGUAGE: 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:

LC_TIME: date and time format

If LC_TIME is set to 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:

Читайте также:  Астра линукс не ставится wine

glibc 2.29 fixed a bug, en_US.UTF-8 started showing in 12-hour format, as was intended. If wanting to use 24-hour format, use LC_TIME=en_GB.UTF-8 .

LC_COLLATE: collation

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

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

To get around potential issues, Arch used to set LC_COLLATE=C in /etc/profile , but this method is now deprecated.

LC_ALL: troubleshooting

The locale set for this variable will always override LANG and all the other LC_* variables, whether they are set or not.

LC_ALL is the only LC_* variable which cannot be set in locale.conf files: it is meant to be used only for testing or troubleshooting purposes, for example in /etc/profile .

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 en_US.UTF-8 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 locale.conf , for example

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

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-locale-settings.sh ) should resolve the issue.

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

LightDM will automatically use accountsservice to set a user’s locale if it is installed. Otherwise, LightDM stores the user session configuration in

/.dmrc . It is possible that an unwanted locale setting is retrieved from there as well.

Источник

Setting Up Locale in Linux

Contents

Introduction

When I logged into a Ubuntu server, the system interface and messages are all shown in Chinese. I want them to be displayed in English. After some searching, I found out that we can change the locale settings.

The definition of locale is:

In computing, a locale is a set of parameters “Parameter”) that defines the user’s language, region and any special variant preferences that the user wants to see in their user interface

Set up locale for normal Linux system

In Linux systems, there are several environment variables related to the locale settings, such as LANG , LC_COLLATE , LC_TIME , LC_ALL etc. A valid locale is like en_US.UTF-8 . You can check this documentation on how locale is formed.

To see your default settings, use the locale command without any option. The output looks like:

These settings are often pre-set by the system root. On CentOS, the system-wide default locale settings are stored in /ect/locale.conf . On Ubuntu, the system locale settings are store in /etc/default/locale .

Among the locale env variables, LC_xxx variables except LC_ALL are ordinary environment variables that can be set individually.

Special variables are LANG , LANGUAGE and LC_ALL . Their priority are listed here:

  1. LANGUAGE
  2. LC_ALL
  3. LC_xxx , according to selected locale category: LC_CTYPE , LC_NUMERIC , LC_TIME , LC_COLLATE , LC_MONETARY , LC_MESSAGES , …
  4. LANG

LANG is a special variable that will set the LC_* variable if it is not set. LC_ALL will set all other LC_XXX variables to the same value. Usually, you do not need to set up LC_ALL in your bash_profile. LANGUAGE is a variable used for message handling, which has a higher priority than LC_ALL , LC_xxx and LANG for messages (see the link [here](https: //www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html#The-LANGUAGE-variable)) . To verify this, suppose that we have the following settings inside .bash_profile :

After sourcing the file, you will find that the messages given for command output will be in Chinese (i.e., LANG is overridden.)

Set up locale for docker container

Ubuntu docker

I try to build a Ubuntu docker image. I want to set my locale to en_US.UTF-8 inside the container by simply adding the following ENV instruction:

When I run the built image, I get the following warning:

bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

The locale command inside container gives the following message:

It seems that the locale file en_US.UTF-8 does not exist inside container. After some searching, I found the correct way to set up locales inside the Ubuntu container. First, we need to install the locales package, which provides the locale-gen command:

Читайте также:  1с бухгалтерия под mac os

After installing the locales packages, a file named local.gen will be created under /etc . According to the documentation of locale-gen :

locale-gen is a program that reads the file /etc/locale.gen and invokes localedef for the chosen localisation profiles. Run locale-gen after you have modified the /etc/locale.gen file.

We should uncomment the line # en_US.UTF-8 UTF-8 in locale.gen and run locale-gen command to generate the needed locale file. After that we can set related settings to en_US.UTF-8 :

We can also directly generate the locale file by appending the locale as the argument to locale-gen :

Putting this all together, we may use the following instructions inside Dockerfile:

CentOS docker

If you tried to build an image based on a CentOS image. You need to use localedef to generate locale files instead of locale-gen :

Other settings are similar to that of Ubuntu.

Источник

Linux: Define Locale and Language Settings

Locales are used in Linux to define which language and character set (encoding) user see in the terminal.

From this article you will learn how to check and change the current locale and language settings from the command line in Linux.

I will show how to check the current locale and language settings and how to get the list of available locals.

You will also see how to set locale and language temporary for the current session only as well as permanently for a single user or for the all users (change default system locale).

Cool Tip: Determine and change a file’s character encoding from the command line in Linux! The best solution for converting text files between different charsets! Read more →

Locale and Language Settings

Execute locale command to get the information about the current locale and language settings:

To list all enabled locales, run:

Locale is defined in the following format:

LANGUAGE ISO 639 language code
TERRITORY ISO 3166 country code
CODESET Character set or encoding identifier, like ISO-8859-1 or UTF-8

e.g. Australian English with UTF-8 encoding is defined as: en_AU.UTF-8

Add New Locale

New locale: Before a locale can be enabled on the system, it must be generated.

If you didn’t find the desired language or encoding in the list of enabled locales, you can search for them in the list of all supported locales and install whatever you need.

Ubuntu-18.04

Supported releases: Ubuntu-15.04, 15.10, 16.04, 16.10, 18.04.

List the all supported (available for generation) locales:

Find the desired locale, for example:

Generate it with:

Now you should see it in the list of available locales:

Ubuntu-14.04

Supported releases: Ubuntu-9.10, 10.04, 10.10, 11.04, 11.10, 12.04, 12.10, 13.04, 13.10, 14.04, 14.10.

List the all supported (available for generation) locales:

Find the desired locale, for example:

Generate it with:

Now you should see it in the list of available locales:

CentOS-7, CentOS-6

List the all supported (available for generation) locales:

Find the desired locale, for example:

Generate it with:

Now you should see it in the list of available locales:

Set Locale for the Current Session

To set the required locale and language for the current session – it is just needed to redefine this variable.

Below you will find the examples of setting locales for some popular languages.

Set the environment variable LANG , as shown in the examples, to change a language and encoding for the current session:

Set the English locale:

Set the Russian locale:

Set the French locale:

Set the German locale:

Set the Hindi locale:

Define Locale and Language Permanently

For this you can set the required value of the LANG variable in a user’s bash profile and the needed locale and language settings will be automatically loaded upon the each session.

Put the following line to the

/.profile files, to change permanently the locale of the current user to en_US.utf8 :

By default, the modification will take effect after logout/login, but you can force it if you run one of the below commands, depending on in which file you have defined the LANG variable:

Set Default System Locale

Cool Tip: Create the awesome ASCII banners from the Linux command line and decorate your SSH warning messages! Read more →

Читайте также:  Eset firewall and windows firewall

Perform the following steps to permanently change the system locale (for the all users).

Ubuntu-18.04

Supported releases: Ubuntu-15.04, 15.10, 16.04, 16.10, 18.04.

Ubuntu-14.04

Supported releases: Ubuntu-9.10, 10.04, 10.10, 11.04, 11.10, 12.04, 12.10, 13.04, 13.10, 14.04, 14.10.

Edit the file with default locale settings:

Set the LANG variable:

CentOS-7

CentOS-6

Edit the file with default locale settings:

Set the LANG variable:

Reboot is required: Note that the above settings will take effect after reboot only.

Источник

How to Set Locales (i18n) On a Linux or Unix

W hat is a “locale” on a Linux operating system? How do I set or get locals (i18n) values on a Linux operating system?

Locales defines language and country specific setting for your programs and shell session. You can use locales to see date, time, number, currency and other values formatted as per your country or language on a Linux or Unix-like system.[donotprint]

Tutorial details
Difficulty level Easy
Root privileges No
Requirements None
Est. reading time 5m

[/donotprint] To set system’s locale you need use shell variable. For example, LANG variable can be used to set en_US (English US) language. This page shows how to set locales (i18n) on a Linux or Unix operating system.

How do I show current locale settings on a Linux or Unix?

The syntax is:
locale
locale name
locale [options] name
The locale command displays information about the current locale, or all locales on the screen.

locales command examples

Simply type the following command:
$ locale

Fig.01 Show current locale on a Linux or Unix

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Display all available locales on your Linux or Unix-like system

Pass the -a option to locale command:
$ locale -a
Sample outputs:

You also run the following command on a Debian or Ubuntu based system to see the list of all supported locales:
$ less /usr/share/i18n/SUPPORTED
Sample outputs:

Locale category sections

The following category sections are defined by POSIX:

  1. LC_CTYPE
  2. LC_COLLATE
  3. LC_MESSAGES
  4. LC_MONETARY
  5. LC_NUMERIC
  6. LC_TIME

View/set global locale for all users on a “ CentOS/RHEL/Scientific Linux v5.x/6.x ” and older

Edit or view /etc/sysconfig/i18n to set global locale for all users:
$ sudo cat /etc/sysconfig/i18n
or
$ sudo vi /etc/sysconfig/i18n
Sample outputs:

You can also edit /etc/profile and set global locale for all users:

View/set global locale for all users on a “ Fedora Linux v22 ” and “ CentOS/RHEL/Scientific Linux 7.x” and above

Type the following command to see the current locale for all users:
$ cat /etc/locale.conf
Sample outputs:

You can use the following systemd command too:
$ localectl status
Sample outputs:

To see all locales available, run:
$ localectl list-locales
To set the default global system locale for all users, type the following command as root:
$ sudo localectl set-locale LANG=localeValueHere
$ sudo localectl set-locale LANG=en_IN.UTF-8

View/set global locale for all users on a Debian or Ubuntu Linux

To see which locales are supported on Debian/Ubuntu, enter:
$ locale -a|more
To set the locales for all users, enter:
$ sudo locale-gen en_IN
$ sudo locale-gen en_IN.UTF-8
Finally run:
$ sudo update-locale
Another option is to run dpkg-reconfigure locales command and select the locale(s) you want to generate. At the end, you’ll be asked which one should be the default. If you have users who access the system through ssh, it is recommended that you choose None as your default locale:
$ sudo dpkg-reconfigure locales

How can I set global locale for one user?

Simply edit your bash shell profile file $HOME/.bash_profile:
$ vi

/.bash_profile
Append/add/edit as follows:

OR create a new .i18n file to user’s $HOME directory:
$ vi $HOME/.i18n
Append/add/edit the following as per your locale setting:

Save and close the file. Please note that

/.bash_profile procedure should work on Linux, OS X, *BSD and many other Unix-like systems. See this page for more info.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

Оцените статью