[PyKDE] Translation Recomendations

David Sankel camior at gmail.com
Mon Jan 3 17:28:21 GMT 2005


Good Afternoon,

  I was wondering if anyone has some suggestions for using translation
files with PyQt.  Since pylupdate doesn't fill .ts files with
information from .ui files, one is forced to create two different
translation files.  Here is what I have:

Program.pro:
  FORMS = SomeWindow.ui
  TRANSLATIONS = translations/Translation_es.ts

Programs_Python.pro:
  SOURCES = SomeCode.py
  TRANSLATIONS = translations/Translation_Python_es.ts

To generate the .ts files:
  lupdate Program.pro
  pylupdate Program_Python.pro

Loading the translations:
  def loadTranslations():
    """Load translation files into QApplication.  They are loaded based on the 
       locale of the host system."""
    # locale = "es" # Spanish Locale
    locale = QTextCodec.locale()
    # There are two translation files for each locale.  The first for files
    # generated with qdesigner and the second for python code.
    filePrefixes = [ "translations/Translation_",
"translations/Translation_Python_" ]
    for prefix in filePrefixes:
      translator = QTranslator(qApp)
      qApp.installTranslator( translator )

Everything above works perfectly.  The negative is, of course, the
complication of having more than one .pro file and more than one .ts
file for our translators.  Does anyone have a better solution? 
Perhaps it is possible to use the pyuic generated .py files to allow
one to use pylupdate instead of lupdate.

Regards,

David Sankel




More information about the PyQt mailing list