warvariuc
warvariuc

Reputation: 59594

Best practices for internationalization using PyQt4

I want to add multiple language support to my application which is written in Python using PyQt4. I was looking for information on how to add multiple languages and would like to see how other people do this.

Here i read:

The PyQt behaviour is unsatisfactory and may be changed in the future. It is recommended that QCoreApplication.translate() be used in preference to tr() (and trUtf8()). This is guaranteed to work with current and future versions of PyQt and makes it much easier to share message files between Python and C++ code.

In files generated by pyuic4 i see something like:

WPopupCalendar.setWindowTitle(QtGui.QApplication.translate("WPopupCalendar", "Календарь", None, QtGui.QApplication.UnicodeUTF8))

This looks too long for me. I was thinking to make my own tr helper function which somehow would automate the process.

Also i could not find articles describing a workflow and specifics for developing multilingual apps in python with pyqt4.

Would you please advice me with some good and convenient techniques on this?

Upvotes: 4

Views: 1668

Answers (1)

ekhumoro
ekhumoro

Reputation: 120578

Just use tr (or trUtf8) everywhere to start with. Only bother with translate when you identify code that is affected by the issue with multiple inheritance (which could easily be never).

I would suggest you have a look at Qt's i18n overview, and the Qt Linguist Manual. They are obviously both oriented towards C++ projects, but it should give you a pretty clear idea of what's required.

For a working example, you could also download the source code of the Eric Python IDE - it's written in PyQt4, and has support for a half dozen or more languages.

Upvotes: 1

Related Questions