I18N 和 L10N 並非 FreeBSD 所特有的,而是共通的遊戲規則。 我們鼓勵你在 FreeBSD 世界中同樣遵守這項遊戲規則。
Locale 設定由三個部分所組成:語言代碼(Language Code)、國碼(Country Code)、編碼(Encoding)。 所以,Locale 的設定名稱就是由這三個一起組成:
語言代碼
_國碼
.編碼
使用者必須要先知道這些特定的國碼、語言代碼(國碼會告訴應用程式該使用哪一種語言), 才能讓 FreeBSD 或其他支援 I18N 的 UNIX® 類系統作 locale 相關設定。 此外,網頁瀏覽器(borwser)、SMTP/POP 主機、Web 主機等也都以這架構為主。 下面是如何使用『語言代碼、國碼』的例子:
語言代碼/國碼 | 簡介 |
---|---|
en_US | 英文(美國) |
ru_RU | 俄文(俄國) |
zh_TW | 正體中文(台灣) |
有些語言並非採用 ASCII 編碼,可能是: 8-bit、wide 或 multibyte 字元,詳情請參閱 multibyte(3)。 較古早的程式可能無法正確判別、或誤判為特殊控制字元。而較新的程式都可以辨認 8-bit 字元。 由於各程式的作法不一,使用者可能需要在編譯程式時,加上 wide 或 multibyte 字元的支援設定,或是正確調整才行。 要輸入、處理 wide 或 multibyte 字元的話,可多多利用 FreeBSD Ports Collection 內有各國語言版本的程式。 詳情請參閱 FreeBSD 各 port 中的 I18N 相關文件。
Specifically, the user needs to look at the application documentation to decide on how to configure it correctly or to pass correct values into the configure/Makefile/compiler.
Some things to keep in mind are:
Language specific single C chars character sets (see multibyte(3)), e.g. ISO8859-1, ISO8859-15, KOI8-R, CP437.
Wide or multibyte encodings, e.g. EUC, Big5.
You can check the active list of character sets at the IANA Registry.
FreeBSD use X11-compatible locale encodings instead.
In the FreeBSD Ports and Package system, I18N applications
have been named with I18N
in their names for
easy identification. However, they do not always support the
language needed.
Usually it is sufficient to export the value of the locale name
as LANG
in the login shell. This could be done in
the user's ~/.login_conf
file or in the
startup file of the user's shell (~/.profile
,
~/.bashrc
, ~/.cshrc
).
There is no need to set the locale subsets such as
LC_CTYPE
, LC_CTIME
. Please
refer to language-specific FreeBSD documentation for more
information.
You should set the following two environment variables in your configuration files:
LANG
for POSIX® setlocale(3) family
functions
This includes the user shell configuration, the specific application configuration, and the X11 configuration.
There are two methods for setting locale, and both are described below. The first (recommended one) is by assigning the environment variables in login class, and the second is by adding the environment variable assignments to the system's shell startup file.
This method allows environment variables needed for locale name and MIME character sets to be assigned once for every possible shell instead of adding specific shell assignments to each shell's startup file. User Level Setup can be done by an user himself and Administrator Level Setup require superuser privileges.
Here is a minimal example of a
.login_conf
file in user's home
directory which has both variables set for Latin-1
encoding:
me:\ :charset=ISO-8859-1:\ :lang=de_DE.ISO8859-1:
Here is an example of a
.login_conf
that sets the variables
for Traditional Chinese in BIG-5 encoding. Notice the many
more variables set because some software does not respect
locale variables correctly for Chinese, Japanese, and Korean.
#Users who do not wish to use monetary units or time formats #of Taiwan can manually change each variable me:\ :lang=zh_TW.Big5:\ :lc_all=zh_TW.Big:\ :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=xcin": #Setting the XIM Input Server
See Administrator Level Setup and login.conf(5) for more details.
Verify that the user's login class in
/etc/login.conf
sets the correct
language. Make sure these settings
appear in /etc/login.conf
:
language_name
:accounts_title
:\ :charset=MIME_charset
:\ :lang=locale_name
:\ :tc=default:
So sticking with our previous example using Latin-1, it would look like this:
german:German Users Accounts:\ :charset=ISO-8859-1:\ :lang=de_DE.ISO8859-1:\ :tc=default:
Before changing users Login Classes execute the following command
#
cap_mkdb /etc/login.conf
to make new configuration in
/etc/login.conf
visible to the system.
Use vipw
to add new users, and make
the entry look like this:
user:password:1111:11:language
:0:0:User Name:/home/user:/bin/sh
Use adduser
to add new users, and do
the following:
Set defaultclass =
language
in
/etc/adduser.conf
. Keep in mind
you must enter a default
class for
all users of other languages in this case.
An alternative variant is answering the specified language each time that
Enter login class: default []:
appears from adduser(8).
Another alternative is to use the following for each user of a different language that you wish to add:
#
adduser -class language
If you use pw(8) for adding new users, call it in this form:
#
pw useradd user_name -L language
This method is not recommended because it requires a different setup for each possible shell program chosen. Use the Login Class Method instead.
To add the locale name and MIME character set, just set
the two environment variables shown below in the
/etc/profile
and/or
/etc/csh.login
shell startup files. We
will use the German language as an example below:
In /etc/profile
:
LANG=de_DE.ISO8859-1; export LANG
MM_CHARSET=ISO-8859-1; export MM_CHARSET
Or in /etc/csh.login
:
setenv LANG de_DE.ISO8859-1
setenv MM_CHARSET ISO-8859-1
Alternatively, you can add the above instructions to
/usr/share/skel/dot.profile
(similar to
what was used in /etc/profile
above), or
/usr/share/skel/dot.login
(similar to
what was used in /etc/csh.login
above).
For X11:
In $HOME/.xinitrc
:
LANG=de_DE.ISO8859-1; export LANG
Or:
setenv LANG de_DE.ISO8859-1
Depending on your shell (see above).
For all single C chars character sets, set the correct
console fonts in /etc/rc.conf
for the
language in question with:
font8x16=font_name
font8x14=font_name
font8x8=font_name
The font_name
here is taken from
the /usr/share/syscons/fonts
directory,
without the .fnt
suffix.
Also be sure to set the correct keymap and screenmap for your
single C chars character set through
sysinstall
(/stand/sysinstall
in FreeBSD versions older than 5.2).
Once inside sysinstall, choose , then
. Alternatively, you can add the
following to /etc/rc.conf
:
scrnmap=screenmap_name
keymap=keymap_name
keychange="fkey_number sequence
"
The screenmap_name
here is taken
from the /usr/share/syscons/scrnmaps
directory, without the .scm
suffix. A
screenmap with a corresponding mapped font is usually needed as a
workaround for expanding bit 8 to bit 9 on a VGA adapter's font
character matrix in pseudographics area, i.e., to move letters out
of that area if screen font uses a bit 8 column.
If you have the moused daemon
enabled by setting the following
in your /etc/rc.conf
:
moused_enable="YES"
then examine the mouse cursor information in the next paragraph.
By default the mouse cursor of the syscons(4) driver occupies the
0xd0-0xd3 range in the character set. If your language uses this
range, you need to move the cursor's range outside of it. To enable
the workaround for FreeBSD, add the following line to
/etc/rc.conf
:
mousechar_start=3
The keymap_name
here is taken from
the /usr/share/syscons/keymaps
directory,
without the .kbd
suffix. If you are
uncertain which keymap to use, you use can kbdmap(1) to test
keymaps without rebooting.
The keychange
is usually needed to program
function keys to match the selected terminal type because
function key sequences cannot be defined in the key map.
Also be sure to set the correct console terminal type in
/etc/ttys
for all ttyv*
entries. Current pre-defined correspondences are:
Character Set | Terminal Type |
---|---|
ISO8859-1 or ISO8859-15 | cons25l1 |
ISO8859-2 | cons25l2 |
ISO8859-7 | cons25l7 |
KOI8-R | cons25r |
KOI8-U | cons25u |
CP437 (VGA default) | cons25 |
US-ASCII | cons25w |
For wide or multibyte characters languages, use the correct
FreeBSD port in your
/usr/ports/language
directory. Some ports appear as console while the system sees it
as serial vtty's, hence you must reserve enough vtty's for both
X11 and the pseudo-serial console. Here is a partial list of
applications for using other languages in console:
Language | Location |
---|---|
Traditional Chinese (BIG-5) | chinese/big5con |
Japanese | japanese/kon2-16dot or japanese/mule-freewnn |
Korean | korean/han |
Although X11 is not part of the FreeBSD Project, we have included some information here for FreeBSD users. For more details, refer to the Xorg web site or whichever X11 Server you use.
In ~/.Xresources
, you can additionally
tune application specific I18N settings (e.g., fonts, menus,
etc.).
Install Xorg server (x11-servers/xorg-server) or XFree86™ server (x11-servers/XFree86-4-Server), then install the language TrueType® fonts. Setting the correct locale should allow you to view your selected language in menus and such.
Some single C chars character sets are usually hardware coded into printers. Wide or multibyte character sets require special setup and we recommend using apsfilter. You may also convert the document to PostScript® or PDF formats using language specific converters.
The FreeBSD fast filesystem (FFS) is 8-bit clean, so it can be used with any single C chars character set (see multibyte(3)), but there is no character set name stored in the filesystem; i.e., it is raw 8-bit and does not know anything about encoding order. Officially, FFS does not support any form of wide or multibyte character sets yet. However, some wide or multibyte character sets have independent patches for FFS enabling such support. They are only temporary unportable solutions or hacks and we have decided to not include them in the source tree. Refer to respective languages' web sites for more information and the patch files.
The FreeBSD MS-DOS® filesystem has the configurable ability to convert between MS-DOS®, Unicode character sets and chosen FreeBSD filesystem character sets. See mount_msdos(8) for details.
All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/
Questions that are not answered by the
documentation may be
sent to <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.