[PyQt] i18n

David Boddie dboddie at trolltech.com
Wed Feb 11 17:24:45 GMT 2009


On Wed Feb 11 14:57:59 GMT 2009, Frédéric wrote:

> Does anybody could point me on example how to use i18n in PyQt?

Here's an example of an application that uses i18n:

  http://qt-apps.org/content/show.php/PyPI+Browser?content=52389

It's not necessarily a good example. ;-)

> Riverbank documentation says that one should not use tr() method, but
> insteead QtCore.QCoreApplication.translate(). As the object must be
> passed to this method, this not improves the readability :o/

To avoid problems, I have previously defined a helper method in subclasses
where I thought it was necessary, like this:

class ActionEditorWidget(QLabel):

    def tr(self, text):
        return qApp.translate("ActionEditorWidget", text)

> Are there some tips, for example, to bind the _() method I use with
> gettext and PyGTK? Something to help me migrate my code without having
> to modify it everywhere...

There might also be a way to rebind the _() method, but it might just be
easier to use a helper method and perform a search and replace to use that
instead.

> Are there also some tools to migrate a .po file to a Qt i18n stuff?

Qt 4.5 will come with a version of Qt Linguist that may help with this:

  http://doc.trolltech.com/4.5/qt4-5-intro.html#qt-linguist-improvements

Another source of information about i18n with PyQt is Mark Summerfield's
book:

  http://www.qtrac.eu/pyqtbook.html

David



More information about the PyQt mailing list