i18n_tool-7
-----------
This package includes a zh_TW.Big5 and a zh_CN.GB2312 locale data, and
a fixed lcGen module. These can help to you establish the needed locale
environment in GNU/Linux system.
Please note that the locale data provided by this package is only valid
for glibc-2.1.X version, where X could be 1 or 2 or 3, but is NOT valid
for other versions.
Also, the description of this article is valid for glibc-2.1.X/2.2, and
XFree86-3.3.5/3.3.6/4.0.X and above. For the early versions like
glibc-2.0.7 and XFree86-3.3.4 or even earlier, this is not suitable.
Therefore, if your system is still using the early versions of the
software, we strongly suggest that you have to upgrade them. It is better
to upgrade them to glibc-2.1.3 and XFree86-3.3.6 or above. If you insist
to use these early versions, then you could refer to "README.old.En" doc
to establish the locale environment with some limitations.
Therefore, before you going on, please make sure the versions of your
system software.
A. Make sure the versions of the system software:
--------------------------------------------------
You have to make sure the versions of glibc and XFree86, via the following
methods:
1. glibc:
ls -l /lib/libc*
If there is a "libc-2.1.3.so" listed, and a symbolic link "/lib/libc.so.6"
points to "libc-2.1.3.so", then it means your system are using the
glibc-2.1.3. For the other versions the method is the same. Please note
that if the filename is "libc-2.1.9X.so", then it should refer to the
under-development and testing version of glibc-2.2. It is very different
to glibc-2.1.X and should be treated as glibc-2.2.
2. XFree86:
xterm -h
This command will list a lot of usage descriptions of xterm, and inside
them there will be the version number of XFree86.
If your system software is glibc-2.1.X or above, and XFree86-3.3.5 or above,
then please continue of reading, otherwise it is suggested to upgrate them.
B. Which locale you need?
--------------------------
In this package the installation methods of 2 locales are provided, and the
locale data for glibc-2.1.X is also provided. In fact, no matter what kinds
of locale, the installation steps are exactly the same. Hence if the locale
you want to install is not listed in this article, as long as you could get
the locale data files (including a locale input file and its corresponding
charmap file, see below for details), then you could install them through
the same steps as described here.
The locales described in this article are zh_TW.Big5 and zh_CN.GB2312, where
the former is for the users in Taiwan who are using Big5 character set; while
the later is for the users in Mainland China who are using GB2312 character
set. Therefore, you can choose one of them to install, or just install both
of them.
C. glibc locale:
-----------------
Here we should discuss the cases for glibc-2.1.X and glibc-2.2 (including
glibc-2.1.9X) respectively:
a. glibc-2.1.X:
---------------
1. Please make sure that your system already contains the locale you want
(zh_TW.Big5 or zh_CN.GB2312) or not. If they are already there, then
you don't have to install them. There are 2 ways to check:
1) Run the command "locale -a" and see if there is zh_TW.Big5 or
zh_CN.GB2312 printed? If yes, it means they are already there.
2) In this version of glibc, all the locale data are stored in
/usr/share/locale directory. So go to there and see if the directories
zh_TW.Big5 or zh_TW.GB2312 could be found or not? And in these
directories they should contain the LC_CTYPE files respectively.
If yes, it means the locales are already there.
Please note that if in your system the character case of the locale name
is not exactly the same as mentioned, e.g., zh_TW.big5 or zh_CN.gb2312,
then you have to change them to be the same cases. The way to change
is renaming the directory name in /usr/share/locale. For example:
mv /usr/share/locale/zh_TW.big5 /usr/share/locale/zh_TW.Big5
2. If in your system the locale you need is not installed (e.g., zh_TW.Big5),
then go to the directory i18n_tool/localedata/zh_TW.Big5/ of this package
and excute:
localedef -i zh_TW -f BIG5_1984 -u mnemonic.ds zh_TW.Big5
where "zh_TW" is the locale input file, and "BIG5_1984" is the charmap
file. They both are provided by this package. The "mnemonic.ds" file is
the repertoiremaps file, which should be found in your system: in the
/usr/share/i18n/repertoiremaps/ directory. If not, you have to install
it through the installation guide of your GNU/Linux distribution. The
package name is something like "i18n_data". And finally the "zh_TW.Big5"
is the locale name we want.
When completed, there will be a zh_TW.big5 directory in /usr/share/locale/
directory. But in the convention of CLE, the locale name is zh_TW.Big5,
and in this article we will follow this convention. So we should change
the directory name "zh_TW.big5" into "zh_TW.Big5".
For zh_CN.GB2312 locale, the installation steps are the same. Please go
to the i18n_tool/localedata/zh_CN.GB2312/ directory of this package and
excute:
localedef -i zh_CN -f GB2312 -u mnemonic.ds zh_CN.GB2312
where, similarly, "zh_CN" is the locale input file, and "GB2312" is the
charmap file. When completed, please also change the directory name
zh_CN.gb2312 to zh_CN.GB2312 in the directory /usr/share/locale.
3. If you are installing zh_CN.GB2312 locale, please check the contents of
/usr/lib/gconv/gconv-modules and search for the word "EUC-CN". Probably
in line 880, you will see the following contents:
# from to module cost
alias EUCCN// EUC-CN//
alias GB2312// EUC-CN//
module EUC-CN// INTERNAL EUC-CN 1
module INTERNAL EUC-CN// EUC-CN 1
Please note the line 3 above: "alias GB2312// EUC-CN//". If in your
file there does not have this line, please add it by yourself.
b. glibc-2.1.9X and glibc-2.2:
------------------------------
Glibc-2.1.9X is the under-development and testing version of glibc-2.2.
Please note that this series of glibc has major changes in I18N and locale
archetecture, and also it is still under very fast development. Therefore,
the locale installation methods might be changed slowly with time. However,
in this series all the locales of Asian languages, e.g., zh_TW.Big5 or
zh_CN.GB2312, are supported directly, so we don't have to install more
other packages or files. We only have to do a little modification (or even
no modifications are needed) for our locale facilities.
We have to note that the locale name we traditionally used is changed inside
glibc-2.2. For example, the "zh_TW.Big5" locale is named as "zh_TW" internally;
while the "zh_CN.GB2312" locale is named as "zh_CN" internally. One goal which
glibc-2.2 wants to accomplish is, no matter what the internal locale name is,
we could still use our traditional locale name in applications, i.e., the
zh_TW.Big5 and zh_CN.GB2312.
In the following the installation / modifications are described:
1. The first, please check that if in your system the suitable locale data is
installed or not? You can use this command to check:
locale -a
to see if there is "zh_TW" or "zh_CN" listed in the output? where the
"zh_TW" stands for "zh_TW.Big5"; while the "zh_CN" stands for "zh_CN.GB2312".
If yes, then you can skip this step, otherwise you can generate them using
the following methdos. Please check if the directory
/usr/share/i18n/
exists or not? In that directory there should have locales/ and charmaps/
sub-directories. If it is not found, then it is probably that you don't
install the i18n_data package (or something like that) provided by glibc-2.2.
Please install it. And then, excute the following commands:
localedef -i zh_TW -f BIG5 zh_TW
localedef -i zh_CN -f GB2312 zh_CN
Please note that you should use the locale input file and the charmap file
provided by glibc-2.2. The files provided in this package are invalid and
can not be used. The files could be found in locales/ and charmaps/
in /usr/share/i18n/ directory. By default you don't have to specify the
path of these files. localedef program will search them from the directories
mentioned above. When finished, there will be zh_TW/ and zh_CN/ directories
created in the /usr/lib/locale/ directory. These are the locale data we
need.
2. If your version of glibc is glibc-2.1.97 and above (including 2.1.97), then
up to now your locale environment is ready. If not, we suggest that it is
better to upgrade your glibc version to 2.1.97 or above. If you do not want
to do this, then you have to do further step:
cd /usr/lib/locale; ln -s zh_TW zh_TW.Big5
cd /usr/lib/locale; ln -s zh_CN zh_CN.GB2312
Again, we strongly suggestion that you should upgrade your glibc instead
of doing this symbolic link, because doing this is not natural and against
the standard.
3. Finally, we recommand to do this:
cd /usr/share/locale; ln -s zh_TW zh_TW.Big5
cd /usr/share/locale; ln -s zh_CN zh_CN.GB2312
This is because according to the standard, the translated messages of the
applications should be stored in
/usr/share/locale/zh_TW/LC_MESSAGES/
/usr/share/locale/zh_CN/LC_MESSAGES/
instead of in zh_TW.Big5/LC_MESSAGES/ or zh_CN/GB2312/LC_MESSAGES/. But
currently there are still many applications which do not obey this standard.
Hence we recommand to do this, such that the whole system could be more
standard compliant.
D. XFree86:
------------
The following descriptions are valid both for XFree86-3.3.5/3.3.6 or
XFree86-4.0/4.0.X.
a. zh_TW.Big5 locale:
---------------------
1. Please check the /usr/X11R6/lib/X11/locale/ directory to see if there
exists the zh_TW.Big5/ directory, and in that directory there is a file
named XLC_LOCALE. If not, please put the file of this package
i18n_tool/localedata/zh_TW.Big5/XLC_LOCALE into the directory
/usr/X11R6/lib/X11/locale/zh_TW.Big5
(you might need to create this directory).
2. If you are using XFree86-3.3.X, please check
/usr/X11R6/lib/X11/locale/locale.dir to see if the following line is there:
zh_TW.Big5/XLC_LOCALE zh_TW.Big5
If not, please add it by yourself. If you are using XFree86-4.0.X, please
check the same file to see if the following lines are there:
zh_TW.Big5/XLC_LOCALE: zh_TW.Big5
zh_TW.Big5/XLC_LOCALE: zh_TW.big5
zh_TW.Big5/XLC_LOCALE: zh_TW
If not, please add them. Please also note that the format of these lines
is different than that in XFree86-3.3.X: there is a colon character in
each line.
3. You have to prepare suitable Chinese (Big5) fonts. From the definition
of XLC_LOCALE in step 1, the font to display Chinese in zh_TW.Big5 locale
is named as BIG5-0. Therefore your system should have these fonts. Take my
system as an example, since I have installed the twmoe fonts (you can get
them from: ftp://linux.cis.nctu.edu.tw/packages/chinese ftp site), which
has the font name ended with "big5-1", so I have to alias these font names
to end with "big5-0":
$ xlsfonts | grep big5
-twmoe-kai-medium-r-normal--16-160-75-75-c-160-big5-1
-twmoe-kai-medium-r-normal--24-240-75-75-c-240-big5-1
-twmoe-kai-medium-r-normal-fs-16-160-75-75-c-160-big5-0
-twmoe-kai-medium-r-normal-fs-24-240-75-75-c-240-big5-0
$ more /usr/X11R6/lib/X11/fonts/chinese/fonts.alias
-twmoe-kai-medium-r-normal-fs-16-160-75-75-c-160-big5-0 -twmoe-kai-medium-r-normal--16-160-75-75-c-160-big5-1
-twmoe-kai-medium-r-normal-fs-24-240-75-75-c-240-big5-0 -twmoe-kai-medium-r-normal--24-240-75-75-c-240-big5-1
b. zh_CN.GB2312 locale:
-----------------------
1. The installation methods for zh_CN.GB2312 locale is very similar. For the
first you don't have to install the XLC_LOCALE file the GB encoding since
XFree86 already has one. But it is placed in
/usr/X11R6/lib/X11/locale/zh/
Therefore for XFree86-3.3.X systems, we have to modify the file locale.dir
to add this line:
zh/XLC_LOCALE zh_CN.GB2312
But for XFree86-4.0.X systems, we also have to modify the same file, but
please remember that the format is a little different. There should be
a colon character in the line, e.g.,
zh/XLC_LOCALE: zh_CN.GB2312
2. You should install the GB fonts, with the font names ended with
"GB2312.1980-0". You can try to find the GB font tar file in XFree86
packages, or search for them in the ftp sites.
E. Test your locale environment:
---------------------------------
In the following we provide a simple program for testing the locale environment.
=================================================================
#define USE_XOPEN_SOURCE
#include <stdio.h>
#include <locale.h>
#ifdef USE_XOPEN_SOURCE
# include <langinfo.h>
#endif
#include <X11/Xlib.h>
#include <X11/Xlocale.h>
main()
{
printf("LC_CTYPE = %s\n", setlocale(LC_CTYPE, ""));
#ifdef USE_XOPEN_SOURCE
printf("encoding = %s\n", nl_langinfo(CODESET));
#endif
if (XSupportsLocale() == True)
printf("X Locale = OK\n");
}
=================================================================
You could save this source code as localetest.c file, and compile it via
gcc localetest.c -I/usr/X11R6/include -L/usr/X11R6/lib -lX11
If you get errors when compilation, please remove the line
#define USE_XOPEN_SOURCE
and compile again. After that, you will get a file named "a.out". Then you
could do the following test:
LC_ALL=zh_TW.Big5 ./a.out
If the output is
LC_CTYPE = zh_TW.Big5
encoding = BIG5
X Locale = OK
then it means your locale environment is successfully installed (please note
that if you remove the "#define USE_XOPEN_SOURCE" line before compilation,
there will not be the "encoding = ...." line in the output). Similarly, for
zh_CN.GB2312 locale the testing result is:
command: LC_ALL=zh_CN.GB2312 ./a.out
LC_CTYPE = zh_CN.GB2312
encoding = GB2312
X Locale = OK
Please note, if in your system there is a zh_CN.GB2312 locale originally, but
the testing result is
LC_CTYPE = zh_CN.GB2312
encoding = GB2312-1980
X Locale = OK
then it is suggested to reinstall the zh_CN.GB2312 locale. Please refer to
the description in section C.
F. Run I18N applications --- setting locale:
----------------------------------------------
If your system is I18N and locale environment ready, then you have to set
locale before running any I18N applications, as described in the following
(here we take zh_TW.Big5 locale for example, and the method for zh_CN.GB2312
is exactly the same):
Set the environment variable: You could set the following 3 kinds of the
environment variables (using bash as the example):
(1) export LANG=zh_TW.Big5
(2) export LC_CTYPE=zh_TW.Big5
(3) export LC_ALL=zh_TW.Big5
where "LANG" will set the whole system environment to be zh_TW.Big5 locale,
and "LC_CTYPE" will set the character processing category to be zh_TW.Big5
locale, and "LC_ALL" will set all the locale categories to be zh_TW.Big5
locale. You could choose one of them, but please note that the piority of
them is
(1) < (2) < (3)
In other words, if (1) and (2) is set simultaneously but with differnt values,
the system will use the setting of (2). Similarly if (3) is set, then system
will only use the setting of it. You can use the command "locale" to see the
current locale setting. For example:
$ locale
LANG=POSIX
LC_CTYPE=zh_TW.Big5
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_ALL=
Here we can see that beside LC_CTYPE category, which is zh_TW.Big5, all the
other categories are the default value: "POSIX". For the meaning of each
categories, please refer to "man 3 setlocale".
No matter what, when we want to run the I18N applications, at least the
LC_CTYPE category should be set to the locale we want to use. If we also
want the message output of the I18N applications to be Chinese, then we
could also set LC_MESSAGES category to be zh_TW.Big5:
export LC_MESSAGES=zh_TW.Big5
After all these settings, we can start to run the I18N applications.
Author: Tung-Han Hsieh
Email: thhsieh@linux.org.tw