QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2091|回复: 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, 2024-4-17 04:56 , Processed in 0.062710 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

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