で設定する必要がある静的文字列を処理する C++ の標準または一般的な方法はありgettext()
ますか?
これは、完全な C++ i18n gettext() “hello world”の例への回答をベースとして、リテラルhello world
を静的なchar* hws
andに変更するだけの例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