[PyQt] How to translate strings after loading *.ui?

Ruslan Popov ruslan.popov at gmail.com
Thu Jun 17 19:16:16 BST 2010


Hi all,

I work on simple wizard. I define each type of dialog as *.ui and have the
translation problem.
How can I translate string defined in *.ui?

For instance, I want to see this:

     <widget class="QLabel" name="label">
      <property name="text">
       <string>Make your choice:</string>
      </property>
     </widget>

as this when using russian locale:

     <widget class="QLabel" name="label">
      <property name="text">
       <string>Сделайте свой выбор:</string>
      </property>
     </widget>


Some of sources:
class WizardDialog(QDialog):

    def __init__(self, ui_file, parent=None, params=dict()):
        QDialog.__init__(self, parent)

        dlg = uic.loadUi(ui_file, self)
        self.setupUi(dlg)

    def prefill(self, title):
        self.setWindowTitle(title)

    def setupUi(self, dialog):
        self.connect(dialog.goBack, SIGNAL('clicked()'), self.go_back)
        self.connect(dialog.goNext, SIGNAL('clicked()'), self.go_next)

    def go_back(self):
        print 'Back button pressed'

    def go_next(self):
        print 'Next button pressed'

class WizardListDlg(WizardDialog):

    def __init__(self, parent=None, params=dict()):
        WizardDialog.__init__(self, 'uis/dlg_list.ui', parent)

    def prefill(self, title, data):
        WizardDialog.prefill(self, title)

        for id, text in data:
            item = QListWidgetItem(text, self.listWidget)
            item.setData(Qt.UserRole, QVariant(id))

    def setupUi(self, dialog):
        WizardDialog.setupUi(self, self)
        self.connect(dialog.listWidget,
                     SIGNAL('itemDoubleClicked(QListWidgetItem *)'),
                     self.go_next)

    def go_back(self):
        print 'Back'

    def go_next(self):
        print 'Next'

Any help will be appreciated.
-- 
Ruslan Popov
phone: +7 916 926 1205
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100617/abe6480b/attachment.html>


More information about the PyQt mailing list