Just found a tutorial that I can easily follow:
http://fedoraproject.org/wiki/How_to_do_I18N_through_gettext
Here is my new code
#include <iostream>
#include <libintl.h>
#include <locale.h>
int main()
{
setlocale(LC_ALL, "");
bindtextdomain("helloworld", "/usr/share/locale");
textdomain("helloworld");
std::cout<<gettext("Hello World!")<<std::endl;
return 0;
}
Then creates pot
file
mkdir po
xgettext --package-name helloworld --package-version 1.0 -d helloworld -o po/helloworld.pot -s a.cpp
Generates mo
file
msginit --no-translator --locale fr_FR --output-file po/helloworld.po --input po/helloworld.pot
sed --in-place po/helloworld.po --expression='/"Hello World!"/,/#: / s/""/"Bonjour tout le monde!"/'
msgfmt po/helloworld.po -o po/helloworld.mo
sudo cp po/helloworld.mo /usr/share/locale/fr/LC_MESSAGES/
Here is the output
[deqing@hdell]~/work/sty$ ./helloworld
Hello World!
[deqing@hdell]~/work/sty$ LANG=fr_FR.utf-8
[deqing@hdell]~/work/sty$ ./helloworld
Bonjour tout le monde!