Je suis à la recherche d'un complet i18n gettext()
exemple de bonjour monde. J'ai commencé un script basé sur A tutorial on Native Language Support using GNU gettext par G. Mohanty. J'utilise Linux et G ++.Complete C + + i18n gettext() "Bonjour tout le monde" exemple
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
Le programme compile, le texte est extrait, le fichier espagnol est créé, modifié et binaire créé, mais hellogt affiche toujours l'anglais. La trace ne montre aucune indication de recherche dans le répertoire de travail actuel pour es_MX ni aucune référence au répertoire LC_MESSAGES.
Merci. La trace m'a aidé à identifier que le code que j'avais ne regardait pas les fichiers comme je m'y attendais. –