On 1 October 2013 19:03, Boris Pek <tehnic...@yandex.ru> wrote: > Hi, > [snip] > > $ env | grep LANG > $ env | grep LC_ > > And search in google (or etc.) these environmental variables. > >> How can I see it in the original form? >
> Try something like this: > $ LC_ALL=C hallowelt > or this: > $ export LC_ALL=C > $ hallowelt > > Best wishes, > Boris Hi Boris, hi guys, Thanks for the tip. Its looking very professional. :) Now, I've made some modifications and I'm having trouble in adding a third language. For the record, look this HOW-TO I'm doing. (I'll state the problem in the end) /* ------------------- BEGIN OF FILE hallowelt.c ----------------- */ /* * MINI-HOWTO to translate printf messages using gettext * By Dr. Beco, (C) 2013, GNU/GPL License. */ #include <libintl.h> #include <locale.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) /* changed in ver.2 from: int main(void) */ { setlocale( LC_ALL, "" ); bindtextdomain( "hallo", "/home/beco/Documents/fontes/cpp/teste/ctranslate" ); textdomain( "hallo" ); /* added to ver.2 */ if(argc!=2) /* added to ver.2 */ { /* added to ver.2 */ if(argc==3) /* added to ver.2 */ setenv ("LANGUAGE", argv[1], 1); /* added to ver.2 */ printf(gettext("verwenden: %s LA [-h]\nwo LA = pt, en oder C\n"), argv[0]); /* added to ver.2 */ exit(1); /* added to ver.2 */ } /* added to ver.2 */ setenv ("LANGUAGE", argv[1], 1); printf(gettext("Hallo, welt!\n")); exit(0); } /* -------------------------------------------------------- Create the directory: $mkdir -p en/LC_MESSAGES Type program above (just ver.1), then get a binary with $gcc -o hallowelt hallowelt.c ================> hallowelt <================ and I get a template with $xgettext -d hallo -s -o hallowelt.pot hallowelt.c ================> hallowelt.pot <================ Create a "po" to have a translation to some language $msginit -l en_US -o en_US-hallowelt.po -i hallowelt.pot ================> en_US-hallowelt.po <================ Edit the "po" file! Then, compile the po to a mo file $msgfmt -c -v -o hallo.mo en_US-hallowelt.po ================> hallo.mo <================ Copy it to the correct location $cp hallo.mo ./en/LC_MESSAGES And its ready. Run it! ================> $ LANG=C ; ./hallowelt <================ Hallo, welt! ================> $ LANG=en_US.UTF8 ; ./hallowet <================ Hello, world! --------------------------------------------------------- Have you upgraded the program to ver.2, then get a binary with $gcc -o hallowelt hallowelt.c ================> hallowelt <================ First, extract the new template $xgettext -d hallo -s -o hallowelt-neue.pot hallowelt.c ================> hallowelt-neue.pot <================ Update the "po" file merging it with the new template $msgmerge -s -U en_US-hallowelt.po hallowelt-neue.pot ================> en_US-hallowelt.po <================ Edit the "po" file! Then, compile the po to a mo file $msgfmt -c -v -o hallo.mo en_US-hallowelt.po ================> hallo.mo <================ Copy it to the correct location $cp hallo.mo en/LC_MESSAGES And its ready. Run it! (suppose your LANG=en_US.UTF8) ================> $ ./hallowet C -h <================ verwenden: ./hallowelt LA [-h] wo LA = pt, en oder C ================> $ ./hallowelt en -h <================ usage: ./hallowelt LA [-h] where LA = pt, en or C ================> $ ./hallowelt <================ usage: ./hallowelt LA [-h] where LA = pt, en or C ================> $ ./hallowelt en <================ Hello, world! ================> $ ./hallowelt C <================ Hallo, welt! --------------------------------------------------------- Want a third language? Create the directory: $mkdir -p pt/LC_MESSAGES Then first create a new po with: $msginit -l pt_BR -o pt_BR-hallowelt.po -i hallowelt-neue.pot ================> pt_BR-hallowelt.po <================ Edit the "po" file! Then, compile all po's to a mo file $msgfmt -c -v -o hallo.mo en_US-hallowelt.po pt_BR-hallowelt.po ================> hallo.mo <================ Copy it to the correct location $cp hallo.mo ./pt/LC_MESSAGES And its ready. Run it! ================> $ ./hallowelt pt <================ Ola, mundo! ================> $ ./hallowelt pt -h <================ uso: ./hallowelt LA [-h] onde LA = pt, en ou C --------------------------------------------------------- */ /* ------------------- END OF FILE hallowelt.c ----------------- */ Now, after I run the command: $ msgfmt -c -v -o hallo.mo en_US-hallowelt.po pt_BR-hallowelt.po I get this fatal errors: pt_BR-hallowelt.po:6: duplicate message definition... en_US-hallowelt.po:7: ...this is the location of the first definition pt_BR-hallowelt.po:22: duplicate message definition... en_US-hallowelt.po:23: ...this is the location of the first definition pt_BR-hallowelt.po:27: duplicate message definition... en_US-hallowelt.po:30: ...this is the location of the first definition msgfmt: pt_BR-hallowelt.po: warning: PO file header missing or invalid warning: charset conversion will not work msgfmt: found 4 fatal errors I've no luck in finding a tutorial on how to add a third language. Anyone had done this before? -------- Second small question: It seems that adding #define _( String ) gettext( String ) breaks xgettext Is there any trick to get it working with the define? Thanks! Beco. -- Dr Beco A.I. researcher "Sometimes the heart sees what is invisible to the eye." (H. Jackson Brown Jr.) -- To UNSUBSCRIBE, email to debian-mentors-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/caluyw2zdliosu+og9ed7ukaxuqxxbetuu2-qtn9qidavgkt...@mail.gmail.com