5

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 ?

George Sofianos
  • 183
  • 1
  • 10

2 Answers2

2

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).

  • Ok i downloaded the source and checked some of the commands. Do you also know how do I test the translations via qmlscene ? – George Sofianos Sep 24 '13 at 10:31
  • @GeorgeSofianos I've updated the answer with instructions of how to bind text domains and where you should place your files. Note that in my case I did that in C++ code, but doing that in QML should work as well. – Dmitry Shachnev Sep 24 '13 at 15:33
  • (You can easily create .pot and .mo files directly in Qt Creator http://i.imgur.com/I9f1Wg3.png) – Alex Sep 25 '13 at 17:01
-1

The best answer seems to be in the doc. http://developer.ubuntu.com/api/ubuntu-12.10/qml/mobile/qml-ubuntu-components0-i18n.html

It seems to be a function that translates the word passed to the user's language.

J3RN
  • 188
  • 9