Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to create .ts files for Qt Linguist with PySide6?
Forum Updated to NodeBB v4.3 + New Features

How to create .ts files for Qt Linguist with PySide6?

Scheduled Pinned Locked Moved Unsolved Qt for Python
9 Posts 3 Posters 2.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StarterKit
    wrote on last edited by
    #1

    Hi all,

    I have a python project written with PySide2 and now I want to migrate to PySide6.
    My UI supports different languages and I did translation with help of Qt Linguist.
    I created .ts files with help of this command:
    pylupdate5 -noobsolete -translate-function g_tr my_project.pro
    Here g_tr is my alias for translate() function for shorter code (I haven't found better solution to type less text) defined this way:

    def g_tr(context, text):
        return QCoreApplication.translate(context, text)
    

    and pylupdate5 is actually not from PySide2 but from PyQt5. I don't know why I took it long time ago but it is still there and does the job. But I think it's no good as I plan to get rid of PySide2 and PyQt5 packages.

    So, I need to replace pylupdate5 with something from PySide6 package. I assumed lupdate should to the trick but it seems it works only with C++ code (at least it gives me errors like Unterminated C++ character or Unbalanced opening parenthesis in C++ code. An with lupdate -help I don't see how I may switch it to python mode (similar to uic -g python).

    So, could you please give me advice - how should I create .ts files from my python sources?

    eyllanescE 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I think you hit that roadblock.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • S StarterKit

        Hi all,

        I have a python project written with PySide2 and now I want to migrate to PySide6.
        My UI supports different languages and I did translation with help of Qt Linguist.
        I created .ts files with help of this command:
        pylupdate5 -noobsolete -translate-function g_tr my_project.pro
        Here g_tr is my alias for translate() function for shorter code (I haven't found better solution to type less text) defined this way:

        def g_tr(context, text):
            return QCoreApplication.translate(context, text)
        

        and pylupdate5 is actually not from PySide2 but from PyQt5. I don't know why I took it long time ago but it is still there and does the job. But I think it's no good as I plan to get rid of PySide2 and PyQt5 packages.

        So, I need to replace pylupdate5 with something from PySide6 package. I assumed lupdate should to the trick but it seems it works only with C++ code (at least it gives me errors like Unterminated C++ character or Unbalanced opening parenthesis in C++ code. An with lupdate -help I don't see how I may switch it to python mode (similar to uic -g python).

        So, could you please give me advice - how should I create .ts files from my python sources?

        eyllanescE Offline
        eyllanescE Offline
        eyllanesc
        wrote on last edited by
        #3

        @StarterKit Qt 6.2's lupdate does support python so check out https://stackoverflow.com/questions/69409367/how-to-create-ts-files-for-qt-linguist-with-pyside6/69409916#69409916

        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

        1 Reply Last reply
        3
        • S Offline
          S Offline
          StarterKit
          wrote on last edited by
          #4

          Thanks a lot, guys.
          You are right - I used outdated lupdate. I upgraded qt6-tools package and got a new one from Qt 6.2. It appears I need to tweak command line options but at least I don't have C++ related errors anymore.
          I'll finalize my command line, post it here and then close the topic as resolved.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            StarterKit
            wrote on last edited by StarterKit
            #5

            I played a bit with translation and it appears tr-function-alias option doesn't work.
            I invoked lupdate with this command

            /usr/lib/qt6/bin/lupdate -no-obsolete my.pro
            

            and here is my pro-file, very simple (I have a couple of examples with Qt 5.15 and 6.2 - they work. So I'm sure it is ok):

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

            If my source code contain calls to self.tr() like

            self.button.setText(self.tr("Check state"))
            

            then everything is ok, I get below output and ts-files have expected strings for translation:

            Updating 'en.ts'...
                Found 1 source text(s) (1 new and 0 already existing)
            Updating 'ru.ts'...
                Found 1 source text(s) (1 new and 0 already existing)
            

            But if I use this kind of code with custom translation function:

            def custom_tr(text):
                return QApplication.translate("Context", text)
               . . . . . . . . . . 
            
                self.button.setText(custom_tr("Check state"))
            

            and invoke lupdate with command

            /usr/lib/qt6/bin/lupdate -no-obsolete -tr-function-alias tr=custom_tr my.pro
            

            then it doesn't find strings to translate:

            Updating 'en.ts'...
                Found 0 source text(s) (0 new and 0 already existing)
            Updating 'ru.ts'...
                Found 0 source text(s) (0 new and 0 already existing)
            

            I used this approach with custom_tr with pylupdate5 and PySide2 - it worked fine. But option tr-function-alias for lupdate doesn't work as expected for PySide6. Either I don't understand syntax (but I played around and can't find other options) or somethign is wrong with it.

            Should I report it as a bug somehow?...

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Unless the removal was documented, then I would say yes, it's a bug.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 1 Reply Last reply
              0
              • SGaistS SGaist

                Unless the removal was documented, then I would say yes, it's a bug.

                S Offline
                S Offline
                StarterKit
                wrote on last edited by
                #7

                @SGaist said in How to create .ts files for Qt Linguist with PySide6?:

                Unless the removal was documented, then I would say yes, it's a bug.

                lupdate --help shows this option as available with detailed usage explanation.
                So I would vote for a bug. But I have no idea how to report it (have never done it before for Qt project). Any help/advices?

                eyllanescE 1 Reply Last reply
                0
                • S StarterKit

                  @SGaist said in How to create .ts files for Qt Linguist with PySide6?:

                  Unless the removal was documented, then I would say yes, it's a bug.

                  lupdate --help shows this option as available with detailed usage explanation.
                  So I would vote for a bug. But I have no idea how to report it (have never done it before for Qt project). Any help/advices?

                  eyllanescE Offline
                  eyllanescE Offline
                  eyllanesc
                  wrote on last edited by
                  #8

                  @StarterKit You must create a bug in https://bugreports.qt.io/.

                  If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                  S 1 Reply Last reply
                  0
                  • eyllanescE eyllanesc

                    @StarterKit You must create a bug in https://bugreports.qt.io/.

                    S Offline
                    S Offline
                    StarterKit
                    wrote on last edited by
                    #9

                    @eyllanesc ok, done https://bugreports.qt.io/browse/PYSIDE-1687

                    1 Reply Last reply
                    2

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved