Linux locale localization configuration
locale introduction
Reference: http://m.blog.chinaunix.net/uid-20621049-id-3427444.html
locale
Divide various aspects of cultural traditions into 12
major categories. 12
These major categories are:
- Language symbols and their classification (
LC_CTYPE
) - number(
LC_NUMERIC
) - Comparison and sorting conventions (
LC_COLLATE
) - Time display format (
LC_TIME
) - currency unit (
LC_MONETARY
) - Information mainly includes prompt information, error information, status information, titles, labels, buttons and menus, etc. (
LC_MESSAGES
) - Name writing method (
LC_NAME
) - Address writing method (
LC_ADDRESS
) - Phone number writing method (
LC_TELEPHONE
) - Weights and Measures Expression (
LC_MEASUREMENT
) - Default paper size (
LC_PAPER
) - An overview of the information contained within the locale itself (
LC_IDENTIFICATION
).
Therefore, locale
it is the language habits, cultural traditions and living habits of people in a certain region. The locale of a region is defined based on these major categories of habits. These locale definition files are placed under /usr/share/i18n/locales
the directory. For example en_US
, zh_CN
and de_DE
@euro are locale definition files. These files are written in text format. You can use Open the board and take a look at the content inside. Of course, except for the limited comments, you may not understand most of the things because the Unicode
character index method is used.
LC_ALL
Relationship with LANG
priority: LC_ALL
>>LC_*
LANG
注意
: According to the Debian wiki - " 强烈建议不要使用 LC_ALL
, 它会覆盖所有内容
only use it when testing and never set it in a startup file".
Common operations of localectl
# 查看当前系统的本地化设置信息
localectl status
System Locale
: System language and regional settings.VC Keymap
: Keymap settings for the virtual console.X11 Layout
:X11 displays the server's keyboard layout settings.X11 Model
:X11 displays the keyboard model setting of the server.X11 Variant
:X11 displays the server's keyboard variant settings.X11 Options
:X11 displays the server's keyboard option settings.Default Locale
:Default localization settings.
# 查看/etc/locale.conf配置
cat /etc/locale.conf
Locales
# 列出可用的语言环境
localectl list-locales
# 查看可以用的zh语言环境
localectl list-locales|grep zh
# 设置中文语言环境
# 使用localectl永久修改locale的LANG
## 相当于在/etc/locale.conf中添加LANG=zh_CN.uft8
localectl set-locale LANG=zh_CN.uft8
keyboard layout
# 列出可用的键盘布局
localectl list-keymaps
# 列出可用的中文键盘布局
localectl list-keymaps | grep cn
# 设置cn键盘布局
localectl set-keymap cn
FAQ: Error when configuring locale
- Before configuring the locale, you must first install the dependency packages of the locale.
# 安装中文命令行支持--有可能找不到
## glibc-langpack-zh 命令行中文包
## glibc-langpack-en 命令行英文包
yum install -y glibc-common glibc-minimal-langpack glibc-langpack-zh glibc-langpack-en
- Generate language files
# 查看系统当前语言
echo $LANG
# 查看locale库是否存在
ll /usr/lib/locale/locale-archive
# 重新生成中文的locate文件
## 配置哪个语言就生成哪个语言文件
localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
Because LC_ALL
's has the highest priority, configuration LC_ALL
can also solve the problem.
LC_ALL="zh_CN.UTF-8"
Linux system locale (UTF-8) error report
https://blog.csdn.net/omaidb/article/details/120104853