內容目錄
一個應用軟體的 多語言化 (M17N)或本地語言支援,通過 2 個步驟完成。
國際化 (I18N): 使一個軟體能夠處理多個語言環境。
本地化 (L10N):使一個軟體處理一個特定的語言環境。
|
提示 |
|---|---|
|
在 multilingualization(多語言化)、internationalization(國際化)和 localization(本地化)中,有17, 18, 或 10 個字母在"m" 和 "n", "i" 和 "n", 或 "l" 和 "n"中間,它們相應表示為 M17N, I18N 和 L10N。細節參見 國際化和本地化 。 |
程式支援國際化的行為,是通過配置環境變數 "$LANG"來支援本地化。語言環境的實際支援,依賴
libc 庫提供的特性,並要求安裝 locales 或
locales-all 軟體包。 locales 軟體包需要被適當的初始化。
如果 locales 或 locales-all
軟體包均沒有安裝,支援語言環境的特性丟失,系統使用 US 英語訊息,並按 ASCII 處理資料。這個行為和 "$LANG" 被設定為
"LANG="、"LANG=C" 或
"LANG=POSIX" 相同。
GNOME 和 KDE 等現代軟體是多語言的。他們通過處理 UTF-8 資料來實現國際化,並通過
gettext(1) 架構提供翻譯資訊來本地化。翻譯資訊可以由獨立的本地化軟體包來提供。
目前的 Debian 桌面 GUI(圖形使用者介面)系統通常在 GUI 環境中設定語言環境為
"LANG=xx_YY.UTF-8"。這裡,"xx" 是 ISO 639 語言程式碼 ,"YY" 是
ISO 3166 國家地區程式碼。這些值由配置桌面的 GUI
對話方塊來設定,並改變程式的行為。參見 節 1.5.2, ““$LANG”變量”
最簡單的文本資料表達是 ASCII,它對英語是足夠的,少於 127 個字元(使用 7 位描述)。
即使純英文文字也可能包含非 ASCII 字元,例如微微卷曲的左右引號在 ASCII 中是不可用的。
“double quoted text” is not "double quoted ASCII" ‘single quoted text’ is not 'single quoted ASCII'
為了支援更多字元,許多字元集和編碼系統被用來支援多語言。(參見 表格 11.2, “編碼值和用法的列表”)。
Unicode 字元集可以用 21 位碼點範圍來顯示幾乎所有人類已知的字元(例如,十六進位制的 0 到 10FFFF)。
文本編碼系統 UTF-8 將 Unicode 碼點適配到一個合理的 8 位資料流,並大部分相容 ASCII 資料處理系統。這個使 UTF-8 作為現代推薦的選擇。UTF 表示 Unicode 轉換格式(Unicode Transformation Format)。當 ASCII 純文本資料轉換為 UTF-8 資料,它有和原始 ASCII 完全一樣的內容和大小。所以配置 UTF-8 語言環境不會有任何丟失。
在 UTF-8
語言環境下相容的應用程式,你可以顯示和編輯外語文本資料,在所要求的字型和輸入法安裝和啟用後。例如在"LANG=fr_FR.UTF-8"語言環境下,gedit(1)
(GNOME 桌面的文本編輯器) 能夠顯示和編輯中文字元文本資料,而顯示的選單是法語。
|
提示 |
|---|---|
|
新標準的
" |
|
注意 |
|---|---|
|
一些程式在支援 I8N 後會消耗更多的記憶體。這是因為它們為了速度優化,而在內部使用 UTF-32(UCS4) 來支援 Unicode,並且每個獨立於語言環境所選的 ASCII 字元資料都會消耗 4 個位元組。再一次地,使用 UTF-8 語言環境並不會使你損失什麼。 |
為了讓系統訪問某一語言環境,語言環境資料必須從語言環境資料庫中編譯。
locales 軟體包 沒有
包含預先編譯的語言環境資料。你需要按下面的方法配置:
# dpkg-reconfigure locales
該過程包含 2 個步驟。
選擇所有需要的語言環境資料編譯為二進位制形式。(請確認至少包含一個 UTF-8 語言環境 )
通過建立 “/etc/default/locale” 來設定系統預設的語言環境值給 PAM 使用(參見 節 4.5, “PAM 和 NSS”)。
設定在 "/etc/default/locale" 裡的系統範圍的預設語言環境,可以被
GUI(圖形使用者介面)應用程式的 GUI 配置覆蓋。
|
注意 |
|---|---|
|
所使用的確切傳統編碼系統可以通過 “ |
locales-all
軟體包有所有預編譯的語言環境資料,但是不建立"/etc/default/locale",你可能還需要安裝
locales 軟體包。
|
提示 |
|---|---|
|
一些 Debian 系發行版的 |
對於跨平臺的資料交換(參見 節 10.1.7, “可移動儲存裝置”),你需要使用特殊的編碼掛載檔案系統.舉個例子,不使用選項時,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, “文字資料轉換工具”. |
在預設情況下,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
通過 $LANGUAGE 環境變數,GNU gettext 能夠適應翻譯語言的優先順序列表。例如:
$ export LANGUAGE="pt:pt_BR:es:it:fr"
獲取更多資訊,參見 info gettext ,閱讀 "The LANGUAGE variable" 章節。
sort(1) 和 ls(1)的字元排序受語言環境 locale 影響。匯出
LANG=en_US.UTF-8,排序用字典
A->a->B->b...->Z->z 順序,而匯出
LANG=C.UTF-8,排序使用 ASCII 二進位制
A->B->...->Z->a->b... 順序。
ls(1) 的日期格式受語言環境影響(參見 節 9.3.4, “定製時間和日期的顯示”)。
date(1)程式的日期格式受語言環境的影響。例如:
$ unset LC_ALL $ LANG=en_US.UTF-8 date Thu Dec 24 08:30:00 PM JST 2023 $ LANG=en_GB.UTF-8 date Thu 24 Dec 20:30:10 JST 2023 $ LANG=es_ES.UTF-8 date jue 24 dic 2023 20:30:20 JST $ LC_TIME=en_DK.UTF-8 date 2023-12-24T20:30:30 JST
不同語言環境的數字標點不一樣。比如說,英語語言環境中, 一千點一顯示為
"1,000.1",而在德語語言環境中,它顯示為
"1.000,1"。你可以在電子表格程式裡面看到這個不同。
"$LANG" 環境變數的每一個細節特徵能夠通過設定 "$LC_*"
變數來覆蓋。這些環境變數又能夠通過設定 “$LC_ALL”變數而被再次覆蓋。細節參見
locale(7) man 手冊頁。除非你有強烈的理由建立複雜的配置,請遠離他們並只使用
"$LANG" 變數來設定一個 UTF-8 語言環境。
The keyboard system can be configured at different layers of the system.
Linux kernel: keyboard(5)
X server: setxkbmap(1),
xkeyboard-config(5), environment variable
XMODIFIERS
GUI desktop environment: Input Method framework: ibus,
fcitx5
Application: environment variables to set its input source:
GTK_IM_MODULE, QT_IM_MODULE,
QT_IM_MODULES, ...
Input method framework (IM) consists of:
Input method engine (IME): Actual input method
Configuration: Handles the configuration for IBus and other services such as IME
Panel: User interface such as language bar and candidate selection table
Multilingual input to the application is processed roughly as:
Keyboard UI panel Configuration Application
| ^ | | ^ ^
v | v v | |
Linux kernel -> Input method engine (IME) -+-> Gtk, Qt -+ |
| ^ | |
| | +-> X, Wayland -+
v |
IME plugin (ibus-mozc, ...)
The Debian system can be configured to work with many international keyboard
arrangements using the keyboard-configuration package.
# dpkg-reconfigure keyboard-configuration
For the Linux console and the X Window system, this updates configuration
parameters in "/etc/default/keyboard". Many non-ASCII
characters including accented characters used by many European languages can
be made available with dead key, AltGr key, and compose
key.
|
注意 |
|---|---|
|
如果 ibus 啟用,即使在基於傳統的 X 的桌面環境下,通過 |
Unlike the X Window protocol, the Wayland core protocol doesn't even support
the input of accented characters. Popular Wayland Compositors, such as
Mutter for GNOME or KWin for KDE, implement extension protocols such as the
text-input-unstable-v3 for the text input (see "current Wayland protocols and their
support status").
The text-input-unstable-v3 protocol works well with Input
methods for Wayland (see "Wayland input method project
post-mortem").
Most GUI applications are built with GUI libraries such as GTK or Qt which
support this text-input-unstable-v3.
Popular Input Method Engines (IME), such as IBus
or Fcitx (version 5), can work with
this text-input-unstable-v3.
IMEs support text input for many languages with plugins.
Recent IMEs integrate X Keyboard
Extension (XKB) functionalities such as setxkbmap
previously provided by the X Window to support accented character text input
for European languages for Wayland.
For GNOME, "ibus" is the default IME which is
automatically installed via its package dependency.
Most multilingualized keyboard input features can be configured from "GNOME Settings" or "GNOME Tweaks".
Some multilingualized keyboard input features may need to be configured from
the ibus-setup(1) command.
The emoji keyboard input is available by typing SUPER-. (period) followed by a keyword for each emoji and SPACE-keys.
The list of IBus and its plugin packages are the following.
表格 8.1. List of IBus and its plugin packages
| 軟體包 | 流行度 | 大小 | 支援的語言環境 |
|---|---|---|---|
| ibus | V:213, I:253 | 1828 | 使用 dbus 的輸入方式框架 |
| ibus-mozc | V:2.1, I:3.8 | 978 | 日文 |
| ibus-anthy | V:0.5, I:1.2 | 8958 | 日文 |
| ibus-skk | V:0.04, I:0.15 | 242 | 日文 |
| ibus-kkc | V:0.03, I:0.19 | 211 | 日文 |
| ibus-libpinyin | V:1.2, I:5.1 | 2767 | 中文(zh_CN) |
| ibus-chewing | V:0.18, I:0.90 | 288 | 繁體中文(zh_TW) |
| ibus-libzhuyin | V:0.00, I:0.11 | 41009 | 繁體中文(zh_TW) |
| ibus-rime | V:0.27, I:0.49 | 78 | 中文(zh_CN/zh_TW) |
| ibus-cangjie | V:0.02, I:0.12 | 235 | 中文(zh_HK) |
| ibus-hangul | V:0.3, I:2.0 | 264 | 韓文 |
| ibus-libthai | V:0.00, I:0.05 | 84 | 泰文 |
| ibus-table-thai | I:0.05 | 59 | 泰文 |
| ibus-unikey | V:0.20, I:0.42 | 286 | 越南語 |
| keyman | I:0.10 | 507 | Multilingual: Keyman plugin for over 2000 languages |
| ibus-table | V:0.08, I:0.99 | 2271 | table plugin for IBus |
| ibus-m17n | V:0.3, I:2.0 | 373 | 多語言:印度語、阿拉伯語和其它 |
Fcitx(版本號5)輸入法框架在中國廣受歡迎並與"ibus"相容。
The list of "fcitx5" and its plugin packages are the
following.
表格 8.2. List of Fcitx5 and its plugin packages
| 軟體包 | 流行度 | 大小 | 支援的語言環境 |
|---|---|---|---|
| fcitx5 | V:7, I:12 | 761 | 輸入方式框架和"ibus"相容 |
| fcitx5-mozc | V:1.0, I:1.6 | 1260 | 日文 |
| fcitx5-anthy | V:0.06, I:0.20 | 808 | 日文 |
| fcitx5-skk | V:0.05, I:0.14 | 369 | 日文 |
| fcitx5-kkc | V:0.00, I:0.06 | 416 | 日文 |
| fcitx5-chinese-addons | I:9.0 | 17 | 中文(zh_* 的元軟體包) |
| fcitx5-pinyin | V:3.8, I:9.4 | 1044 | 中文(zh_CN) |
| fcitx5-chewing | V:0.2, I:1.0 | 217 | 繁體中文(zh_TW) |
| fcitx5-zhuyin | I:0.06 | 41051 | 繁體中文(zh_TW) |
| fcitx5-rime | V:0.44, I:0.84 | 371 | 中文(zh_CN/zh_TW) |
| fcitx5-table-cangjie-large | I:0.12 | 1292 | 中文(zh_HK) |
| fcitx5-hangul | V:0.09, I:0.23 | 235 | 韓文 |
| fcitx5-libthai | I:0.05 | 119 | 泰文 |
| fcitx5-table-thai | I:0.08 | 34 | 泰文 |
| fcitx5-unikey | V:0.08, I:0.20 | 588 | 越南語 |
| fcitx5-m17n | V:0.12, I:0.51 | 259 | 多語言:印度語、阿拉伯語和其它 |
| fcitx5-table | V:0.4, I:9.2 | 520 | table plugin for fcitx5 |
| fcitx5-keyman | V:0.03, I:0.04 | 235 | Multilingual: Keyman plugin for over 2000 languages |
我發現在英語環境("en_US.UTF-8")下啟動日文輸入法非常有用. 下面是在 Wayland 上的
GNOME下使用 IBus 的做法:
Install the Japanese input tool package ibus-mozc (or
ibus-anthy).
選擇 "Settings" → "Keyboard" → "Input Sources" → 在"Input Sources"中單擊
"+" → "Japanese" → "Japanese mozc (or anthy)",
然後單擊"Add"。如果它沒有被啟用。
你可以選擇許多輸入源。
重新登入使用者帳號。
右鍵單擊 GUI 工具條圖示,設定每一個輸入源。
使用SUPER-SPACE在安裝的輸入法之間進行切換. (SUPER鍵通常是Windows鍵.)
|
提示 |
|---|---|
|
如果你希望在日本物理鍵盤(shift- |
For Wayland:
The im-config package does nothing and can be removed
safely.
You probably don't need to set environment variables except for the backward compatibility etc.
If you need to set environment variables, create a file such as
~/.config/environment.d/50-input-method.conf to set them.
For X Window:
Install the im-config package.
im-config(8) 的使用者介面選單入口是 "Input method"。
此外,從使用者的 shell 來執行 "im-config" 。
im-config(8)如果指令是從root帳號執行的表現會有所不同。
im-config(8) 讓最佳的輸入法作為系統預設而不需要使用者干預。
Linux 控制台只能顯示有限的字元。(你需要使用特殊的終端程式,例如 jfbterm(1),從而在非 GUI
控制台中顯示非歐洲語言。)
只要需要的字型安裝並被啟用,GUI(圖形使用者介面)環境(章 7, GUI(圖形使用者介面)系統)能夠顯示任意 UTF-8 字元。(原始字型資料的編碼會被處理,並對使用者來說是透明的。)
The Debian system can be configured to work with many international console
arrangements using the console-setup package.
# dpkg-reconfigure console-setup
For the Linux console and the X Window system, this updates configuration
parameters in "/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.
有幾個元件可以用來調配字元控制檯和 ncurses(3) 系統功能。
“/etc/terminfo/*/*” 檔案(terminfo(5))
“$TERM” 環境變數(term(7))
setterm(1)、stty(1)、tic(1)
和 toe(1)
如果 xterm 的 terminfo 對非 Debian 的
xterm 不起作用,則當你從遠端登入到 Debian 系統時,你需要改變你的終端型別
“$TERM”,從 “xterm” 更改為功能受限的版本(例如
“xterm-r6”)。更多內容參見
“/usr/share/doc/libncurses5/FAQ”。“dumb”
是 “$TERM” 中最通用的。
在東亞語言環境下,方框繪製、希臘字元和西里爾字元可能會顯示得比你預期的樣子更寬,這樣會導致終端輸出排列不再整齊(參見 Unicode 標準附錄 #11,4.2 Ambiguous 字元)。
您可以繞過這個問題:
gnome-terminal:首選項 → 配置檔案 → 配置名 →
相容性 → 寬度有歧義的字元 → 窄
ncurses:設定環境變數 export
NCURSES_NO_UTF8_ACS=0。