Best Internationalization Practices Using PyQt4

I want to add multi-language support to my application that 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 it.

Here I read:

PyQt's behavior is unsatisfactory and may change in the future. It is recommended that QCoreApplication.translate () be used in preference from tr () (and trUtf8 ()). This is guaranteed to work with current and future versions of PyQt and greatly facilitate the exchange of message files between Python and C ++ code.

In the files created by pyuic4 , I see something like:

 WPopupCalendar.setWindowTitle(QtGui.QApplication.translate("WPopupCalendar", "", None, QtGui.QApplication.UnicodeUTF8)) 

This is too long for me. I was thinking of creating my own helper function tr , which somehow automates the process.

Also, I could not find articles describing the workflow and features of developing multilingual applications in python with pyqt4.

Could you advise me some good and convenient methods?

+4
source share
1 answer

Just use tr (or trUtf8 ) to get started. Just worry with translate when you define code that is affected by the multiple inheritance problem (which can easily be never).

I would advise you to take a look at the Qt i18n review , and the Qt Linguist Guide . Obviously, they are focused on C ++ projects, but this should give you a pretty clear idea of ​​what is required.

In a working example, you can also download the Eric Python IDE source code - it is written in PyQt4 and has support for half a dozen or more languages.

+1
source

Source: https://habr.com/ru/post/1381035/