【发布时间】:2016-07-27 08:05:20
【问题描述】:
您好,我正在用 c++ 编写 i18n 的示例代码。我引用了以下link。
输出以英文显示文本。这里有什么问题?
#include "start.hpp"
#include <iostream>
#include <locale.h>
#include "/opt/local/share/gettext/gettext.h"
using namespace std;
int main(int argc, char *argv[]){
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("hello", cwd) << std::endl;
std::cout << "textdomain(): " << textdomain( "hello") << std::endl;
std::cout << gettext("hello, world!") << std::endl;
return 0;
}
$> g++ -o start start.cpp
$> xgettext -d start -o start.pot start.cpp
$> msginit --no-translator -l es_MX -o start_es.po -i start.pot
已创建 start_es.po。
我使用 poedit.app 打开了 start_es.po 文件并翻译了文本并保存了
$> mkdir -p es/LC_MESSAGES
$> msgfmt -c -v -o ./es/LC_MESSAGES/start.mo start_es.po
1 条已翻译的消息。
$>导出 LANG=es_MX
$> ./开始
【问题讨论】:
标签: c++ internationalization gettext