用gettext实现shell脚本国际化.

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
yaska
帖子: 1169
注册时间: 2007-10-28 21:35

用gettext实现shell脚本国际化.

#1

帖子 yaska » 2008-02-18 19:46

不知道有没有人发过.
相信很多同志翻译过程序的zh_CN.po
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
头像
windwiny
帖子: 2254
注册时间: 2007-03-13 17:26

#2

帖子 windwiny » 2008-02-18 22:39

噢,这样也行
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#3

帖子 bones7456 » 2008-02-19 12:59

有点意思,加个精华,嘿嘿.
关注我的blog: ε==3
头像
yaska
帖子: 1169
注册时间: 2007-10-28 21:35

#4

帖子 yaska » 2008-02-19 16:13

bones7456 写了:有点意思,加个精华,嘿嘿.
哈.,让多人看到....
谁用德语,法语什么的, 贴上来看看..
回复