Komplettes C ++ i18n gettext () "Hallo Welt" Beispiel
Ich suche eine komplette i18ngettext()
Hallo Welt Beispiel. Ich habe ein Skript basierend auf gestartetEin Tutorial zur Unterstützung von Muttersprachen mit GNU gettext von G. Mohanty. Ich benutze Linux und G ++.
Code:
<code>cat >hellogt.cxx <<EOF // hellogt.cxx #include <libintl.h> #include <locale.h> #include <iostream> #include <cstdlib> int main (){ 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("hellogt", cwd) << std::endl; std::cout << "textdomain(): " << textdomain( "hellogt") << std::endl; std::cout << gettext("hello, world!") << std::endl; } EOF g++ -ohellogt hellogt.cxx xgettext -d hellogt -o hellogt.pot hellogt.cxx msginit --no-translator -l es_MX -o hellogt_spanish.po -i hellogt.pot sed --in-place hellogt_spanish.po --expression='/#: /,$ s/""/"hola mundo"/' sed --in-place hellogt_spanish.po --expression='s/PACKAGE VERSION/hellogt 1.0/' mkdir -p ./es_MX/LC_MESSAGES msgfmt -c -v -o ./es_MX/LC_MESSAGES/hellogt.mo hellogt_spanish.po export LANG=es_MX ls -l $PWD/es_MX/LC_MESSAGES/hellogt.mo ./hellogt strace -e trace=open ./hellogt </code>
Das Programm kompiliert, der Text wird extrahiert, die spanische Datei wird erstellt, geändert und binär erstellt, aber hellogt zeigt weiterhin Englisch an. Die Ablaufverfolgung zeigt weder Hinweise darauf, dass im aktuellen Arbeitsverzeichnis nach es_MX gesucht wurde, noch Verweise auf das Verzeichnis LC_MESSAGES.