[Turn] Ubuntu encoding UTF-8 GBK gb18030

Source: Internet
Author: User
Tags mozilla thunderbird mozilla thunderbird mail thunderbird mail
Add encoding support
sudo locale-gen zh_CN.GBKsudo locale-gen zh_CN.GB2312sudo locale-gen zh_CN.GB18030

2. Update locale:

sudo dpkg-reconfigure locales

Sudo locale-gen

If
Zh_cn.gb18030... Done

Prompts such as indicate that the internal code has been installed successfully

//////////////////////////////////////// //////////////////////////////////////// ////////////////////

Display Chinese characters:
$ Sudo apt-Get update
Then you can select and install Chinese in system> Administration> language support.
In this way, the interface can display Chinese, but the default encoding standard is UTF-8, and many applications are developed in windows, the default encoding is gb2312, in this way, garbled characters are generated after transplantation.
Change to GBK encoding:
$ Sudo locale-gen
Edit/var/lib/locales/supported. d/local
Add zh_cn.gbk GBK
Edit/etc/environment
Change
Lang = zh_cn.gbk
Language = "zh_cn: Zh: en_us: en"
Ststst_id3_tag_rncoding = GBK
Lc_ctyle = zh_cn.gbk
Lc_all = "zh_cn.gbk"

Today, I started to migrate all my work environments to Linux. After a day, it was quite calm. Fortunately, the Mozilla Thunderbird mail client was used in Windows instead of outlook, which is too convenient. You can directly copy the MB mail storage directory to Linux for direct use, in stark contrast, Microsoft's new version of live Messager found today that Microsoft does not even support installation on their own WINXP 64/wind2003/2008? I have nothing to say.

Ubuntu uses UTF-8 encoding by default to facilitate global operation. However, the support for Chinese characters is not detailed. Even if it is installed in Chinese by default, no GB * or other support will be automatically added, causing garbled characters when accessing some win text files in Ubuntu.

I. Configure the system environment
Run sudo VI/var/lib/locales/supported. d/ZH
Add the following configuration parameters

Zh_cn.gb18030 gb18030 (the latest Chinese character encoding Character Set, backward compatible with GBK, gb2312)
Zh_cn.gbk GBK (expanded Chinese character encoding, backward compatible with gb2312, and contains all big5 Chinese characters)
Zh_cn.gb2312 gb2312! ")
Zh_cn.gb18031 gb18031. Maybe's heroes who use Google Android SDK need this)
Zh_hk.big5 big5 (traditional)
Zh_tw.big5 big5 (traditional)

Then run sudo locale-gen
The following message is displayed.
Zh_cn.gb18030... Done
Zh_cn.gbk... Done
......

II. The system environment supports GB * Internal Code. However, if you use tools such as VI and gedit to access files, garbled characters will continue. You need to configure different tools to detect the supported encoding.
E.g. vi
Run sudo VI/etc/Vim/vimrc
Add the following configuration parameters
Let & termencoding = & Encoding
Set fileencodings = UTF-8, gb18030, GBK, gb2312, big5

E.g. gedit
Run sudo gconf-editor.
Select apps/gedit-2/preferences/encodings
Find auto_detected and add gb18030, GBK, gb2312, and big5 to values.

OK ~

