Construct a graphical installation program for Linux (2) (1)

Source: Internet
Author: User
Tags i18n

This section describes how to start the graphic environment and set the Chinese language environment after the installation program is loaded into the memory. In addition to introducing the specific programming implementation of these two functions by the installer, this article also introduces some basic knowledge about Linux culture, including how to customize the Locale environment Glibc and X Window System required in the installation program display), po file processing. After the second stage of the installation program is completed, the entire installation program has been transferred to the memory. At this time, the control is transferred from the installation program's loader to the main program of the installation program for execution. At this time, the installer is like a program started from the Linux Console environment, which performs automatic detection and basic device configuration. To perform graphical installation, the main program of the installer starts the XFree86 sub-system and sets the current language environment as a Chinese environment.
1. multi-language environment support
To implement multi-language support in Linux, you must introduce the multi-language environment support corresponding to glibc and graphic environment when customizing the installation program. For the glibc environment, it is the foundation of the entire Linux culture. We need to save the locale information in the/usr/share/Locale directory, save the font information in the/usr/share/consolefonts directory and save the information of the character conversion module in the/usr/lib/gconv directory.
In X Windows, we need to save the configuration of X locale in the/usr/X11R6/lib/X11/Locale directory, at the same time, save the required font set in the/usr/X11R6/lib/X11/fonts directory.
After the installer starts, you must correctly set the LC _ * variable and call the setlocale function. To display Chinese characters, the installer must also load the correct Chinese font.
1.1. Basic concepts of Internationalization
Internationalization (I18N) is an extension feature that supports multiple languages in the design structure and mechanism. Its functions and code design are not specific to a specific attribute or region. Locale is the most basic identifier for ansi c to support internationalization. For Chinese Linux, it is the most basic requirement to support Chinese Locale.
1.1.1. Locale environment
Locale naming rules: <language >_< region Name>. <character encoding name>
For zh_CN.GB2312, zh represents Chinese characters, CN represents Chinese regions, and GB2312 represents GB2312.
Locale uses a group of categories, allowing you to manipulate each group of categories independently. You can either set environment variables or setlocale. These types are stored in/usr/share/locale. They include:
LC_COLLATE
Used for comparison and sorting.
LC_CTYPE
It is used for character classification and string processing to control the Processing Methods of all characters, including character encoding, whether the characters are single-byte or multi-byte, and how to print them.
LC_MONETORY
Format the currency unit.
LC_NUMERIC
Format the display of non-currency numbers.
LC_TIME
Used to format the time and date.
LC_MESSAGES
It is used to control the language used for program output, including prompt information, error information, status information, title, label, button, and menu.
LC_ALL
It is not an environment variable, but a macro. You can use setlocale to set all LC _ * environment variables. After setting this variable, You can abolish the set values of LC _ * and LANG so that the set values of these variables are consistent with those of LC_ALL.
LANG
The value is used to specify all the variable values not set in the preceding environment variable. If the value of any of the preceding variables is specified, the default setting of the corresponding LANG value is abolished.
Other environment variables include LC_ADDRESS, LC_IDENTIFICATION, LC_PAPER, LC_NAME, LC_TELEPHONE, and LC_MEASUREMENT.
Standard Locale:
"C"
This is the standard C Locale. The attributes and behaviors specified by iso c are specified. Locale is used by default when the program starts.
"POSIX"
This is the standard POSIX Locale. It is the alias of the Standard C Locale.
""
An empty name is used to allow the program to select the current environment setting value.
To set a Chinese environment, you must correctly set the above Locale variable. For example, when you use the zh_CN.GB2312 environment, run the locale command. The system environment you see is:
LANG = "zh_CN.GB2312"
LC_CTYPE = "zh_CN.GB2312"
LC_NUMERIC = "zh_CN.GB2312"
LC_TIME = "zh_CN.GB2312"
LC_COLLATE = "zh_CN.GB2312"
LC_MONETARY = "zh_CN.GB2312"
LC_MESSAGES = "zh_CN.GB2312"
LC_PAPER = "zh_CN.GB2312"
LC_NAME = "zh_CN.GB2312"
LC_ADDRESS = "zh_CN.GB2312"
LC_TELEPHONE = "zh_CN.GB2312"
LC_MEASUREMENT = "zh_CN.GB2312"
LC_IDENTIFICATION = "zh_CN.GB2312"
LC_ALL =
1.1.2. Create a Locale environment
To create a locale environment, we must have the following description file:
Locale-data
This file defines all the details of the Locale environment LC _ *, including character classification and conversion, character sorting, Region display time, currency display format, and so on. It is usually stored in the/usr/share/i18n/locales directory of the system.
Charmap
This file defines the correspondence between all characters in Locale and the inner code. It is usually stored in the/usr/share/i18n/charmaps directory of the system.
Both files are plain text files and can be viewed and modified directly using the text editor. The two files can generate the corresponding locale environment. By default, the generated locale environment is saved in the/usr/share/locale directory in binary format. The locale environment generated by these two text files is implemented by the localedef program. For example, generate the locale environment of zh_CN.GB2312:
Mkdir/home/usr/share/locale/zh_CN.gb2312
Localedef-I zh_CN-f GB2312 zh_CN.GB2312 -- prefix =/home
Cd/home/usr/share/locale/
Mv zh_CN.gb2312 zh_CN.GB2312
These commands are run in the/home directory to generate the Locale environment zh_CN.GB2312. According to the POSIX standard, a Locale encoding name is case-insensitive. Although we specify GB2312 in uppercase, glibc generates a lower-case encoding name for uniformity. However, many programs depend on zh_CN.GB2312, so this file is renamed.
In addition to the Locale environment, you also need the gconv file. This group of files is used to define which module should be used for processing when glibc's gconv system encounters GB2312 encoding characters. The gconv-modules file describes the correspondence between character encoding and processing module files. For example, the/usr/lib/gconv/gonv-modules file must contain the following lines:
Alias GB2312 // EUC-CN //
1.1.3. X Windows multi-language environment
The multi-language environment of the X Window System is built on the Locale architecture of the underlying libc system. The X function library uses the functions provided by libc to convert characters. Therefore, to make the Locale of the X Window application work correctly, you must first set a correct libc Locale environment and set the LC_CTYPE category correctly.
After encoding is specified and character recognition and conversion are processed using the libc function, the main problem of multi-language processing in X Window System is graphic display and input. In the X system, multi-language environments must be able to provide graphic output and character input for multi-language characters. The graphical output of characters also needs to process the font, which is related to the font setting method.
Like libc, Locale is also set in X Window System, which is called X-Locale. All XFree86 systems keep it in the/usr/X11R6/lib/X11/locale directory. Each Locale in this directory has a directory that stores its own X-locale. Generally, the file name is XLC_LOCALE. This file contains the settings related to the encoding of the Region, and comments starting with the # font size in the file. Take the content of Simplified Chinese XLC_LOCALE on the installer as an example:
XLC_FONTSET
# Fs0 class (7-bit ASCII)
Fs0 {
Charset {
Name ISO8859-1: GL
}
Font {
Primary ISO8859-1: GL
Vertical_rotate all
}
}
# Fs1 class
Fs1 {
Charset {
Name GB2312.1980-0: GL
}
Font {
Primary GB2312.1980-0: GL
}
}
END XLC_FONTSET
The preceding content defines the character set used to display Locale. In a multi-language environment, in order to display both Chinese and English at the same time, the system usually requires multiple fonts. For example, in the above example, two different encoding fonts are used to display Simplified Chinese, one of which is a Chinese font encoded in GB2312, whose font name ends with a GB2312.1980-0, the other is the English font of the ISO8859-1 Code whose font name ends with the ISO8859-1.
The next section of XLC_LOCALE defines how the font of Locale is processed in the X system:
XLC_XLOCALE
Encoding_name zh. euc
Mb_cur_max 2
State_depend_encoding False
Wc_encoding_mask \ x30000000
Wc_shift_bits 7
Cs0 {
Side GL: Default
Length 1
Wc_encoding \ x00000000
Ct_encoding ISO8859-1: GL
}
Cs1 {
Side GR: Default
Length 2
Wc_encoding \ x30000000
Ct_encoding GB2312.1980-0: GL; GB2312.1980-0: GR
}
END XLC_XLOCALE
The part defined by cs0 is a iso8859-1-encoded English character, each character occupies one byte. Cs1 defines a part of the GB2312 Encoded chinese character, each occupying two bytes, both of which must be represented in a GB2312.1980-0 font. Note that for the above X settings, the font of the GB2312.1980-1 type cannot be properly displayed unless the user modifies X Locale.
In addition, the/usr/X11R6/lib/X11/locale file uses the locale. dir and locale. alias files to define the names and locations of available X-Locale. Locale. dir defines the location of each X-Locale file and the actual Locale name. The locale. alias file defines the possible aliases of each Locale.
The font of X Window is stored in the/usr/X11R6/lib/X11/fonts directory. The PCF font is generally used. After copying a new font file to this directory, run
Mkfontdir
Use this command to update the fonts. dir contents in the directory. For example,
Fzs14.pcf. Z fzs14
HelvR12_iso01.pcf.gz-adobe-helvetica-medium-r-normal -- 12-120-75-75-p-67-iso8859-1
The two lines of information are extracted from the file, such as, helvr12_iso01.pcf.gz file contains iso8859-1 encoding files. However, the font file fzs14.pcf. Z does not contain similar font instructions. Therefore, we also need to use the fonts. alias file to create a font alias.
-Hlc-song-medium-r-normal -- 14-140-75-75-c-140-gb2312.1980-0 fzs14
In this way, when the installer uses the following resources, the X Window System will know to load the fzs14 font.
Style "font "{
Fontset = "-*-helvetica-*-r-normal-*-14-*-iso8859-1, -*-medium-*-14-*-gb2312.1980-0"
}
1.2. International Implementation of the installer
Automatically generate po files
In the installer, two functions _ () and _ () are defined. The former translates the input strings, and the latter directly returns the input strings, all strings to be supported in multiple languages must use these two functions. They are used differently in the installer. The former is used for some interface controls that can be reconstructed, and their values are generally used as local variables; the latter is generally used for global variables. To display this string in multiple languages, you need to use translate) function. The main purpose of using these two functions is to easily use the xgettext program to automatically generate po files.
Xgettext only takes effect for the c language source program file. Therefore, before using it, you must first convert the perl source program into a c program, and then run xgettext to automatically propose a text string that requires multi-language processing. The following program segment is part of the Makefile in the po directory. It can automatically generate an empty po file.
PMSFILES = $ (wildcard *. pm)
PMSCFILES = $ (PMSFILES: % = % _. c)
POFILES = $ (shell ls *. po)
All: $ (PMSCFILES) DrakX. pot
Clean:
Rm-f empty. po messages $ (POFILES: % = % t) $ (PMSCFILES)
Verif:
Perl-ne '/^ \ s * #/or $ I + = my @ l =/\ B __? \ (/G; END {print "$ I \ n"} '$ (PMSFILES)
Perl-ne '$ I + = my @ l =/\. c:/g; END {print "$ I \ n"}' DrakX. pot
DrakX. pot: $ (PMSFILES)
Xgettext-F-n -- keyword = _ -- keyword =__-o $ (PMSCFILES)
Rm $ (PMSCFILES)
$ (PMSCFILES): % _. c: %
Perl-pe's | ^ (__? \ () | $1 |; s | # ([^ +]. *) |/* \ 1 * \/|; s | $ | \ n \ | '$ <>$ @


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.