【发布时间】:2009-07-11 22:17:19
【问题描述】:
C++ 中是否有标准或通用的方法来处理需要由gettext() 设置的静态字符串?
这是一个使用Complete C++ i18n gettext() “hello world” example 的答案作为基础的示例,只需将文字hello world 更改为静态char* hws 和char* hw。
看起来hws 在从
本地操作系统环境。在更改语言环境后设置 hw 从而生成西班牙语文本。
cat >hellostaticgt.cxx <<EOF
// hellostaticgt.cxx
#include <libintl.h>
#include <locale.h>
#include <iostream>
char* hws = gettext("hello, world static!");
int main (){
setlocale(LC_ALL, "");
bindtextdomain("hellostaticgt", ".");
textdomain( "hellostaticgt");
char* hw = gettext("hello, world!");
std::cout << hws << std::endl;
std::cout << hw << std::endl;
}
EOF
g++ -o hellostaticgt hellostaticgt.cxx
xgettext --package-name hellostaticgt --package-version 1.0 --default-domain hellostaticgt --output hellostaticgt.pot hellostaticgt.cxx
msginit --no-translator --locale es_MX --output-file hellostaticgt_spanish.po --input hellostaticgt.pot
sed --in-place hellostaticgt_spanish.po --expression='/#: /,$ s/""/"hola mundo"/'
mkdir --parents ./es_MX.utf8/LC_MESSAGES
msgfmt --check --verbose --output-file ./es_MX.utf8/LC_MESSAGES/hellostaticgt.mo hellostaticgt_spanish.po
LANGUAGE=es_MX.utf8 ./hellostaticgt
【问题讨论】:
标签: c++ linux internationalization gettext