[转]用gettext实现shell脚本国际化

[ 文章作者:钟艺东 最后修改:2009年9月15日 ]
[ 文章链接:http://www.g868.com/change-shell-script-to-use-gettext-to-achieve-international.html ]

shell脚本也可以用gettext实现国际化. .很简单很强大.. 看下面的例子...

$ 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

2009年9月15日

发表评论

XHTML: 您可以使用这些标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">