0

2.0 + MinGW32 + Windows platform + Netbeans IDE to create my application. i have created the front-end but now i need to add language selection option and i want auto translation and i m new to GTK so i want detailed help. i searched on google but i didn't found any help for doing it on windows so please help as soon as possible :( I have designed my layout using gtkBuilder.

I want to know the exact steps to follow to get it done...

Please highlight how to use gettext() or_() in windows and what are .po files and how to handle them...

** Sorry for bad English...

2 Answers2

0

Well, it depends on which Makefile generator you use. I don't think you're using autotools for that, so you may need to implement your own logic for that.

I did that on Windows/MinGW with CMake. The workflow you need to follow to produce your .po files is in the GNU gettext overview. Basically, xgettext parses your code to extract the strings you want to translate. You can pass it a keyword, generally "_" which identifies the _() macro used in your code to mark strings for translation. It will generate the .pot (PO template) files. You can then copy that file and rename it into a .po file, and translate the strings with tools like poedit.

The, you needs some mechanisms to update your po files. This uses msgmerge, that will merge your new .pot files with the existing .po files. It will add the new strings to translate, and comment out the strings that disappeared.

Unfortunately, this is all tied to your build system, so there'not one sigle way to do it. I used CMake, but you can use shell scripts or any system able to call a command and generate files.

Hope this helps.

liberforce
  • 11,189
  • 37
  • 48
0
cat >hellogt.cxx <<EOF
// hellogt.cxx
#include <libintl.h>
#include <locale.h>
#include <iostream>
int main (){
    setlocale(LC_ALL, "");
    bindtextdomain("hellogt", ".");
    textdomain( "hellogt");
    std::cout << gettext("hello, world!") << std::endl;
}
EOF
g++ -o hellogt hellogt.cxx
xgettext --package-name hellogt --package-version 1.2 --default-domain hellogt --output hellogt.pot hellogt.cxx
msginit --no-translator --locale es_MX --output-file hellogt_spanish.po --input hellogt.pot
sed --in-place hellogt_spanish.po --expression='/"hello, world!"/,/#: / s/""/"hola mundo"/'
mkdir --parents ./es_MX.utf8/LC_MESSAGES
msgfmt --check --verbose --output-file ./es_MX.utf8/LC_MESSAGES/hellogt.mo hellogt_spanish.po
LANGUAGE=es_MX.utf8 ./hellogt

Here is a description of the files created by the above:

hellogt.cxx         C++ source file
hellogt             Executable image
hellogt.pot         Extracted text from C++ source file (portable object template)
hellogt_spanish.po  Modified text for Spanish with translations added (using sed)
es_MX.utf8/
 LC_MESSAGES/
   hellogt.mo       Binary translated text for Spanish used at run-time

SOURCE: Complete C++ i18n gettext() "hello world" example

Community
  • 1
  • 1
  • Well, the "sed" step is mostly useless, the translations are generally done using an external tool, like poedit, or by editing manually the .po file. The gettext call in hellogt.cxx is also replaced by a call to the \_() macro, who hides it (and the --keyword=_ option is then passed to xgettext to recognize the strings marked for translation). _T() is used for strings that should not be translated. – liberforce Nov 24 '11 at 13:23