aboutsummaryrefslogtreecommitdiff
path: root/documentation/content/zh-tw/books/handbook/l10n/_index.adoc
blob: e08ad133d5e5c756f6420fa26779a72ed25c41c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
---
title: 章 22. 在地化 - i18n/L10n 使用與安裝
part: 部 III. 系統管理
prev: books/handbook/virtualization
next: books/handbook/cutting-edge
---

[[l10n]]
= 在地化 - i18n/L10n 使用與安裝
:doctype: book
:toc: macro
:toclevels: 1
:icons: font
:sectnums:
:sectnumlevels: 6
:sectnumoffset: 22
:partnums:
:source-highlighter: rouge
:experimental:
:images-path: books/handbook/l10n/

ifdef::env-beastie[]
ifdef::backend-html5[]
:imagesdir: ../../../../images/{images-path}
endif::[]
ifndef::book[]
include::shared/authors.adoc[]
include::shared/mirrors.adoc[]
include::shared/releases.adoc[]
include::shared/attributes/attributes-{{% lang %}}.adoc[]
include::shared/{{% lang %}}/teams.adoc[]
include::shared/{{% lang %}}/mailing-lists.adoc[]
include::shared/{{% lang %}}/urls.adoc[]
toc::[]
endif::[]
ifdef::backend-pdf,backend-epub3[]
include::../../../../../shared/asciidoctor.adoc[]
endif::[]
endif::[]

ifndef::env-beastie[]
toc::[]
include::../../../../../shared/asciidoctor.adoc[]
endif::[]

[[l10n-synopsis]]
== 概述

FreeBSD 計劃的使用者及貢獻者分佈在世界各地,也因此 FreeBSD 支援多語系,讓使用者可以使用非英文語言來檢視、輸入或處理資料。使用者可以選擇大多數主要語言,包含但不限於以下語言:中文、德文、日文、韓文、法文、俄文及越南文。

`國際化` (Internationalization) 一詞可以縮寫為 i18n,即 第一個字母到最後一個字母間的字母數量。L10n 也使用同樣的命名規則,但源自 `在地化` (Localization)。 i18n/L10n 的方法、協定及應用程式讓使用者可以自己選擇使用的語言。

本章會討論 FreeBSD 的國際化及在地化功能。在閱讀本章之後,您會了解:

* 語系名稱如何組成。
* 如何設定登入 Shell 的語系。
* 如何設定 Console 給非英文語言的使用者。
* 如果設定 Xorg 使用不同語言。
* 如何找到支援 i18n 的應用程式。
* 那裡可以找到更多設定特定語言的資訊。

在開始閱讀這章之前,您需要:

* 了解如何 crossref:ports[ports,安裝其他第三方應用程式]。

[[using-localization]]
== 使用語系

語系設定值由三個元件所組成:語言代號、城市代號及編碼。語系名稱組成的方式如下:

[.programlisting]
....
LanguageCode_CountryCode.Encoding
....

_LanguageCode_ 與 _CountryCode_ 用來表示城市及特定語言。<<locale-lang-country>> 提供了幾個 __LanguageCode_CountryCode__ 的範例:

[[locale-lang-country]]
.常用語言及城市代碼
[cols="1,1", frame="none", options="header"]
|===
| 語言代號_城市代號
| 說明

|en_US
|英文,美國

|ru_RU
|俄文,俄國

|zh_TW
|繁體中文,台灣
|===

完整可用的語系清單可用以下指令查詢:

[source,shell]
....
% locale -a | more
....

查詢目前使用的語系設定:

[source,shell]
....
% locale
....

語言特定的字元集如 ISO8859-1, ISO8859-15, KOI8-R 及 CP437 在 man:multibyte[3] 有詳細說明。可用的字元集可在 http://www.iana.org/assignments/character-sets[IANA Registry] 查詢。

某些語言,如中文或日文,無法使用 ASCII 字元表示,會需要使用寬 (Wide) 字元或多位元組 (Multibyte) 字元來擴充的語言編碼。EUC 與 Big5 即是使用寬子元或多位元組字元的例子。舊的應用程式會誤判這些字元為控制字元,新的應用程式則通常可以辨識這些字元,依實作的需要,使用者可能需要開啟寬字元或多位元組字元支援或者使用正確的字元設定來編譯應用程式。

[NOTE]
====
FreeBSD 使用 Xorg 相容的語系編碼。
====

本節剩餘的部份將說明各種在 FreeBSD 系統上設定語系的方法。下一節將會探討如何尋找以及編譯使用 i18n 支援的應用程式。

[[setting-locale]]
=== 設定登入 Shell 的語系

語系設定可在使用者的 [.filename]#~/.login_conf# 或使用者的 Shell 的啟動檔設定:[.filename]#~/.profile#, [.filename]#~/.bashrc# 或 [.filename]#~/.cshrc#。

有兩個環境變數需要設定:

* `LANG` 用來設定語系
* `MM_CHARSET` 用來設定應用程式所使用的 MIME 字元集

除了使用者的 Shell 設定外,這些變數也應針對特定應用程式設定以及 Xorg 設定。

兩種可以完成所需變數設定的方法有:<<login-class,登入類別 (Login class)>> 法 (較建議) 及 <<startup-file,啟動檔 (Startup file) >> 法。以下兩節將示範如何使用這兩個方法。

[[login-class]]
==== 登入類別 (Login Class) 法

第一種方式,同時也是建議使用的方法,它可以對任何可能的 Shell 設定需要的語系及 MIME 字元集變數。此設定也可由每位使用者自行設定或者由超級管理者為所有使用者設定。

以下精簡範例示範在一個使用者的家目錄中的 [.filename]#.login_conf# 設定 Latin-1 編碼使用的兩個環境變數:

[.programlisting]
....
me:\
	:charset=ISO-8859-1:\
	:lang=de_DE.ISO8859-1:
....

以下使用者的 [.filename]#~/.login_conf# 範例設定了繁體中文於 BIG-5 編碼使用到的環境變數。有一部份應用程式無法正確處理中文、日文及韓文的語系變數,因此需要額外多做一些設定:

[.programlisting]
....
#Users who do not wish to use monetary units or time formats
#of Taiwan can manually change each variable
me:\
	:lang=zh_TW.Big5:\
	:setenv=LC_ALL=zh_TW.Big5,LC_COLLATE=zh_TW.Big5,LC_CTYPE=zh_TW.Big5,LC_MESSAGES=zh_TW.Big5,LC_MONETARY=zh_TW.Big5,LC_NUMERIC=zh_TW.Big5,LC_TIME=zh_TW.Big5:\
	:charset=big5:\
	:xmodifiers="@im=gcin": #Set gcin as the XIM Input Server
....

或者,超級使用者可以設定所有系統使用者的語系。以下在 [.filename]#/etc/login.conf# 中的變數可用來設定語系及 MIME 字元集:

[.programlisting]
....
language_name|Account Type Description:\
	:charset=MIME_charset:\
	:lang=locale_name:\
	:tc=default:
....

若套用之前的 Latin-1 編碼範例如下:

[.programlisting]
....
german|German Users Accounts:\
	:charset=ISO-8859-1:\
	:lang=de_DE.ISO8859-1:\
	:tc=default:
....

請參考 man:login.conf[5] 以取得更多有關這些變數的詳細資訊。請注意,它已經含有預先定義的 _russian_ class。

每次編輯 [.filename]#/etc/login.conf# 之後,請記得要執行以下指令來更新登入類別的能力資料庫(Capability database):

[source,shell]
....
# cap_mkdb /etc/login.conf
....

===== 變更登入類別的工具

除了手動編輯 [.filename]#/etc/login.conf# 之外,尚有需多工具可用來為新建立的使用者設定語系。

當使用 `vipw` 來新增使用者時,可指定 _language_ 來設定語系:

[.programlisting]
....
user:password:1111:11:language:0:0:User Name:/home/user:/bin/sh
....

當使用 `adduser` 來新增使用者時,可對所有使用者或指定的使用者事先設定預設的語言。

若所有新的使用者都使用同樣的語言,可在 [.filename]#/etc/adduser.conf# 設定 `defaultclass=_language_`。

要在建立使用者時覆蓋預設的設定,可在出現此提示時輸入需要的語系:

[source,shell]
....
Enter login class: default []:
....

或執行 `adduser` 時指定語系:

[source,shell]
....
# adduser -class language
....

若使用 `pw` 來新增使用者,則可指定語系如下:

[source,shell]
....
# pw useradd user_name -L language
....

To change the login class of an existing user, `chpass` can be used. Invoke it as superuser and provide the username to edit as the argument.

[source,shell]
....
# chpass user_name
....

[[startup-file]]
==== Shell 啟動檔 (Startup File) 法

第二種方法,較不建議使用,因每一種使用到的 Shell 都需要手動設定,而每一種 Shell 都有不同的設定檔以及語法。例如將一位使用者的 `sh` shell 設定為德語,需要將下列行加到 [.filename]#~/.profile#,若要設定給使用該 Shell 的所有使用者則必須將下列行加到 [.filename]#/etc/profile# 或 [.filename]#/usr/shared/skel/dot.profile#:

[.programlisting]
....
LANG=de_DE.ISO8859-1; export LANG
MM_CHARSET=ISO-8859-1; export MM_CHARSET
....

然而,在 `csh` shell 所使用的設定檔名稱及語法不同。同樣的設定需加入下列行至 [.filename]#~/.csh.login#, [.filename]#/etc/csh.login# 或 [.filename]#/usr/shared/skel/dot.login#:

[.programlisting]
....
setenv LANG de_DE.ISO8859-1
setenv MM_CHARSET ISO-8859-1
....

更複雜一點的情況,Xorg 的 [.filename]#~/.xinitrc# 語系設定會依使用的 Shell 而有所不同。第一個例子是針對 `sh` shell 而第二個則是針對 `csh` shell:

[.programlisting]
....
LANG=de_DE.ISO8859-1; export LANG
....

[.programlisting]
....
setenv LANG de_DE.ISO8859-1
....

[[setting-console]]
=== Console 設定

已有許多語系的字型可在 Console 使用,要查看可用的字型清單,可輸入 `ls /usr/shared/syscons/fonts`。要設定 Console 的字型,可在 [.filename]#/etc/rc.conf# 指定去掉 [.filename]#.fnt# 字尾的字型名稱 _font_name_:

[.programlisting]
....
font8x16=font_name
font8x14=font_name
font8x8=font_name
....

鍵盤對應表 (Keymap) 及螢幕對應表 (Screenmap) 用可加入下行到 [.filename]#/etc/rc.conf# 來設定:

[.programlisting]
....
scrnmap=screenmap_name
keymap=keymap_name
keychange="fkey_number sequence"
....

要查看可用的螢幕對應表,可輸入 `ls /usr/shared/syscons/scrnmaps`。在設定螢幕對應表 _screenmap_name_ 時請去掉 [.filename]#.scm# 字尾。在 VGA Adapter 的字型字元矩陣擴充位元 8 到位元 9 時會需要使用螢幕對應表與相關的字型對應來解決,因此若螢幕字型使用位元 8 的欄位,字母會移出虛擬繪圖區 (Pseudographics area)。

要查看可用的鍵盤對應表,可輸入 `ls /usr/shared/syscons/keymaps`。在設定鍵盤對應表 _keymap_name_ 時請去掉 [.filename]#.kbd# 字尾。若要不重開機測試鍵盤對應用可使用 man:kbdmap[1]。

`keychange` 項目用在當功能鍵序列無法定義在鍵盤對應表時,可設定對應選擇終對機類型的功能鍵。

接下來,在 [.filename]#/etc/ttys# 為所有虛擬終端機項目設定正確的 Console 終端機類型。<<locale-charset>> 摘要了可用的終端機類型:

[[locale-charset]]
.已定義供特定字元集使用的終端機類型
[cols="1,1", frame="none", options="header"]
|===
| 字元集
| 終端機類型

|ISO8859-1 or ISO8859-15
|`cons25l1`

|ISO8859-2
|`cons25l2`

|ISO8859-7
|`cons25l7`

|KOI8-R
|`cons25r`

|KOI8-U
|`cons25u`

|CP437 (VGA 預設值)
|`cons25`

|US-ASCII
|`cons25w`
|===

對於使用寬字元或多位元組字元的語言,需從 Port 套件集安裝支援該語言的 Console。 可用的 Port 摘要在 <<locale-console>>。安裝完成之後,請參考 Port 的 [.filename]#pkg-message# 或操作手冊來取得設定及使用說明。

[[locale-console]]
.Port 套件集中可用的 Console
[cols="1,1", frame="none", options="header"]
|===
| 語言
| Port 位置

|繁體中文 (BIG-5)
|package:chinese/big5con[]

|中文/日文/韓文
|package:chinese/cce[]

|中文/日文/韓文
|package:chinese/zhcon[]

|日文
|package:chinese/kon2[]

|日文
|package:japanese/kon2-14dot[]

|日文
|package:japanese/kon2-16dot[]
|===

若在 [.filename]#/etc/rc.conf# 有開啟 moused,可能會需要額外的設定。預設 man:syscons[4] 驅動程式的滑鼠游標會佔用字元集 `0xd0`-`0xd3` 的範圍,若語言有使用到此範圍,可加入以下行到 [.filename]#/etc/rc.conf# 來移動游標的範圍:

[.programlisting]
....
mousechar_start=3
....

=== Xorg 設定

crossref:x11[x11,X Window 系統] 會說明如何安裝並設定 Xorg。當要設定 Xorg 在地化時,可從 FreeBSD Port 套件集中取得其他可用的字型及輸入法。應用程式特定的 i18n 設定像是字型與選單,可以在 [.filename]#~/.Xresources# 中調校且可允許使用者在圖型化應用程式選單檢視其所選擇的語言。

X 輸入法 (X Input Method, XIM) 協定是 Xorg 針對輸入非英語字元的標準。<<locale-xim>> 摘要了在 FreeBSD 套件集中可用的輸入法應用程式。也可使用其他如 Fcitx 及 Uim 應用程式。

[[locale-xim]]
.可用的輸入法
[cols="1,1", frame="none", options="header"]
|===
| 語言
| 輸入法

|中文
|package:chinese/gcin[]

|中文
|package:chinese/ibus-chewing[]

|中文
|package:chinese/ibus-pinyin[]

|中文
|package:chinese/oxim[]

|中文
|package:chinese/scim-fcitx[]

|中文
|package:chinese/scim-pinyin[]

|中文
|package:chinese/scim-tables[]

|日文
|package:japanese/ibus-anthy[]

|日文
|package:japanese/ibus-mozc[]

|日文
|package:japanese/ibus-skk[]

|日文
|package:japanese/im-ja[]

|日文
|package:japanese/kinput2[]

|日文
|package:japanese/scim-anthy[]

|日文
|package:japanese/scim-canna[]

|日文
|package:japanese/scim-honoka[]

|日文
|package:japanese/scim-honoka-plugin-romkan[]

|日文
|package:japanese/scim-honoka-plugin-wnn[]

|日文
|package:japanese/scim-prime[]

|日文
|package:japanese/scim-skk[]

|日文
|package:japanese/scim-tables[]

|日文
|package:japanese/scim-tomoe[]

|日文
|package:japanese/scim-uim[]

|日文
|package:japanese/skkinput[]

|日文
|package:japanese/skkinput3[]

|日文
|package:japanese/uim-anthy[]

|韓文
|package:korean/ibus-hangul[]

|韓文
|package:korean/imhangul[]

|韓文
|package:korean/nabi[]

|韓文
|package:korean/scim-hangul[]

|韓文
|package:korean/scim-tables[]

|越南文
|package:vietnamese/xvnkb[]

|越南文
|package:vietnamese/x-unikey[]
|===

[[l10n-compiling]]
== 尋找 i18n 應用程式

i18n 應用程式會使用 i18n 工具包做為程式庫開發。這讓開發人員可以寫一個簡單的檔案並翻譯顯示的選單及文字至各種語言。

https://www.FreeBSD.org/ports/[FreeBSD Port 套件集]中含有許多內建支援寬字元或多位元組字元的應用程式可支援各種語言。該類型的應用程式在名稱上會註明 `i18n` 以易於辨識。雖然如此,但不一定支援您所需要的語言。

有一部份應用程式可以使用指定的字元集來編譯。通常會在 Port 的 [.filename]#Makefile# 中設定,或者傳送參數給 configure。請參考各 FreeBSD Port 原始碼中的 i18n 說明文件以取得更多有關需要的設定值資訊或 Port 的 [.filename]#Makefile# 來了解在編譯時有那些可以使用的編譯選項。

[[lang-setup]]
== 特定語言的語系設定

This section provides configuration examples for localizing a FreeBSD system for the Russian language. It then provides some additional resources for localizing other languages.

[[ru-localize]]
=== 俄語 (KOI8-R 編碼)

This section shows the specific settings needed to localize a FreeBSD system for the Russian language. Refer to <<using-localization,Using Localization>> for a more complete description of each type of setting.

To set this locale for the login shell, add the following lines to each user's [.filename]#~/.login_conf#:

[.programlisting]
....
me:My Account:\
	:charset=KOI8-R:\
	:lang=ru_RU.KOI8-R:
....

To configure the console, add the following lines to [.filename]#/etc/rc.conf#:

[.programlisting]
....
keymap="ru.utf-8"
scrnmap="utf-82cp866"
font8x16="cp866b-8x16"
font8x14="cp866-8x14"
font8x8="cp866-8x8"
mousechar_start=3
....

For each `ttyv` entry in [.filename]#/etc/ttys#, use `cons25r` as the terminal type.

To configure printing, a special output filter is needed to convert from KOI8-R to CP866 since most printers with Russian characters come with hardware code page CP866. FreeBSD includes a default filter for this purpose, [.filename]#/usr/libexec/lpr/ru/koi2alt#. To use this filter, add this entry to [.filename]#/etc/printcap#:

[.programlisting]
....
lp|Russian local line printer:\
	:sh:of=/usr/libexec/lpr/ru/koi2alt:\
	:lp=/dev/lpt0:sd=/var/spool/output/lpd:lf=/var/log/lpd-errs:
....

Refer to man:printcap[5] for a more detailed explanation.

To configure support for Russian filenames in mounted MS-DOS(TM) file systems, include `-L` and the locale name when adding an entry to [.filename]#/etc/fstab#:

[.programlisting]
....
/dev/ad0s2      /dos/c  msdos   rw,-Lru_RU.KOI8-R 0 0
....

Refer to man:mount_msdosfs[8] for more details.

To configure Russian fonts for Xorg, install the package:x11-fonts/xorg-fonts-cyrillic[] package. Then, check the `"Files"` section in [.filename]#/etc/X11/xorg.conf#. The following line must be added _before_ any other `FontPath` entries:

[.programlisting]
....
FontPath   "/usr/local/lib/X11/fonts/cyrillic"
....

Additional Cyrillic fonts are available in the Ports Collection.

To activate a Russian keyboard, add the following to the `"Keyboard"` section of [.filename]#/etc/xorg.conf#:

[.programlisting]
....
Option "XkbLayout"   "us,ru"
Option "XkbOptions"  "grp:toggle"
....

Make sure that `XkbDisable` is commented out in that file.

For `grp:toggle` use kbd:[Right Alt], for `grp:ctrl_shift_toggle` use kbd:[Ctrl+Shift]. For `grp:caps_toggle` use kbd:[CapsLock]. The old kbd:[CapsLock] function is still available in LAT mode only using kbd:[Shift+CapsLock]. `grp:caps_toggle` does not work in Xorg for some unknown reason.

If the keyboard has "Windows(TM)" keys, and some non-alphabetical keys are mapped incorrectly, add the following line to [.filename]#/etc/xorg.conf#:

[.programlisting]
....
Option "XkbVariant" ",winkeys"
....

[NOTE]
====
The Russian XKB keyboard may not work with non-localized applications. Minimally localized applications should call a `XtSetLanguageProc (NULL, NULL, NULL);` function early in the program.
====

See http://koi8.pp.ru/xwin.html[http://koi8.pp.ru/xwin.html] for more instructions on localizing Xorg applications. For more general information about KOI8-R encoding, refer to http://koi8.pp.ru/[http://koi8.pp.ru/].

=== 其他特定語言資源

This section lists some additional resources for configuring other locales.

Traditional Chinese for Taiwan::
The FreeBSD-Taiwan Project has a Chinese HOWTO for FreeBSD at http://netlab.cse.yzu.edu.tw/\~statue/freebsd/zh-tut/[http://netlab.cse.yzu.edu.tw/~statue/freebsd/zh-tut/].

Greek Language Localization::
A complete article on Greek support in FreeBSD is available https://www.FreeBSD.org/doc/el/articles/greek-language-support/[here], in Greek only, as part of the official FreeBSD Greek documentation.

Japanese and Korean Language Localization::
For Japanese, refer to http://www.jp.FreeBSD.org/[http://www.jp.FreeBSD.org/], and for Korean, refer to http://www.kr.FreeBSD.org/[http://www.kr.FreeBSD.org/].

Non-English FreeBSD Documentation::
Some FreeBSD contributors have translated parts of the FreeBSD documentation to other languages. They are available through links on the https://www.FreeBSD.org/[FreeBSD web site] or in [.filename]#/usr/shared/doc#.