2005年3月14日星期一

用Knoppix Live Installer添加中文支持(I)

去年初琢磨过怎么对Knoppix进行remaster以添加中文支持,但这个remaster做起来实在是费劲,尤其是压缩cloop映象一节。所以后来一直就想利用Knoppix可以保存$HOME这一点来定做一个$HOME映像,大家只要下载这个映像,启动时添加home=/dev/hda?就可以了。

Knoppix Live Installer(前次的介绍)这种方式比我原来设想的似乎要更高级一点,方便一点,于是就用这种方式来试验了一下。

中文支持主要是环境配置、中文字体、中文message catalog和中文输入法。
arphic字体包和KDE的中文i18n很容易就搞定了,但中文输入法就不太顺利。

安装字体字体

安装字体我们要做的是:
1. 用apt下载当前的ttf-arphic-gbsn00lp等字体包
2. 将包解开,将ttf字体安装到~/.fonts
3. 用fc-cache生成~/.fonts
4. 注册defoma hints
前三步很容易完成:
modules/ttf-arphic-gbsn00lp/description
"'AR PL SungtiL GB' Chinese TrueType font by Arphic Technology"
modules/ttf-arphic-gbsn00lp/files:
# basename location_to_download type md5sum
ttf-arphic-gbsn00lp none apt none
modules/ttf-arphic-gbsn00lp/install.sh:
#!/bin/bash
[ ! -d $HOME/.fonts ] && mkdir $HOME/.fonts
# copy fonts
cp -a ttf-arphic-gbsn00lp/usr/share/fonts/truetype/arphic/*.ttf $HOME/.fonts

# generate font cache
fc-cache $HOME/.fonts

mkfontscale $HOME/.fonts
cp -f $HOME/.fonts/fonts.scale $HOME/.fonts/fonts.dir
xset +fp $HOME/.fonts

麻烦的是注册hints这一步需要root权限,而且不一定能够执行(因为在Knoppix光盘上运行,大部分目录都是只读的)
好在这一步不做问题也不大。

但我还是试验了一下,似乎也可以:
(添加到install.sh):
# register defoma hints
fontsdir=$HOME/.fonts
hintfile=/etc/defoma/hints/ttf-arphic-gbsn00lp.hints
sed 's#/usr/share/fonts/truetype/arphic/gbsn00lp.ttf#$fontsdir/gbsn00lp.ttf#'
ttf-arphic-gbsn00lp$hintfile > $hintfile
sudo /usr/bin/defoma-font -t reregister-all $hintfile
注意这里对/etc目录下的配置做了改动,除非用saveconfig将配置保存下来并且下次启动时加上myconfig=...选项,否则它们不会起作用

中文message catalog

其他软件的各种语言mo都是一起安装的,所以没有什么问题,不需要再做什么。唯独KDE是例外,需要另外安装一个中文语言包kde-i18n-zhcn。

这里存在的另一个问题就是这些翻译包都要放到/usr/share/locale/下面去的,但Knoppix从光盘上运行,/usr是只读的,怎么办?

好在现在的Linux内核都支持文件系统的bind(就是将一个目录映射为另外一个目录),我们只要这样就可以了
mount --bind $mydir /usr/share/locale/zh_CN
mydir是新建立的存放message catalog的地方,kde-i18n-zhcn中的mo文件解压后就放在这里
注意映射之前需要先将原来/usr/share/locale/zh_CN拷贝到新目录,否则就只有kde的翻译了

modules/kde-i18n-zhcn/description
"Chinese Simplified (zh_CN) internationalized (i18n) files for KDE"
modules/kde-i18n-zhcn/files
# basename location_to_download type md5sum
kde-i18n-zhcn none apt none
modules/kde-i18n-zhcn/install.sh
[ ! -d $DESTDIR/usr/share/locale/zh_CN ] && mkdir -p $DESTDIR/usr/share/locale/zh_CN
# copy message catalogs
mv kde-i18n-zhcn/usr/share/locale/zh_CN/* $DESTDIR/usr/share/locale/zh_CN/
# copy other translations to new folder
# WARNING: you should have enough spaces for storing all this
cp -a /usr/share/locale/zh_CN/* $DESTDIR/usr/share/locale/zh_CN/

# rebind /usr/share/locale/zh_CN/
sudo mount --bind $DESTDIR/usr/share/locale/zh_CN/ /usr/share/locale/zh_CN/

这里还需要解决一个问题: 执行上述mount之后再从KDE的Control Center或者Configuration Wizard选择"简体中文"当然没有问题。但下次重启动呢?如何让系统启动时自动执行上面的mount? 这一步必须在/home加载后,KDE启动之前完成,时机很是问题。

考虑到非KDE桌面下用这个特性的可能性比较小,所以我选择了用KDE的Autostart特性来做这一步
(添加到install.sh:)
cat < $HOME/.kde/Autostart/knx-clx-rebind.sh
[Desktop Entry]
Name=kde-i18n-zhcn
Exec=sudo mount --bind $DESTDIR/usr/share/locale/zh_CN/ /usr/share/locale/zh_CN/
Type=Application
Icon=message
Terminal=0
EOF
但这样是否切实可能,还要进一步验证。


中 文输入法我打算用比较熟悉的fcitx来做,但这里有一个障碍: fcitx需要读取/usr/share/fcitx目录下的数据文件,系统并没有先建立一个/usr/share/fcitx供我们mount --bind,而我们也不能象前面那样映射整个/usr/share. 我现在看到一个解决办法,但是否可行,明天试验了才能知道。

没有评论: