BOoRFGOnZ 发表于 2008-8-1 15:01:35

gettext实现shell脚本国际化

$ cat test.sh
#!/bin/bash
export TEXTDOMAINDIR=/usr/share/locale
export TEXTDOMAIN=test.sh
echo "$(gettext -s hello)"

编辑一个po文件:
$ cat test.sh.po
msgid "hello"
msgstr "你好!"

编译成mo文件:
$msgfmt -o test.sh.mo test.sh.po

复制到/usr/share/locale/zh_CN/LC_MESSAGES/
$cp test.sh.mo /usr/share/locale/zh_CN/LC_MESSAGES/

中文:
$ export LANG=zh_CN.UTF-8
$ ./test.sh
你好!

英文:
$ export LANG=en_US.UTF-8
$ ./test.sh
hello
页: [1]
查看完整版本: gettext实现shell脚本国际化