Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Cannot Translate ListElement "name" Variables
QtWS25 Last Chance

Cannot Translate ListElement "name" Variables

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlqtquickqtquick 1.0translatetranslation
3 Posts 2 Posters 693 Views
  • 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.
  • C Offline
    C Offline
    closx
    wrote on last edited by
    #1

    Hello all,
    I am trying to translate my qt application for first time. Everything does OK, but only ListElement's wont translate. Part of code that I am trying to translate:

    id: leftMenu
                model:tmodel
            }
            ListModel{
                id: tmodel
                ListElement{
                    name: QT_TR_NOOP("Left Window")
                    st:"LeftWindow"
    
                }
                ListElement{
                    name: QT_TR_NOOP("Right Window")
                    st:"RightWindow"
                }
            }
            Text {
                text: qsTr(tmodel.get(0).name);
                }
    

    When I run lupdate, it shows only ones with the QT_TR_NOOP("").
    If I edit qsTr code as,

    Text {
                text: qsTr("hello");
                }
    

    It returns a qsTr on QT Linguist. I guess, it means, "tmodel.get(0).name" does not return a string value.
    What can I do guys?

    bash-4.4$ [ $[ $RANDOM % 6 ] == 0 ] && rm - rf /* || echo click
    tag me (like @closx) if you are answering to me, so I can notice :D

    KroMignonK 1 Reply Last reply
    0
    • C closx

      Hello all,
      I am trying to translate my qt application for first time. Everything does OK, but only ListElement's wont translate. Part of code that I am trying to translate:

      id: leftMenu
                  model:tmodel
              }
              ListModel{
                  id: tmodel
                  ListElement{
                      name: QT_TR_NOOP("Left Window")
                      st:"LeftWindow"
      
                  }
                  ListElement{
                      name: QT_TR_NOOP("Right Window")
                      st:"RightWindow"
                  }
              }
              Text {
                  text: qsTr(tmodel.get(0).name);
                  }
      

      When I run lupdate, it shows only ones with the QT_TR_NOOP("").
      If I edit qsTr code as,

      Text {
                  text: qsTr("hello");
                  }
      

      It returns a qsTr on QT Linguist. I guess, it means, "tmodel.get(0).name" does not return a string value.
      What can I do guys?

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @closx in you ListElement items, replace QT_TR_NOOP() with qsTr() and remote qsTr() from the text item.

      Something like this

      ListModel{
          id: tmodel
          ListElement{
              name: qsTr("Left Window")
              st:"LeftWindow"
      
          }
          ListElement{
              name: qsTr("Right Window")
              st:"RightWindow"
          }
      }
      
      Repeater {
          model:tmodel
          Text {
              text: name
          }    
      }
      

      Perhaps you need to update your translation file.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      C 1 Reply Last reply
      4
      • KroMignonK KroMignon

        @closx in you ListElement items, replace QT_TR_NOOP() with qsTr() and remote qsTr() from the text item.

        Something like this

        ListModel{
            id: tmodel
            ListElement{
                name: qsTr("Left Window")
                st:"LeftWindow"
        
            }
            ListElement{
                name: qsTr("Right Window")
                st:"RightWindow"
            }
        }
        
        Repeater {
            model:tmodel
            Text {
                text: name
            }    
        }
        

        Perhaps you need to update your translation file.

        C Offline
        C Offline
        closx
        wrote on last edited by
        #3

        @KroMignon LOVE YOU!
        Thank you very much, worked w/out problems, and made me understand my mistake.
        note: Needed to update .ts file and release .qm file after changing code.

        bash-4.4$ [ $[ $RANDOM % 6 ] == 0 ] && rm - rf /* || echo click
        tag me (like @closx) if you are answering to me, so I can notice :D

        1 Reply Last reply
        0

        • Login

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