Existe-t-il un moyen standard ou commun en C++ de gérer les chaînes statiques qui doivent être définies par gettext()
?Comment initialiser un char statique * avec gettetxt() en utilisant un environnement de système d'exploitation local?
Voici un exemple en utilisant la réponse à Complete C++ i18n gettext() “hello world” example comme base changeant juste le hello world
littéral à un char* hws
et char* hw
statique. Il semble que hws
soit initialisé au texte anglais par défaut avant que les paramètres régionaux ne soient définis dans l'environnement de système d'exploitation local . Alors que hw
est défini après la modification des paramètres régionaux, le texte en espagnol est généré.
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
mise en forme Changed de "statique" dans "static char * hws". B.Stroustrup, La troisième édition du langage de programmation C++, page 83, indique que les objets globaux, les espaces de noms et les objets statiques locaux sont collectivement appelés des objets statiques. –