Linux locale set language

How to Change or Set System Locales in Linux

A locale is a set of environmental variables that defines the language, country, and character encoding settings (or any other special variant preferences) for your applications and shell session on a Linux system. These environmental variables are used by system libraries and locale-aware applications on the system.

Locale affects things such as the time/date format, the first day of the week, numbers, currency and many other values formatted in accordance with the language or region/country you set on a Linux system.

In this article, we will show how to view your currently installed system locale and how to set system’s locale in Linux.

How to View System Locale in Linux

To view information about the current installed locale, use the locale or localectl utility.

You can view more information about an environmental variable, for example LC_TIME, which stores the time and date format.

To display a list of all available locales use the following command.

How to Set System Locale in Linux

If you want to change or set system local, use the update-locale program. The LANG variable allows you to set the locale for the entire system.

The following command sets LANG to en_IN.UTF-8 and removes definitions for LANGUAGE.

To configure a specific locale parameter, edit the appropriate variable. For instance.

You can find global locale settings in the following files:

  • /etc/default/locale – on Ubuntu/Debian
  • /etc/locale.conf – on CentOS/RHEL

These files can also be edited manually using any of your favorite command line editors such as Vim or Nano, to configure your system locale.

To set a global locale for single user, you can simply open

/.bash_profile file and add the following lines.

For more information, see the locale, update-locale and localectl man pages.

That’s all! In this short article, we have explained how to view and set system local in Linux. If you have any questions, use the feedback form below to reach us.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

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) .

Читайте также:  Mf3310 драйвер windows 10 x64

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:

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.

Читайте также:  Open source windows software download

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.

Источник

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.

Читайте также:  Apache linux установка настройка

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 →

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.

Источник

Локализация Ubuntu Server 18.04 LTS

Локаль (locale или локализация) в Linux определяет, какой язык и какой набор символов (кодировку), пользователь видит в терминале. Посмотрим, как проверить текущие настройки языка и кодировки, как получить список всех доступных локалей, как сменить язык и кодировку для текущей сессии или установить их постоянно.

Для тех, кому лень читать всю статью до конца — чаще всего для локализации консоли достаточно повторно сконфигурировать пакет locales :

Сначала будут созданы нужные локали (их выбрать на первом экране), потом установлена локаль по умолчанию (ее выбрать на втором экране).

Текущие настройки языка

Посмотрим информацию о текущем языковом окружении:

Список доступных локалей

Теперь посмотрим список всех установленных языков и кодировок:

Есть только системная локаль C.UTF-8 , которая присутствует всегда. А нам надо добавить еще две локали — en_US.UTF-8 и ru_RU.UTF-8 .

Добавить новую локаль

Смотрим список всех поддерживаемых (доступных для установки) локалей:

Устанавливаем нужные локали — en_US.UTF-8 и ru_RU.UTF-8 :

Второй способ установить локали — расскомментровать нужные строки в файле /etc/locale.gen

И просто выполнить команду locale-gen без указания локалей:

Подробная информация о локалях

Более подробную информацию об установленных в системе локалях можно посмотреть так:

Часть локалей размещена в архиве /usr/lib/locale/locale-archive , а часть — в директориях внутри /usr/lib/locale/ .

Локаль по-умолчанию

Хорошо, нужные локали у нас теперь есть, осталось только задать локаль по умолчанию:

Эта команда запишет в файл /etc/default/locale строку:

После этого надо будет перезайти в систему. И проверяем информацию о языковом окружении:

Теперь все правильно, так что запишем эту информацию в файл /etc/default/locale :

Быстрая локализация

До сих пор мы все делали ручками, но если лень — можно просто повторно сконфигурировать пакет locales . Сначала будут созданы нужные локали (их нужно выбрать на первом экране), потом установлена локаль по умолчанию (ее нужно выбрать на втором экране).

Удалить лишние локали

После установки (генерации) локали, она помещается в архив /usr/lib/locale/locale-archive . Файл архива — это файл, отображаемый в память, который содержит все локали системы; он используется всеми локализованными программами. Посмотреть список локалей в архиве можно с помощью команды:

Удалить заданную локаль из файла архива:

Обратите внимание на название локали — ru_UA.utf8 , а не ru_UA.UTF-8 . Если неправильно указать локаль — она не будет удалена из архива:

В случае, если утилита locale-gen была вызвана с опцией —no-archive , надо удалить соответствующую директорию в /usr/lib/locale :

Переводы для системных программ

Локализация для основных системных программ, чтобы получать сообщения на русском языке:

Локализация для текущей сессии

Достаточно временно установить переменную окружения LANG в текущей сессии терминала:

Или даже так — передать переменную LANG конкретной программе:

Файлы конфигурации шрифта и клавиатуры

Настройки можно найти в файлах конфигурации /etc/default/console-setup и /etc/default/keyboard :

Это системные настройки, пользователь может создать свои в файлах

Настройка шрифта и клавиатуры

Чтобы сформировать файлы конфигурации /etc/default/console-setup и /etc/default/keyboard можно использовать команды:

После того, как файлы конфигурации будут сформированы, нужно выполнить команду setupcon без аргументов или перезагрузить систему.

Источник

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