0

I used pyside6 to develop a software, I'm trying to do i18n on it. I found a weird problem with the pyside6-lupdate tool.

When I use the 'tr' marker in my python file, the tool can successfully exact it to a ts file. i.e main.py

self.btn_open_file = QPushButton(self.tr('Open File Folder'), self)

the command I run in the terminal is:

pyside6-lupdate main.py -ts test.ts

But when I use it on QT designer generated python files, it won't work anymore, as those files use 'translate' as the marker, shown as below: ui_peg_page.py

def retranslateUi(self, PegPage):
        PegPage.setWindowTitle(QCoreApplication.translate("PegPage", u"Form", None))
        self.label.setText(QCoreApplication.translate("PegPage", u"1. Peg to Existing Mapping Column (OR)", None))
        self.label_2.setText(QCoreApplication.translate("PegPage", u"2. Create a New Mapping Column", None))
        self.groupBox.setTitle(QCoreApplication.translate("PegPage", u"GroupBox", None)

When I run the command again, nothing was extracted. I wonder if anyone has encountered the same issue before. My pyside6 version is 6.2.2.1. I tried this on both mac and windows, both won't work. Would appreciate it much if anyone can point me a way out.

2 Answers 2

0

As you use Qt Designer for UI creation you should provide lupdate with form file, not a generated python module.

See details in PYSIDE-1717 and PYSIDE-1774.

3
  • Thanks for the sharing, but I still think pyside6-lupdate should be a legit use in the future, as I have no problem doing this in the earlier version like pyside2 and pyqt5. I think the QT team will fix in the future, pyside6-lupdate definitely can work with these two markers "QCoreApplication.translate" and "tr", it just the "u" unicode marker stands in the way now. Also pyside6-lupdate's "-tr-function-alias" is not working too. I believe it is just not stable yet.
    – Gaz Zhao
    Jan 28, 2022 at 13:40
  • It seems you misunderstood my comment and/or didn't check jira cases. lupdate is legit to use (pyside6-lupdate is the same tool, name just depends on a platform). But you shouldn't use lupdate with auto-generated files (created by Qt Designer). You should provide lupdate with form-file instead (ui-file).
    – StarterKit
    Jan 29, 2022 at 19:19
  • With regards to "-tr-function-alias" - yes, this was a bug - bugreports.qt.io/browse/PYSIDE-1687 It should be fixed already in recent version.
    – StarterKit
    Jan 29, 2022 at 19:21
0

After many failed trials, finally I found the tweak to fix it. If you want to use "QCoreApplication.translate("hared coded context", u"Text"), remove the unicode prefix "u", it will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.