Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1774

lupdate doesn't handle retranslateUi() created by Qt Designer

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Duplicate
    • Affects Version/s: 6.2.2
    • Fix Version/s: None
    • Component/s: Tooling
    • Labels:
      None
    • Platform/s:
      Linux/X11

      Description

      Summary is in a subject line. More detailed example:

      main.py - very simle file to display main window and assign text to a label:

      from PySide6.QtWidgets import QApplication, QMainWindow
      from main_wnd import Ui_MainWindow
      
      class MainWnd(QMainWindow, Ui_MainWindow):
          def __init__(self):
              QMainWindow.__init__(self)
              self.setupUi(self)
      
              self.label.setText(self.tr("Test label"))
      
      
      def main():
          app = QApplication()
          wnd = MainWnd()
          wnd.show()
          return app.exec()
      
      
      if __name__ == '__main__':
          main()
      

      UI of main window is created as main_wnd.ui with help of Qt Designer (attached). This file was converted to main_wnd.py with help of command /usr/lib/qt6/uic -g python -o ./main_wnd.py ./main_wnd.ui. It contains a right block of code for UI translation:

      def retranslateUi(self, MainWindow):
          MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"Test phrase window", None))
          self.label.setText(QCoreApplication.translate("MainWindow", u"TextLabel", None))
      

      Then I created very simple main.pro file:

      SOURCES = ./main.py ./main_wnd.py
      TRANSLATIONS = en.ts ru.ts
      

      Next step is to generate translation files and here is the problem.

      When I run command /usr/lib/qt6/bin/lupdate main.pro I get only this in ru.ts:

      <?xml version="1.0" encoding="utf-8"?>
      <!DOCTYPE TS>
      <TS version="2.1">
      <context>
          <name>MainWnd</name>
          <message>
              <location filename="main.py" line="12"/>
              <source>Test label</source>
              <translation type="unfinished"></translation>
          </message>
      </context>
      </TS>
      

      I.e. it takes only text from my own main.py module and ignores QCoreApplication.translate() calls generated by Qt Designer in main_wnd.py.

       

      Old version of the tool (pylupdate5 main.pro) generates full set of tranlations - one line for main.py and two lines for main_wnd.py:

      <?xml version="1.0" encoding="utf-8"?>
      <!DOCTYPE TS>
      <TS version="2.1">
      <context>
          <name>MainWindow</name>
          <message>
              <location filename="main_wnd.py" line="50"/>
              <source>Test phrase window</source>
              <translation type="unfinished"></translation>
          </message>
          <message>
              <location filename="main_wnd.py" line="51"/>
              <source>TextLabel</source>
              <translation type="unfinished"></translation>
          </message>
      </context>
      <context>
          <name>MainWnd</name>
          <message>
              <location filename="main.py" line="9"/>
              <source>Test label</source>
              <translation type="unfinished"></translation>
          </message>
      </context>
      </TS>
      

        Attachments

        1. main_wnd.py
          2 kB
        2. main_wnd.ui
          0.9 kB
        3. main.pro
          0.1 kB
        4. main.py
          0.4 kB

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              crmaurei Cristian Maureira-Fredes
              Reporter:
              starterkit Ivan Ivanov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes