From: http://blog.sina.com.cn/s/blog_607dece60100fe0b.html
For Linux users in China, it is a problem that the system often displays garbled characters when it needs to display Chinese characters. For some reason, when it needs a system with an English interface, however, the system cannot normally input and display Chinese characters. in addition, because most major Linux distributions are dominated by English, the system and applications of the English interface are slightly better than those of Chinese in terms of appearance and Stability of the interface, there are also fewer strange bugs. Therefore, many Linux users who have a basic English language prefer to use an English interface system. However, the contradiction emerges again: in the English system, how can we display and enter Chinese characters properly? Is there a perfect solution for both worlds? Therefore, I began to explore how to solve this problem. My perfect state is that the system and applications are all in English (System menu, application toolbar, default input method, etc.), and when I need to read and write Chinese documents, display Chinese characters correctly and call up the Chinese input method. After a successful setup, we now use FC4 Linux as an example to explain some related knowledge and setup processes.
This article mainly describes the general idea and process of modifying the Linux system configuration by modifying the system configuration. If you are not patient, skip Section 1-4 of the article and go directly to Section 5 "Quick Setting.
1. Introduction to related variables
We know that most Linux systems do not support both Chinese and English versions. Taking FC4 Linux as an example, the system is released all over the world. whether the system is Chinese or English depends on the Language Pack you choose. When installing and using different countries, people in different countries select their own language packs. The language in the application is not completely written. It calls the relevant language based on the system settings, once an application is written, it can be used by users in different countries around the world on the mother tongue interface. This is called internationalization (International), or i18n for short. This is also the future trend of software development.
If I have installed different language packs and different fonts on the system, how does the system determine the language interface I want and call the relevant fonts? What files and variables are under control in the system?
In the RedHat and fcseries Linux systems, the default language file used by the system is/etc/sysconfig/i18n. if the system is installed in Chinese by default, the i18n content is as follows:
Code:
Lang = "zh_CN.UTF-8" sysfont = "latarcyrheb-sun16" supported = "zh_CN.UTF-8: zh_cn: ZH"
The Lang variable is short for language. A user with a slight English base can see that this variable determines the default language of the system, that is, the system menu, the tool bar language of the program, and the default language of the input method. Sysfont is short for system font and determines which font is used by default. The supported variable determines the language supported by the system, that is, the language that the system can display. It should be noted that because the computer originated from the English-speaking country, no matter what you set these variables, English is always supported by default, and no matter what font you use, the English font is always included.
Among these variables, Lang variables are used in the character mode and graphic interface. They are read and take effect after you log on to the system, I believe that many users often encounter garbled error messages when entering Linux commands on the Character interface, you must install Chinese software in character mode such as zhcon or CCE to display Chinese error messages normally. What should I do if I don't want him to show Chinese garbled characters or use zhcon specially to read a very simple error message? A simple zero-time solution is to set the Lang variable:
Code:
[Root @ gucuiwen ~] # Lang = "en_US.UTF-8"
That is, to set the system language to English temporarily, or to be simpler, you can directly do this:
Code:
[Root @ gucuiwen ~] # Lang = ""
That is, the Lang variable is cleared. because English is supported in any situation, after the Lang variable is cleared, the system uses English by default. After this setting, the error messages output in character mode are all in English. However, this setting is temporary, but it only changes the bash variable Lang temporarily. It is invalid when you log out and log on again or switch to another character terminal.
Now, the reader should think of, as long as the i18n file in the Lang variable set to English "en_US.UTF-8", you can solve this problem permanently. The modified file is as follows:
Code:
# Lang = "en_US.UTF-8" sysfont = "latarcyrheb-sun16" supported = "zh_CN.UTF-8: zh_cn: ZH"
Please do not simply empty the Lang variable, because this variable is used not only in character mode, but also in the graphic interface. It is no problem to simply clear it in character mode, however, in the graphic interface, Chinese characters cannot be displayed normally. In the past, the i18n file of the Re d ha T series also contains a language variable, the language settings under the graphic interface are specially controlled. Now the fcseries has integrated these two variables into one variable.
After modifying this variable and restarting the graphic interface, you can see that the interface is completely in English. However, you cannot call up the Chinese Input Method by pressing CTRL + space. You cannot add a Chinese Input Method to the input menu. We simply modified the Lang variable to change the system language settings. Of course, this step can also be modified using a tool in the graphic interface without modifying the configuration file.
Ii. Operation Level
This question seems to have nothing to do with the topic of this article, but now more and more Linux beginners are encountering problems with the Linux graphic interface, and these problems are also involved in the Chinese Input Method setting process, so I 'd like to mention it by the way.
After the current Linux installation is complete, it runs at the 5th system running level by default. In the system v-style UNIX system, the system is divided into different running levels, which is different from the Unix of the BSD branch, commonly used as 0 ~ 6. Seven levels:
0 Shutdown
1 single user
2. Multiple users without Networks
3. Multiple users with networks
4 reserved, user-defined
5. Multiple users in the graphic interface
6. restart the system
Since the current Linux system runs at 5th levels after installation, that is, the system directly enters the graphic interface after startup, instead of starting the graphic interface with startx or xinit after logon in character mode. This looks very convenient. But what are the disadvantages? Once you have changed some settings and displayed problems, the system keeps sending tokens between graphics and characters. It is very troublesome for new users to learn how to deal with them, and for those who study Linux, this is not conducive to understanding and learning some underlying Linux things. Old users who have used Linux for a long time know that in the past, Linux such as redhat6.0 had a default running node of 3. Even if redhat9.0 was later installed, they can select the default character logon or graphical logon. However, the current fcseries and most other versions directly allow users to directly log on to the GUI regardless of November 21. Although Linux is becoming easier for most cainiao, there is a lot of fun and new users cannot experience it.
Maybe you don't believe that there are a lot of problems when you log on to the system using graphics. Therefore, as a Linux and Solaris System Administrator with 6 years of Linux experience, I strongly recommend that you set the default running level of the system to 3rd after the system is installed. After logging on to the character terminal, manually enter the startx command to start the graphic interface. You can modify it as follows:
Use a text editor to modify the/etc/inittab File
Code:
ID: 5: initdefault:
Modify this line
Code:
ID: 3: initdefault:
After saving, the system restarts and starts to the character interface by default. The difference between different running levels is that the system starts services by default. For example, Level 3 does not start the x gui service by default, but Level 5 is started by default. There is no difference in nature, and it doesn't matter whether the functions of different levels are strong or not. Users can define different levels of default services on their own. At any running level, you can use the init command to switch to another running level.
3. Call up the Chinese Input Method:
The reason why I have to pay so much attention to the system operation level is that the understanding of the system starts from the bottom up.
First, change the default running level to 3. Of course, if you really don't want to modify it, temporarily use the init 3 command to switch to level 3rd.
In this way, you can start the graphic interface with startx, and then exit the graphic interface with CTRL + ALT + backspace. Note that I am talking about the "exit" graphical interface, instead of pressing CTRL + ALT + F2 to switch to a character terminal.
Okay, everything starts with startx. When you need to set something in a Linux system or configure a service, the most important thing is to know how it starts. You must know why. If you are free, set/etc/rc. the script that runs when the system is started in the d directory is read through, and you will be fully aware of what the configuration files under/etc are used for, how to modify, and what effect the modifications have. You can change the system as you like. This is what I have always stressed. You must know why. Be sure to go deep into the system, read the script, and learn to use commands and manually modify the system configuration file. In this way, you will have a thorough understanding of the system. Using graphical interfaces all day long cannot help you to have a thorough and in-depth understanding of the system, different Linux systems provide different GUI configuration programs, but the commands and configuration files are the same. The more underlying the program, the more universal it is. Therefore, you should first learn to manually configure and modify the system configuration file, and then use the graphical interface tool to modify it to reduce the workload.
I mentioned my ideas for solving the problem above. I started with this idea:
The Chinese input method is used in the graphic interface and is a program running in the graphic interface. Everything in the graphic interface is started and run by the startx program. This is the root cause of the problem.
Locate the startx location:
Code:
[Root @ gucuiwen ~] # Which startx/usr/x11r6/bin/startx
Check whether startx is a script or binary file:
Code:
[Root @ gucuiwen ~] # File/usr/x11r6/bin/startx/usr/x11r6/bin/startx: Bourne shell script text executable
Startx is a shell script, so I opened it for analysis and reading to see if I could find some clues about the input method startup process and related variables:
Code:
[Root @ gucuiwen ~] # Vi/usr/x11r6/bin/startx
I found the information of other scripts and configuration files called by the script during running:
Code:
Userclientrc = $ home/. xinitrc userserverrc = $ home/. xserverrc sysclientrc =/etc/X11/xinit/xinitrc sysserverrc =/etc/X11/xinit/xserverrc
It is also known that startx aims to find the available desktop system X server system and user-defined parameters in the system, and finally calls xinit to initialize the X graphical interface. I did not find the Code directly related to the start Input Method in the startx script, so I can be sure that the Code related to the input method is in the script called by startx. So I came
In the/etc/X11/xinit/directory, read and analyze the scripts in this directory. Some of these scripts are directly called by startx, and some are called by the scripts called by startx, there is a multi-level nesting relationship, and it's hard to figure out without patience. Finally, I found the Code related to the input method in the xinput. Sh script in the/etc/X11/xinit/xinitrc. d directory:
Code:
Lang_region = $ (echo $ tmplang | sed-E's /".. * // ') lang_region = "zh_cn" # This line is added after modification for F in $ home /. xinput. d/$ {lang_region} "$ home /. xinput. d/Default "/etc/X11/xinit/xinput. d/$ {lang_region} "/etc/X11/xinit/xinput. d/default; do [-r $ F] & source $ F & break
Done
Through the analysis script, I know that when the GUI is started, the script determines whether to enable the Input Method Based on the Lang variable, and which language the input method is enabled. The problem is: We haven't changed the Lang variable to English, and the Lang variable obtained by the system is Chinese. Therefore, it knows that the Chinese input method needs to be enabled during the GUI startup process, however, after the Lang variable is changed to English, the system knows that the system is in English based on the Lang variable, so it does not start the Chinese input method or set or export the relevant variables, resulting in the unavailability of the Chinese input method. Therefore, as long as the "cheat" system in this script makes the input script "think" that the system is Chinese, does it run the Chinese Input Method and export the relevant variables? Therefore, through the analysis script, in xinput. sh:
Code:
Lang_region = $ (echo $ tmplang | sed-E's/"... * // ') is followed by lang_region =" zh_cn"
Change lang_region = $ (echo $ tmplang | sed-E's/"... */') to lang_region =" zh_cn ".
You can add more rows for convenience in the future. Simply delete the added row.
Of course, set/etc/X11/xinit/xinput. d/$ {lang_region} in the for loop
/Etc/X11/xinit/xinput. d/ZH _ Cn can also be used.
Of course there are other ways to change the syntax. The premise is that you must understand the shell script syntax and understand the meaning of the script. After this modification, even if the system is in English, xinput. the sh script also reads/etc/X11/xinit/xinput. d/ZH _ Cn file, export the content, set input variables such as xmodifers, and run the iiimx input method program.
So why not directly run the iiimx input method program after the GUI is started? This is not the case. Because the input method program is a software that needs to run with the input application, many variables need to be exported during the operation. Directly running iiimx only runs the main program without relevant variables, and cannot work with the application to complete the input.
After the modification is completed, save the script file. Enter the startx command to start the graphic interface. Then you can use the system interface in full English and the Chinese input method. Note that the system is full of English, and the default input method is English, the application started from gnome or KDE menu cannot be switched to Chinese by pressing CTRL + space when entering Chinese for the first time. You need to click the input method icon on the taskbar to switch, after the first switch, you can use the CTRL + space shortcut to switch between Chinese and English input methods.
Iv. follow-up questions
Some software, such as open office, can be started through gnome or KDE menus. Even if you switch to the Chinese Input Method, you cannot enter Chinese. This is because the entire desktop system environment is in English, software "inherit" The English environment related variables, these software is "identification", is not to allow the input of Chinese, this time can open a gnome terminal, the Lang variable temporary set to zh_CN.UTF-8:
[Root @ gucuiwen ~] # Lang = "zh_CN.UTF-8"
Then, on this gnome terminal, run the following command to open office:
[Root @ gucuiwen ~] # Oowriter &
In this way, the open office inherits the Lang variable of the gnome terminal. After the tool bar and menu are started, they are both Chinese and can enter Chinese. By extension, any software can use this method to open the software on the Chinese interface and the software on the English interface as needed. To run software on the English interface, you only need to open the gnome or KDE menu and modify the Lang variable in the terminal when running the software on the Chinese interface, run the command from the terminal that modified the Lang variable. Of course, if you have installed fonts in other languages, you can run programs on interfaces of other languages. For example, Japanese:
[Root @ gucuiwen ~] # Lang = "ja_JP.UTF-8"
[Root @ gucuiwen ~] # Gedit &
The gedit editor opened with the above two commands is full Japanese interface, but can enter Chinese and English and display Japanese. In this way, a system, multiple languages and texts coexist.
Of course, the premise is that the Japanese font and locale are installed, otherwise all the text will be displayed as a series of question marks. In short, you must first understand the principles and then enjoy the fun of using Linux.
5. Quick setup steps:
1. Modify the/etc/sysconf/i18n file
Lang = "zh_CN.UTF-8"
Modify:
Lang = "en_US.UTF-8"
2. Modify the/etc/X11/xinit/xinitrc. d/xinput. Sh file and put one line in it:
Lang_region = $ (echo $ tmplang | sed-E's /"..*//')
Modify:
Lang_region = "zh_cn"
3. Restart the graphic interface to display Chinese characters and enter Chinese characters on the English interface.
--------------------------------------------------------------------
The following is an individual supplement:
When you log on to Linux Using SSH, ssh terminals sometimes get garbled, even if you set lang = en_US.UTF-8. I have tried securecrt, OpenSSH, and SSH Secure Shell clients. sometimes it is better to change the client settings, but sometimes you can only run a command once after changing the client settings, and then it becomes garbled.
By chance, someone on the Internet said it would be okay to change the Lang variable value to "C. but it's still really evil. It's just lang = C, and all the problems have been solved, and you don't have to set the client anymore. It's really inexplicable! But now I still don't know what the "c" means. It's so amazing.