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

Ruslan Popov ruslan.popov at gmail.com
Fri Jun 18 06:20:11 BST 2010


I understand that there is a simple way - just assign right string when UI
has loaded.
But may be there is UI-way...

On Thu, Jun 17, 2010 at 10:16 PM, Ruslan Popov <ruslan.popov at gmail.com>wrote:

> 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
>
>


-- 
Ruslan Popov
phone: +7 916 926 1205
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100618/2148a6ed/attachment-0001.html>


More information about the PyQt mailing list