Linux locale localization configuration

locale introduction

Reference: http://m.blog.chinaunix.net/uid-20621049-id-3427444.html

localeDivide various aspects of cultural traditions into 12major categories. 12These major categories are:

  1. Language symbols and their classification ( LC_CTYPE)
  2. number( LC_NUMERIC)
  3. Comparison and sorting conventions ( LC_COLLATE)
  4. Time display format ( LC_TIME)
  5. currency unit ( LC_MONETARY)
  6. Information mainly includes prompt information, error information, status information, titles, labels, buttons and menus, etc. ( LC_MESSAGES)
  7. Name writing method ( LC_NAME)
  8. Address writing method ( LC_ADDRESS)
  9. Phone number writing method ( LC_TELEPHONE)
  10. Weights and Measures Expression ( LC_MEASUREMENT)
  11. Default paper size ( LC_PAPER)
  12. An overview of the information contained within the locale itself ( LC_IDENTIFICATION).

Therefore, localeit 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/localesthe directory. For example en_US, zh_CNand 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 Unicodecharacter index method is used.

LC_ALLRelationship with LANGpriority: 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

image.png


Locales

# 列出可用的语言环境
localectl list-locales

# 查看可以用的zh语言环境
localectl list-locales|grep zh

image.png

# 设置中文语言环境
# 使用localectl永久修改locale的LANG
## 相当于在/etc/locale.conf中添加LANG=zh_CN.uft8
localectl set-locale LANG=zh_CN.uft8

Insert image description here


keyboard layout

# 列出可用的键盘布局
localectl list-keymaps

# 列出可用的中文键盘布局
localectl list-keymaps | grep cn

image.png

# 设置cn键盘布局
localectl set-keymap cn

FAQ: Error when configuring locale

  1. 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
  1. Generate language files
# 查看系统当前语言
echo $LANG

# 查看locale库是否存在
ll /usr/lib/locale/locale-archive

# 重新生成中文的locate文件
## 配置哪个语言就生成哪个语言文件
localedef -c -f UTF-8 -i zh_CN zh_CN.utf8

Insert image description here
Because LC_ALL's has the highest priority, configuration LC_ALLcan 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


Minimize the automatic installation of Centos7 and modify the complete Chinese display

https://blog.csdn.net/omaidb/article/details/120389937

Guess you like

Origin blog.csdn.net/omaidb/article/details/131728293