views:

260

answers:

1

I have couple of application written in PyQt4 where I've used standard Python gettext library for internationalization and localization of GUI. It works good for me. But I've selected gettext just because I've already had knowledge and experience of gettext usage, and zero of experience with Qt4 tr() approach.

Now I'd like to better compare both approaches and understand what I'm missing by using gettext instead of QObject.tr, and does there any serious reason why I should not use gettext for Qt4/PyQt4 applications?

In my understanding advantages of using gettext are:

  • GNU gettext is mature and it seems to be standard de-facto in GNU/Linux world.
  • There is enough special editors for PO files to simplify translators work, although textual nature of PO templates makes it not strictly necessary.
  • There is even web services available which can be used for collaborative translations.
  • gettext is standard Python library, so I don't need to install anything special to use it in runtime.
  • It has very good support for singular/plural forms selection via ngettext().

What I see as advantages of QObject.tr():

  • This is native technology for Qt4/PyQt4 so maybe it will work better/faster (although I have no data to prove).
  • The messages to translate may have additional context information which will help translators to choose the best variants for homonym words, e.g. the english word "Letter" can be translates as "Character", "Mail" or even kind of "Paper size" depending on the actual context.

What I see as disadvantages of QObject.tr() vs gettext:

  • I did not found in the Qt documentation how's supported singular/plural selection there.
  • Qt4 TS translation template is in XML format and therefore more complex to edit without special editor (QT Linguist) and it seems there is no other third-party solutions or web services. So it would require for translators to learn new tool (if they are already familiar with PO tools).

But all the items above are not critical enough to clearly say that any tool is better of other. And I don't want to start flame war about what is better because it's very subjective. I just want to know what I missing as pros and cons of QObject.tr() vs gettext.

A: 

You could add that args are managed differently...

With Gettext, we can do

_("Hello %(name)s from %(city)s") % {person.__dict__}

whereas in PyQt, we do

self.tr("Hello %1 from %2").arg(person.name).arg(person.city)

emel