At first you need to include the following headers:
Code: Select all
#include <libintl.h>
#include <locale.h>
Code: Select all
#define _(S) gettext(S)
Code: Select all
int main (int argc , char ** argv) {
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
Well, that's all, you've added localisation support in your app already.
But, that's just the support, you could build and run your app, but no magic translation will happen. A bit more work is needed.
You need to define in your source, which strings may be translated, to do so, we've defined the MACRO on top.
Now, put the strings you would translate in the clamps _() like this:
Code: Select all
set_title(_("This string will be to translate"));
When done, you could produce the .pot file for your app with the following command:
Code: Select all
xgettext --keyword=_ --language=C++ --add-comments --sort-output --package-name=$(NAME) --package-version=$(VER) -o po/$(NAME).pot sourcefilename.cpp sourcefilename1.cpp etc.cpp
You may need to add the /po directory beforehand.
now you could generate the .po from the .pot file which then could be used to hold the translation.
Code: Select all
msginit --input=po/$(NAME).pot --locale=$(LANG) --output=po/$(LANG).po
You properly wont to automate the po file generation so that supporters could easily generate the po file for there language, so here are some targets for your makefile, you could easily adapt them for your build system, if you use a other one:
Code: Select all
#@localisation
MSGLANGS=$(notdir $(wildcard po/*po))
MSGOBJS=$(addprefix locale/,$(MSGLANGS:.po=/LC_MESSAGES/$(NAME).mo))
gettext: $(MSGOBJS)
locale/%/LC_MESSAGES/$(NAME).mo: po/%.po
mkdir -p $(dir $@)
msgfmt -c -o $@ po/$*.po
updatepot:
xgettext --keyword=_ --language=C++ --add-comments --sort-output --package-name=$(NAME) --package-version=$(VER) -o po/$(NAME).pot $(NAME).cpp
for POFILE in $(MSGLANGS) ; do msgmerge --update po/$$POFILE po/$(NAME).pot ; done
po:
msginit --input=po/$(NAME).pot --locale=$(LANG) --output=po/$(basename $(LANG)).po
the po target must be declared as .PHONY
with this targets you could produce the po file by:
Code: Select all
make po
Code: Select all
make po LANG=your_choice
Code: Select all
locale -a
Code: Select all
cp --parents $(MSGOBJS) $(DESTDIR)$(SHARE_DIR)
That's it, now translation teams or supporters could easily add there language support to your application.
https://github.com/brummer10/jalv_selec ... ISATION.md