一个应用软件的 Multilingualization (M17N) 或 Native Language Support,通过 2 个步骤完成。
Internationalization (I18N): 使一个软件能够处理多个 locales.
Localization (L10N):使一个软件处理一个特定的 locale.
|
提示 |
|---|---|
|
在 multilingualization, internationalization 和 localization 中,有17, 18, 或 10 个字母在"m" 和 "n", "i" 和 "n", 或 "l" 和 "n"中间,它们相应表示为 M17N, I18N 和 L10N. |
GNOME 和 KDE 等现代软件是多语言的。他们通过处理 UTF-8 数据来实现国际化,并通过 gettext(1) 架构提供翻译信息来本地化。翻译信息可以由独立的本地化软件包来提供。翻译信息易于选择使用,通过给适当的 locale 设置适当的环境变量即可。
最简单的文本数据表示方法是 ASCII,使用少于 127 个字符 (用 7 位表示),这对英语足够了。为了支持用于国际化的更多字符,人们发明了许多字符编码系统。现代知名的编码系统是 UTF-8,它可以处理人类所知的几乎所有字符(参见 第 8.3.1 节 “Basics of encoding”).
细节请参见 i18n 介绍.
有本地化硬件配置数据便能支持国际化硬件。
|
警告 |
|---|---|
|
本章是基于 2013 年发布的 Debian 7.0 ( |
The Debian system can be configured to work with many international keyboard
arrangements using the keyboard-configuration and
console-setup packages.
# dpkg-reconfigure keyboard-configuration # dpkg-reconfigure console-setup
This configures the keyboard for the Linux console and the X Window updates
configuration parameters in "/etc/default/keyboard" and
"/etc/default/console-setup". This also configures the
Linux console font.
Many non-ASCII characters including accented characters used by many European languages can be made available with dead key, AltGr key, and compose key.
For Asian languages, you need more complicated input method support such as IBus discussed next.
Multilingual input to the application is processed as:
Keyboard Application | ^ | | +-> Linux kernel -> Input method -> Gtk, Qt, or X
Setup of multilingual input for the Debian system is simplified by using the
IBus family of packages with the
im-config package. The list of IBus packages are the
following.
表 8.1. IBus 支持的输入方式列表
| 软件包 | 流行度 | 大小 | 支持的 locale |
|---|---|---|---|
| ibus | V:6, I:9 | 1900 | 使用 dbus 的输入方式框架 |
| ibus-mozc | V:0, I:1 | 879 | 日文 |
| ibus-anthy | V:1, I:2 | 746 | 同上 |
| ibus-kkc | V:0, I:0 | 266 | 同上 |
| ibus-skk | V:0, I:0 | 274 | 同上 |
| ibus-pinyin | V:0, I:2 | 1402 | 中文(zh_CN) |
| ibus-chewing | V:0, I:0 | 388 | 中文 (zh_TW) |
| ibus-hangul | V:0, I:0 | 297 | 韩文 |
| ibus-table | V:0, I:1 | 895 | IBus 表引擎 |
| ibus-table-thai | I:0 | 69 | 泰文 |
| ibus-unikey | V:0, I:0 | 239 | 越南语 |
| ibus-m17n | V:0, I:0 | 163 | 多语言:印度语、阿拉伯语和其它 |
The kinput2 method and other locale dependent Asian classic input methods still exist but are not recommended for the modern UTF-8 X environment. The SCIM and uim tool chains are an slightly older approach for the international input method for the modern UTF-8 X environment.
I find the Japanese input method started under English environment
("en_US.UTF-8") very useful. Here is how I did this with
IBus for GNOME3:
Install the Japanese input tool package ibus-anthy with
its recommended packages such as im-config.
Execute "im-config" from user's shell and select
"ibus" as the input method.
Select "Settings" → "Keyboard" → "Input Sources" → click
"+" in "Input Sources" → "Japanese" → "Japanese (anthy)"
and click "Add".
Select "Japanese" and click "Add" to support the Japanese layout keyboard without character conversion. (You may chose as many input sources.)
Relogin to user's account.
Verify setting by "im-config".
Setup input source by right clicking the GUI toolbar icon.
Switch among installed input sources by SUPER-SPACE. (SUPER is normally the Windows key.)
请注意以下几点。
im-config(8) behaves differently if command is executed from root or not.
im-config(8) enables the best input method on the system as default without any user actions.
The GUI menu entry for im-config(8) is disabled as default to prevent cluttering.
If you wish to input without going through XIM (mechanism used by the X),
set "$XMODIFIERS" value to "none" while starting a
program. This may be the case if you use Japanese input infrastructure
egg on
emacs(1)
while disabling ibus. From shell, execute as the
following.
$ XMODIFIERS=none emacs
In order to adjust the command executed by the Debian menu, place customized
configuration in "/etc/menu/" following method described
in "/usr/share/doc/menu/html".
Linux console can only display limited characters. (You need to use special terminal program such as jfbterm(1) to display non-European languages on the non-X console.)
X Window can display any characters in the UTF-8 as long as required font data exists. (The encoding of the original font data is taken care by the X Window System and transparent to the user.)
The following focuses on the locale for applications run under X Window environment started from gdm3(1).
The environment variable "LANG=xx_YY.ZZZZ" sets the
locale to language code "xx", country code
"yy", and encoding "ZZZZ" (see 第 1.5.2 节 ““$LANG”变量”).
The current Debian system normally sets the locale as
"LANG=xx_YY.UTF-8". This uses the UTF-8 encoding with the Unicode character set. This UTF-8 encoding system is a multibyte code system and
uses code points smartly. The ASCII data, which
consist only with 7-bit range codes, are always valid UTF-8 data consisting
only with 1 byte per character.
The previous Debian system used to set the locale as
"LANG=C" or "LANG=xx_YY" (without
".UTF-8").
The ASCII character set is used for
"LANG=C" or "LANG=POSIX".
The traditional encoding system in Unix is used for
"LANG=xx_YY".
Actual traditional encoding system used for "LANG=xx_YY"
can be identified by checking
"/usr/share/i18n/SUPPORTED". For example,
"en_US" uses "ISO-8859-1" encoding and
"fr_FR@euro" uses "ISO-8859-15"
encoding.
|
提示 |
|---|---|
|
For meaning of encoding values, see 表 11.2 “List of encoding values and their usage”. |
Unicode character set can represent practically all characters known to human with code point range from 0 to 10FFFF in hexadecimal notation. Its storage requires at least 21 bits.
Text encoding system UTF-8 fits Unicode code points into a sensible 8 bit data stream compatible with the ASCII data processing system. UTF stands for Unicode Transformation Format.
I recommend to use UTF-8 locale for your
desktop, e.g., "LANG=en_US.UTF-8". The first part of the
locale determines messages presented by applications. For example,
gedit(1)
(text editor for the GNOME Desktop) under
"LANG=fr_FR.UTF-8" locale can display and edit Chinese
character text data while presenting menus in French, as long as required
fonts and input methods are installed.
I also recommend to set the locale only using the "$LANG"
environment variable. I do not see much benefit of setting a complicated
combination of "LC_*" variables (see
locale(1))
under UTF-8 locale.
Even plain English text may contain non-ASCII characters, e.g. slightly curly left and right quotation marks are not available in ASCII.
“double quoted text” is not "double quoted ASCII" ‘single quoted text’ is not 'single quoted ASCII'
When ASCII plain text data is converted to UTF-8 one, it has exactly the same content and size as the original ASCII one. So you loose nothing by deploying UTF-8 locale.
Some programs consume more memory after supporting I18N. This is because they are coded to use UTF-32(UCS4) internally to support Unicode for speed optimization and consume 4 bytes per each ASCII character data independent of locale selected. Again, you loose nothing by deploying UTF-8 locale.
The vendor specific old non-UTF-8 encoding systems tend to have minor but annoying differences on some characters such as graphic ones for many countries. The deployment of the UTF-8 system by the modern OSs practically solved these conflicting encoding issues.
In order for the system to access a particular locale, the locale data must
be compiled from the locale database. (The Debian system does not come with all available locales pre-compiled
unless you installed the locales-all package.) The full
list of supported locales available for compiling is available in
"/usr/share/i18n/SUPPORTED". This lists all the proper
locale names. The following lists all the available UTF-8 locales already
compiled to the binary form.
$ locale -a | grep utf8
The following command execution reconfigures the locales
package.
# dpkg-reconfigure locales
This process involves 3 steps.
Update the list of available locales
Compile them into the binary form
Set the system wide default locale value in
"/etc/default/locale" for use by PAM (see 第 4.5 节 “PAM and NSS”)
The list of available locale should include "en_US.UTF-8"
and all the interesting languages with "UTF-8".
The recommended default locale is "en_US.UTF-8" for US
English. For other languages, please make sure to chose locale with
"UTF-8". Any one of these settings can handle any
international characters.
|
注意 |
|---|---|
|
Although setting locale to " |
The value of the "$LANG" environment variable is set and
changed by many applications.
Set initially by the PAM mechanism of login(1) for the local Linux console programs
Set initially by the PAM mechanism of the display manager for all X programs
Set initially by the PAM mechanism of ssh(1) for the remote console programs
Changed by some display manager such as gdm3(1) for all X programs
Changed by the X session startup code via "~/.xsessionrc"
for all X programs
Changed by the shell startup code, e.g. "~/.bashrc", for
all console programs
|
提示 |
|---|---|
|
It is a good idea to install system wide default locale as
" |
You can chose specific locale only under X Window irrespective of your system wide default locale using PAM customization (see 第 4.5 节 “PAM and NSS”) as follows.
This environment should provide you with your best desktop experience with stability. You have access to the functioning character terminal with readable messages even when the X Window System is not working. This becomes essential for languages which use non-roman characters such as Chinese, Japanese, and Korean.
|
注意 |
|---|---|
|
There may be another way available as the improvement of X session manager package but please read following as the generic and basic method of setting the locale. For gdm3(1), I know you can select the locale of X session via its memu. |
The following line defines file location of the language environment in the
PAM configuration file, such as "/etc/pam.d/gdm3.
auth required pam_env.so read_env=1 envfile=/etc/default/locale
Change this to the following.
auth required pam_env.so read_env=1 envfile=/etc/default/locale-x
For Japanese, create a "/etc/default/locale-x" file with
"-rw-r--r-- 1 root root" permission containing the
following.
LANG="ja_JP.UTF-8"
Keep the default "/etc/default/locale" file for other
programs as the the following.
LANG="en_US.UTF-8"
This is the most generic technique to customize locale and makes the menu selection dialog of gdm3(1) itself to be localized.
Alternatively for this case, you may simply change locale using the
"~/.xsessionrc" file.
对于跨平台的数据交换(参见 第 10.1.7 节 “Removable storage device”),你需要使用特殊的编码挂载文件系统.举个例子,不使用选项时,mount(8) 假设 vfat 文件系统 使用 CP437. 你需要给文件名提供明确的挂载选项来使用UTF-8 或 CP932.
|
注意 |
|---|---|
|
在 GNOME 这类的现代桌面环境下,当自动挂载一个热拔插 U 盘时,你可以提供这样的挂载选项。右击桌面上的图标,点击 "Drive" , "Setting", 输入 "utf8" 到 "Mount options:". 当这个 U 盘下次挂载是,UTF-8 就可以了。 |
|
注意 |
|---|---|
|
如果你在升级一个系统,或者从老的非 UTF-8 系统迁移磁盘,非 ASCII 字符的文件名也许是使用老旧的 ISO-8859-1 或 eucJP 来编码. 请寻求文本转换工具把他们转换到 UTF-8. 参见 第 11.1 节 “Text data conversion tools”. |
在默认情况下,Samba 对新的客户端(Windows NT, 200x, XP)使用
Unicode,但对老的客户端(DOS 和 Windows 9x/Me)使用 CP850.可以在 "/etc/samba/smb.conf"
文件里面,使用"dos charset" 来改变老客户端的这个默认编码。比如说,CP932 表示为日语。
在 Debian 系统中显示的许多文档和文本信息有翻译存在,比如错误信息、标准程序输出、菜单和手册页。GNU gettext(1) 命令工具链是大部分翻译活动的后端工具。
aptitude(8) 里,"Tasks" → "Localization" 提供一个有用的二进制包扩展列表, 给应用程序增加本地化信息和提供翻译文档。
举个例子,你可以安装 manpages-<LANG> 包来获得本地化 man 手册页信息。从
"/usr/share/man/it/" 来读取 <programname> 意大利语的 man
手册页 ,执行下面的操作。
LANG=it_IT.UTF-8 man <programname>
sort(1) 的字符排序,受 locale 语言选择的影响. 西班牙语和英语的 locale 排序是不一样的。
ls(1)
的日期格式受 locale 影响. "LANG=C ls -l" 和
"LANG=en_US.UTF-8" 的日期格式是不一样的(参见 第 9.2.5 节 “Customized display of time and date”).
不同 locales 的数字标点不一样.比如说,英语 locale, 一千点一显示为 "1,000.1",而在德语
locale,它显示为 "1.000,1". 你可以在电子表格程序里面看到这个不同。