CentOS7 Chinese language garbled problem solving

1. Install Chinese language pack  

First check whether the system has Chinese language pack installed  

# locale -a (list the names of all available common locales)

If the above items are found, it means that the Chinese language pack has been installed in the system and there is no need to install it again. What do these items mean?

{language code}_{country code}.{character set}

zh is the code name of Chinese, CN is the code name of China, gb18030, gb2312, utf8 is the language character set

Then each item can be understood as "you speak Chinese, you are in China, and the language character set is gb18030/gb2312/utf8"

If the above items are not found, manually install the Chinese language pack

# yum install kde-l10n-Chinese (about 11M)

2. Modify the i18n internationalization and locale.conf localization configuration files

Before modifying the configuration file, let's take a look at the current system locale

#    locale  

   

("en_US.UTF-8" can be understood as "you speak English, you are in the United States, and the language character set is UTF-8" according to the above content) 

The meaning of each item is:

LANG: The language of the current system

LC_CTYPE: language symbols and their classification

LC_NUMERIC: Number

LC_COLLATE: comparison and sorting conventions

LC_TIME: time display format

LC_MONETARY: monetary unit

LC_MESSAGES: Information is mainly prompt information, error information, status information, title, label, button and menu, etc.

LC_NAME: Name writing style

LC_ADDRESS: address notation

LC_TELEPHONE: Phone number notation

LC_MEASUREMENT: Metrics expression

LC_PAPER: Default paper size

LC_IDENTIFICATION: an overview of the information contained in the locale itself

LC_ALL: the highest priority variable, if this variable is set, all LC_* and LANG variables will be forced to follow its value

We see that although the Chinese language pack is installed, the locale of the machine is not Chinese, so first modify the i18n configuration file

#    vim /etc/sysconfig/i18n

Add the following two lines of code

LANG="zh_CN.UTF-8"
LC_ALL="zh_CN.UTF-8"

#  source    /etc/sysconfig/i18n

Then modify the locale.cnf configuration file

#   vim /etc/locale.conf

LANG="zh_CN.UTF-8"

#  source   /etc/locale.conf

reboot the system

# reboot

3. Set the terminal connection code

File->Open->Select Session->Right Click->Properties->Terminal (The terminal connection tool I use is Xshell, other connection tools can change the encoding method by Baidu)

Change encoding to UTF-8

Reconnect, and then view the current system locale

# locale 

It is found that the system locale has been successfully changed to "zh_CN.UTF-8"

Try to edit Chinese again

# vim are you a pig

# ls

SUCCESS! So far, the problem of Chinese garbled characters in the system has been resolved.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325006348&siteId=291194637