Skip to content

Gettext for vle 1.1

rtrepos edited this page Nov 28, 2013 · 2 revisions

Gettext is a program intended for the management of languages in computer applications. Program coming from the GNU project, It is very used in freeware, command line applications, graphical user interfaces and web sites. Gettext is a set of programs and a "C" API.

For more information: see the documentation of Gettext and the wikipedia page.

How do the programmer use it in the code

The functions of the gettext "C" API are available by including the file i18n.hpp in the directory vle/utils/i18n.hpp. In the VLE source code source, the sentences to translate have to be written in English and be put in a call to the gettext() function :

 #include <vle/utils/i18n.hpp>
 #include <iostream>
 using vle::fmt;
 // simple translation (from french)
 std::cout << _("phrase à traduire\n");
 // translation with string formatting thanks to boost::format (from french)
 std::cout << fmt(_("phrase à traduire avec paramètres : %1%\n")) % param);
 // translation of a long formatted string (from french)
 std::cout << fmt(
    _("Very very very very very very very very very very very "
    "" very very very very very very very very very very very"
    "long sentence : %1%\n") % param);
 // plurals handling, using a parameter (unsigned long int)
 std::cout << ngettext("model", "models", nb);
 // plurals handling, using a predefined string
 std::cout << fmt(ngettext("%1% model", "%1% models", nb)) % nb;

How do the translator provide a new language

Creation of the catalog from all the C++ files and Glade :

 cd git/vle
 find . -name "*pp" > /tmp/FILES
 find . -name "*glade" >> /tmp/FILES
 xgettext --language=c++ --boost -k_ -j -f /tmp/FILES -o i18n/vle-1-1.pot

Creation of a french translation file of translation:

 cd git/vle/i18n
 msginit -l fr -o fr.po -i vle-1-1.pot

Compilation of a catalog (build by the Gettext script of CMake):

 cd git/vle/i18n
 msgfmt -c -v -o fr.mo fr.po

Update of a translation file with one new release of the catalog file:

 cd git/vle/i18n
 msgmerge --update fr.po vle-1-1.pot

Clone this wiki locally