【发布时间】:2013-10-21 09:11:47
【问题描述】:
我正在尝试以本地语言打印“hello world”程序并且我成功执行了...但是现在我正在尝试通过输入 hello world @run time 来做同样的事情...这可能吗?如何? 我遵循了以下代码示例...
cat >hellogt.cxx <<EOF
// hellogt.cxx
#include <libintl.h>
#include <locale.h>
#include <iostream>
#include <cstdlib>
int main (){
char* cwd = getenv("PWD");
std::cout << "getenv(PWD): " << (cwd?cwd:"NULL") << std::endl;
char* l = getenv("LANG");
std::cout << "getenv(LANG): " << (l?l:"NULL") << std::endl;
char* s = setlocale(LC_ALL, "");
std::cout << "setlocale(): " << (s?s:"NULL") << std::endl;
std::cout << "bindtextdomain(): " << bindtextdomain("hellogt", cwd) << std::endl;
std::cout << "textdomain(): " << textdomain( "hellogt") << std::endl;
std::cout << gettext("hello, world!") << std::endl;
}
EOF
g++ -ohellogt hellogt.cxx
xgettext -d hellogt -o hellogt.pot hellogt.cxx
msginit --no-translator -l es_MX -o hellogt_spanish.po -i hellogt.pot
sed --in-place hellogt_spanish.po --expression='/#: /,$ s/""/"hola mundo"/'
sed --in-place hellogt_spanish.po --expression='s/PACKAGE VERSION/hellogt 1.0/'
mkdir -p ./es_MX/LC_MESSAGES
msgfmt -c -v -o ./es_MX/LC_MESSAGES/hellogt.mo hellogt_spanish.po
export LANG=es_MX
ls -l $PWD/es_MX/LC_MESSAGES/hellogt.mo
./hellogt
strace -e trace=open ./hellogt
【问题讨论】:
-
到目前为止,您尝试了什么?它是如何工作的?它是如何没有工作的?
-
我正在打印所需语言所需的所有消息,但我是手动执行的,我的意思是...您可以在其中观察到 hola mundo 是 hello world 的等效西班牙语句子,它是在外部生成的从 poedit ......我想在 @runtime 上做这个......
标签: c++ internationalization g++ locale gettext