Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Linguist: recover text to the base language
Qt 6.12 LTS is out! See what's new in the release blog

Qt Linguist: recover text to the base language

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 5 Posters 1.6k 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.
  • sitesvS Offline
    sitesvS Offline
    sitesv
    wrote on last edited by sitesv
    #1

    Hi everyone!

    I have the text table . In runtime I change the text language from lang1 (base lang) to lang2.
    Table text is saves to the file in the end of the process.

    Is it possible to recover text from lang2 to lang1 at the start of app or save text to file in base language?

    1 Reply Last reply
    0
    • sitesvS sitesv

      @SGaist, yes, I use QTranslator to change language.
      My case:
      I use QComboBox, that shows a list of the parameter variants. QComboBox is connected to the QTableWidget as a delegate.
      So, user selects one of the QComboBox variant (ver.1). After translation, this parameter contains translated version (ver.2) of the text. This text saves to the xml.
      But when the app starts and xml reads, variable has ver.2 and it can't be shown correctly.

      S Offline
      S Offline
      SimonSchroeder
      wrote on last edited by
      #8

      @sitesv said in Qt Linguist: recover text to the base language:

      I use QComboBox, that shows a list of the parameter variants. QComboBox is connected to the QTableWidget as a delegate.

      Okay, I understand why this might get complicated. In a lot of cases it is sufficient to be able to compare the text that was read in from the file with a specific string (where we can use the translated string again).

      In your case, I suggest the following: For each entry in the QComboBox add the non-translated text as user data. When adding items you can use QComboBox::addItem(tr(text),text). When the user selects something you get back the non-translated string using comboBox->itemData(comboBox->currentIndex()).toString(). Now, it gets slightly more complicated: Change from a QTableWidget to a QTableView. This also means that you need to write your own model class derived from QAbstractItemModel. Inside the model store the non-translated texts. The magic now happens with your derived class which needs to override data(...). For the DisplayRole of this function you then return the translated string, i.e. only when displaying the string in the table will you translate the text and everything before that is the non-translated text. You can then still get out the non-translated text from the model (your own derived class) and store this in your xml file.

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

        Hi,

        If you are using QTranslator, it's a one way translation from the original text in code to the one provided by QTranslator.

        You need to provide more information about your text table. What is it ? Is it user modifiable ? How do you save and restore it ?

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

        sitesvS 1 Reply Last reply
        0
        • S Offline
          S Offline
          SimonSchroeder
          wrote on last edited by
          #3

          With Qt Linguist you are editing .ts files. These get converted to .qm files. The .qm files store the information in binary format as a hash table for quicker access. IIRC the base language string is saved alongside the translation because of possible collisions. However, Qt does not provide a way to access the original string (which you actually know when you are looking up the translation). Hash tables also just work well one way. It is not feasible to do the inverse look up. As the data is all stored inside the .qm file you could read that information yourself or change the Qt source code to give you the information you want.

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            If you are using QTranslator, it's a one way translation from the original text in code to the one provided by QTranslator.

            You need to provide more information about your text table. What is it ? Is it user modifiable ? How do you save and restore it ?

            sitesvS Offline
            sitesvS Offline
            sitesv
            wrote on last edited by sitesv
            #4

            @SGaist, yes, I use QTranslator to change language.
            My case:
            I use QComboBox, that shows a list of the parameter variants. QComboBox is connected to the QTableWidget as a delegate.
            So, user selects one of the QComboBox variant (ver.1). After translation, this parameter contains translated version (ver.2) of the text. This text saves to the xml.
            But when the app starts and xml reads, variable has ver.2 and it can't be shown correctly.

            sitesvS S 2 Replies Last reply
            0
            • D Offline
              D Offline
              davidbland889
              wrote on last edited by
              #5
              This post is deleted!
              1 Reply Last reply
              0
              • sitesvS sitesv

                @SGaist, yes, I use QTranslator to change language.
                My case:
                I use QComboBox, that shows a list of the parameter variants. QComboBox is connected to the QTableWidget as a delegate.
                So, user selects one of the QComboBox variant (ver.1). After translation, this parameter contains translated version (ver.2) of the text. This text saves to the xml.
                But when the app starts and xml reads, variable has ver.2 and it can't be shown correctly.

                sitesvS Offline
                sitesvS Offline
                sitesv
                wrote on last edited by sitesv
                #6

                @davidbland889, thanks for reply.
                but I trying to figure out for possibility to resolve my case without external api. I think my case is simple and common :)

                JonBJ 1 Reply Last reply
                0
                • sitesvS sitesv

                  @davidbland889, thanks for reply.
                  but I trying to figure out for possibility to resolve my case without external api. I think my case is simple and common :)

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #7

                  @sitesv Ignore that user, it's spam!

                  1 Reply Last reply
                  1
                  • sitesvS sitesv

                    @SGaist, yes, I use QTranslator to change language.
                    My case:
                    I use QComboBox, that shows a list of the parameter variants. QComboBox is connected to the QTableWidget as a delegate.
                    So, user selects one of the QComboBox variant (ver.1). After translation, this parameter contains translated version (ver.2) of the text. This text saves to the xml.
                    But when the app starts and xml reads, variable has ver.2 and it can't be shown correctly.

                    S Offline
                    S Offline
                    SimonSchroeder
                    wrote on last edited by
                    #8

                    @sitesv said in Qt Linguist: recover text to the base language:

                    I use QComboBox, that shows a list of the parameter variants. QComboBox is connected to the QTableWidget as a delegate.

                    Okay, I understand why this might get complicated. In a lot of cases it is sufficient to be able to compare the text that was read in from the file with a specific string (where we can use the translated string again).

                    In your case, I suggest the following: For each entry in the QComboBox add the non-translated text as user data. When adding items you can use QComboBox::addItem(tr(text),text). When the user selects something you get back the non-translated string using comboBox->itemData(comboBox->currentIndex()).toString(). Now, it gets slightly more complicated: Change from a QTableWidget to a QTableView. This also means that you need to write your own model class derived from QAbstractItemModel. Inside the model store the non-translated texts. The magic now happens with your derived class which needs to override data(...). For the DisplayRole of this function you then return the translated string, i.e. only when displaying the string in the table will you translate the text and everything before that is the non-translated text. You can then still get out the non-translated text from the model (your own derived class) and store this in your xml file.

                    1 Reply Last reply
                    2
                    • sitesvS Offline
                      sitesvS Offline
                      sitesv
                      wrote on last edited by
                      #9

                      @SimonSchroeder Thank You!

                      1 Reply Last reply
                      0
                      • sitesvS sitesv has marked this topic as solved on

                      • Login

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