找回密码
 注册
查看: 1648|回复: 0

gettext实现shell脚本国际化

[复制链接]
发表于 2008-8-1 15:01:35 | 显示全部楼层 |阅读模式
$ 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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2025-2-6 00:59 , Processed in 0.048930 second(s), 15 queries .

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表