Wikipedia entry for GNU gettextは、ロケールが単に翻訳である例 "fr"を示しています。 i18n gettext() “hello world” exampleは言語と国の両方でロケール値を持っていますが、 "es_MX
"です。私は "es_MX
"の例を変更して "es"という訳を使用しましたが、予想されるスペイン語ではなく英語のテキストを生成します。 Controlling your locale with environment variablesによるとなぜロケールes_MXは動作しますが、esは動作しませんか?
cat >hellogt.cxx <<EOF
// hellogt.cxx
#include <libintl.h>
#include <locale.h>
#include <iostream>
int main(){
setlocale(LC_ALL, "");
bindtextdomain("hellogt", ".");
textdomain("hellogt");
std::cout << gettext("hello, world!") << std::endl;
}
EOF
g++ -o hellogt hellogt.cxx
xgettext --package-name hellogt --package-version 1.2 --default-domain hellogt --output hellogt.pot hellogt.cxx
msginit --no-translator --locale es --output-file hellogt_spanish.po --input hellogt.pot
sed --in-place hellogt_spanish.po --expression='/"hello, world!"/,/#:/s/""/"hola mundo"/'
mkdir --parents ./es.utf8/LC_MESSAGES
msgfmt --check --verbose --output-file ./es.utf8/LC_MESSAGES/hellogt.mo hellogt_spanish.po
LANG=es.utf8 ./hellogt
: が定義されている場合
環境変数、 のみGNU gettextので使用される言語、...、LANGUAGEはLC_ALL、LC_MESSAGES、およびLANGに優先 かかります。
LANGUAGE=es.utf8 ./hellogt
は英語ではなく、期待されるスペイン語のテキストを生成します。
しかし、これは「LANG = es」が機能しない理由を説明していません。