Display and enter Chinese Characters in an English Linux System

Source: Internet
Author: User
Let the English Linux system display and enter Chinese (to)-General Linux technology-Linux technology and application information. The following is a detailed description. [I = s] This post was last edited by lazycat_work



This article is about displaying Chinese in the graphic interface X.

I. Introduction of related variables we know that most Linux systems do not have Chinese and English versions. Taking FC4 Linux as an example, the system was released all over the world, whether the system is Chinese or English depends on the Language Pack you selected. 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 content of i18n 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 = "" refers to clearing the LANG variable. 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 = "zh_CN.UTF-8"
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 not only used in character mode, also used in the graphical interface, simple clearing does not solve the problem in character mode. However, in the graphic interface, Chinese characters cannot be displayed normally, in the previous Re d ha t series versions, the i18n file also contains a LANGUAGE variable that specifically controls the LANGUAGE settings under the graphic interface, these two variables have been integrated into one variable in the fcseries. 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. 2. The running level issue seems to have nothing to do with the topic of this article, but now more and more linux beginners are encountering issues with the linux GUI, 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 because the current Linux system runs at 5th levels after installation, that is, after the system is started, it directly enters the graphic interface, you do not need to use startx or xinit to start the GUI after logging on 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: This line is modified
Code: id: 3: initdefault: restart after saving, the system 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 runs a program 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 to 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 found that startx is a shell script, so I opened it for analysis and reading, see if you can find some clues about the START process and related variables of the input method:
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. startx aims to find the available desktop system X server system and user-defined parameters in the system, finally, xinit is called 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 analyzes the script. I know that when the GUI is started, the script determines whether to enable the Input Method Based on the LANG variable and the language used for input. 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 /\.. * // ') Then lang_region = "zh_CN" is added to directly add lang_region =$ (echo $ tmplang | sed-e's /\.. * // ') can be modified 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. 4. Some software related to subsequent problems, such as Open Office, cannot be started through GNOME or KDE, even if it is switched to the Chinese input method, 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" and then in this gnome terminal, run the command to open office: [root @ gucuiwen ~] # Oowriter & in this way, the Open Office will "inherit" The LANG variable of the gnome terminal. After starting, the toolbar and menu 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 Setting steps: 1. Modify the/etc/sysconf/i18n file and
LANG = "zh_CN.UTF-8"
Modify:
LANG = "en_US.UTF-8" 2. modify/etc/X11/xinit/xinitrc. d/xinput. sh file, put one line: lang_region =$ (echo $ tmplang | sed-e's /\.. * // ') change to lang_region = "zh_CN" 3. Restart the graphic interface to display Chinese characters and enter Chinese Characters in English.
Related Article

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.