1
嗨,我正在編寫i18n在c + +中的示例代碼。我參考了以下link。如何跟蹤C++ GNU xgettex執行?
輸出顯示英文文本。這裏有什麼問題?
#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;
}
$>克++ -o啓動start.cpp
$> -d了xgettext開始-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
$> ./start