# Ubuntu – How To Use i18n.tr in Ubuntu Touch Projects

application-developmentqmlqtubuntu-sdkubuntu-touch

I have been using i18n.tr for a while in my Ubuntu-Touch projects. I know what this function is about but I don't know how to add a translation to my project.

Where do I have to place my translation file?
With what name?
How must its content be written?
How should I connect it with my app?
How do I test it with qmlscene ?

Take a look at TouchWriter code and especially its README, where all needed commands are given.

### Quick summary

• You need to bind the text domain before using gettext. In C++ you can do it like this:

bindtextdomain("domainname", "somedir");
textdomain("domainname");


In Qml you can probably do something like this:

i18n.bindtextdomain("domainname", "somedir");
i18n.domain = "domainname";


Be sure to do that before 18n.tr is used.

• To generate .pot template and source .po files, use these commands:

xgettext -C --qt --keyword=tr -p somedir -o messages.pot
msginit -i somedir/messages.pot -o somedir/somelanguage.po


(replace somedir with the directory your domain is bound to, and somelanguage with the language you want to translate to).

• To generate .mo files from source .po files, use msgfmt po-file -o mo-file command.

• Compiled .mo files should be placed inside a directory you bound the text domain to, more specifically in

somedir/somelanguage/LC_MESSAGES/domainname.mo


(replace somedir, somelanguage and domainname with your values).