Needs to be set up for translations

Bug #1004389 reported by David Planella
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
quickly-ubuntu-qt-template
In Progress
Undecided
Unassigned

Bug Description

The template needs to be set up for translations.

It's already using gettext, so it should be straightforward to set up.

- The project needs a po folder to contain translations
- It also needs a means to create a .pot file that contains all translatable messages
- It might be worth creating a setup.py file and use python-distutils-extra, which will not only help with translations, but also with the packaging.
- Once all these are set up, then translations in Launchpad can be opened so that translators can do their job

I'm happy to help with all these.

There is only one thing I don't really know how to do right now: using gettext to make QML translatable. This will need some investigation.

Note that we cannot use Qt's translation mechanism, since Launchpad is only compatible with gettext (and Quickly itself uses gettext).

Revision history for this message
Angelo Compagnucci (angeloc) wrote :

Best strategy is here https://code.launchpad.net/~agateau/unity-2d/gettext2/+merge/53668, but doesn't fit with our scope.

In short terms:

unity2d use another function to get translations (u2dtr), superseding QT's tr() one.
For qml, they have an helper that replace on the fly qsTr() with u2d.tr().

The do not use ui files however.

Revision history for this message
Angelo Compagnucci (angeloc) wrote :

I think we can try something like what done in unity2d:

void qmlInit(QDeclarativeContext* context)
 {
     static QmlHelper helper;
     context->setContextProperty("u2d", &helper);
 }

 QString QmlHelper::tr(const QString& text)
 {
     return ::u2dTr(text.toUtf8().constData());
 }

 QString QmlHelper::tr(const QString& singular, const QString& plural, int n)
 {
     return ::u2dTr(
         singular.toUtf8().constData(),
         plural.toUtf8().constData(),
         n);
 }

Installing a translation helper and replace in qml files the tr() use with ourclass.tr() . ourclass.tr() could simply return a string based on _() function.

It doesn't solve the problem with ui files, they will use qt internal translator.

We can use retranslateUI at our favor: this method will be called every time a new translator is installed, or manually if you want. Of course, we cannot install a new translator (useless for us) but we can use a custom function that internally calls self.retranslateUI.
retranslateUI should contains each instruction to set translated messages ( see this example http://qt-project.org/faq/answer/how_can_i_dynamically_switch_between_languages_in_my_application_using_e.g_ ) so we can pass a string from _() instead of tr().

Writing retranslateUI is tedious. I'm thinking of a function that loop inside all children of the object returned by uiloader, and for each one looks up gettext translation to find the one that matches and it calls the appropriate method (which in the majority of cases is setText()).

Revision history for this message
Angelo Compagnucci (angeloc) wrote :

More elements

QUiLoader.setLanguageChangeEnabled(enabled) could set auto-reload of translations on widgets if enabled, so no need to use retranslateUI for that purpose.

Changed in quickly-ubuntu-qt-template:
status: New → In Progress
Revision history for this message
Angelo Compagnucci (angeloc) wrote :

Some updates:

I choose to use native QT translation system. To make it Lunchpad compatible, a pot is generated when the project is saved (quickly save). This way the pot could be translated as usual with Launchpad tools or locally on the developer machine.
Before packagin, po files are converted back to the .qm QT native format and packaged with application instead of po files.

Done with automatic conversion to pot file on quickly save.
In progress, fixing python-distutils-extra to package qm files if they are present.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.