Ejemplo completo de C ++ i18n gettext () "hola mundo"
Estoy buscando una completa i18ngettext()
Hola ejemplo del mundo. He comenzado un guión basado enUn tutorial sobre soporte de idioma nativo usando GNU gettext por G. Mohanty. Estoy usando Linux y G ++.
Código:
<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>
El programa compila, el texto se extrae, el archivo en español se crea, se modifica y se crea un binario, pero hellogt aún muestra el inglés. La traza no muestra evidencia de buscar en el directorio de trabajo actual para es_MX ni ninguna referencia al directorio LC_MESSAGES.