Thanks to LEC for its support.
The enca tool is very convenient and used to detect file inner code (the premise is that the system environment supports, for example, the environment does not support big5, so it cannot be detected. It has been dizzy for a long time)
Install sudo apt-Get install enca
Use enca filename
This tool is found in Google (http://blog.oolec.com /? P = 79), found around the Earth, Meng found that the author of the article is sitting next to me, and then find something to ask first, don't blindly run.

Enable Ubuntu to display gb2312 and GBK encoded files normally
  • Lduug was released on 00:27:00

1842

   

The utf8 character set in the Ubuntu environment, the Windows Default character set is GBK, And the Ubuntu default character set is UTF-8, which causes garbled characters when you use Telnet to log on to a remote server or view Windows files. Set the Ubuntu environment to GBK or gb2312, or set the software to correctly display Chinese characters. The following uses the GBK character set as an example:

1. Modify the default Ubuntu character set to GBK.
1. First set sudo VI/var/lib/locales/supported. d/local
Add a row of zh_cn.gbk GBK
Sudo locale-gen generates locale

 

2. Modify the Ubuntu Character Set
Method 1: Modify the. profile file in the user directory and add the following content:
Language = "zh_cn: Zh: en_us: en"
Lang = zh_cn.gbk
Log on again.
This method is only valid for this user.
Method 2: Modify/etc/environment and add the following content:
Language = "zh_cn: Zh: en_us: en"
Lang = zh_cn.gbk
Restart X.
This method is valid for users who have not set Lang and language environment variables.

2. Set the software name to display the GBK normally
This requires the software to support multi-character encoding. The most common is IE and other browsers. You can set the encoding to display the GBK character set. Some software in Ubuntu also supports this function. Taking Ubuntu's End-End program as an example, you can enable it to normally display GBK encoding by clicking the menu in the termial window: terminal-> set character encoding-> select GBK.

######################################## ##

Fix Chinese garbled characters in file names, MP3 tags, and text files

Users who transfer files from windows to Ubuntu often find that the files they create, download, and save in windows are often garbled (kubuntu is more likely to have problems ). When you use the default player to open previous music files (such as MP3), the chance of Garbled text is close to 100%.

The solutions to these problems have been included in Ubuntu's usage skills, but I think it is necessary to move them here due to the universality of the problem.

Convert the file name from GBK to utf8

Sudo apt-Get install convmv
Convmv-r-F cp936-T utf8-notest-nosmart *
Convert the file content from GBK to utf8 iconv-f gbk-T utf8 $ I> newfile
Convert MP3 tag Encoding

Sudo apt-Get install Python-mutagen
Find.-INAME "*. MP3"-execdir mid3iconv-e GBK {}\;

#####################################
Gedit is used to open the. txt file in buntu.pdf by default, gedit is UTF-8 encoded. The gb2312 files edited in windows are garbled. One solution is to change the gedit encoding to gb2312. The method is as follows:

Right-click applications and choose editmenu. In the mainmenu dialog box, select systemtools-configurationeditor and enable it from the applications menu.

Turn on/apps/gedit-2/preferences/encodings/double-click auto_detected on the right, click Add in the pop-up dialog box, add values value to gb2312, OK, select, click the up button to move it to the first place.

Similarly, set show_in_menu and set gb2312 to the first place.

Another scheme is that when you open the .txt file using openoffice, you will be asked to select encoding and select gb2312.

**************************************** *******

1. Default System Encoding

We know that in Chinese Windows, the default encoding of the system is GBK. From the perspective of Java Development, it is to perform operations such as Java source code compilation and file read/write, the default encoding is GBK, and we refer to the general Ubuntu Chinese installation documentation, may be recommended to set the default language to zh_CN.UTF-8, this will bring some problems, for example, when I use eclipse in windows, the default encoding of the editor is GBK, but under Ubuntu is the UTF-8, the same is the use of Eclipse, in windows under the Chinese documentation to Ubuntu will generate garbled, you must manually set the attribute encoding to GBK one by one for normal operations. Some test codes also use the default encoding to read files. The files read from these codes also contain garbled characters.

Therefore, it is best to set the system's default encoding to GBK, which is the closest to the development environment in windows. there should be more than one setting method. I used/etc/environment to edit it:
Language = "zh_cn: Zh: en_us: en"
Ststst_id3_tag_encoding = GBK
Lang = zh_cn.gbk
Lc_ctyle = zh_cn.gbk

**************************************** ******
Ubuntu Chinese encoding settings
Today, I started to migrate all my work environments to Linux. After a day, it was quite calm. Fortunately, the Mozilla Thunderbird mail client was used in Windows instead of outlook, which is too convenient. You can directly copy the MB mail storage directory to Linux for direct use, in stark contrast, Microsoft's new version of live Messager found today that Microsoft does not even support installation on their own WINXP 64/wind2003/2008? I have nothing to say.

Ubuntu uses UTF-8 encoding by default to facilitate global operation. However, the support for Chinese characters is not detailed. Even if it is installed in Chinese by default, no GB * or other support will be automatically added, causing garbled characters when accessing some win text files in Ubuntu.

I. Configure the system environment
Run sudo VI/var/lib/locales/supported. d/ZH
Add the following configuration parameters

Zh_cn.gb18030 gb18030 (the latest Chinese character encoding Character Set, backward compatible with GBK, gb2312)
Zh_cn.gbk GBK (expanded Chinese character encoding, backward compatible with gb2312, and contains all big5 Chinese characters)
Zh_cn.gb2312 gb2312 !")
Zh_cn.gb18031 gb18031. Maybe's heroes who use Google Android SDK need this)
Zh_hk.big5 big5 (traditional)
Zh_tw.big5 big5 (traditional)

Then run sudo locale-gen
The following message is displayed.
Zh_cn.gb18030... Done
Zh_cn.gbk... Done
......

II. The system environment supports GB * Internal Code. However, if you use tools such as VI and gedit to access files, garbled characters will continue. You need to configure different tools to detect the supported encoding.
E.g. vi
Run sudo VI/etc/Vim/vimrc
Add the following configuration parameters
Let & termencoding = & Encoding
Set fileencodings = UTF-8, gb18030, GBK, gb2312, big5

E.g. gedit
Run sudo gconf-editor.
Select apps/gedit-2/preferences/encodings
Find auto_detected and add gb18030, GBK, gb2312, and big5 to values.

[Turn] Ubuntu encoding UTF-8 GBK gb18030

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.