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. Couldn't loading the Translation properly at runtime..!
Forum Updated to NodeBB v4.3 + New Features

Couldn't loading the Translation properly at runtime..!

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 1.4k Views 1 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.
  • Kiranachari ShilpiK Offline
    Kiranachari ShilpiK Offline
    Kiranachari Shilpi
    wrote on last edited by
    #1

    1st.png

    It is the first image showing selection option for the change language, when i clicked upon german language ,

    2nd.png
    only some words are changing as you can see , but when i went to the next dialog of the project translation is working fine , coming back to the previous page now ,
    3rd.png
    you can see the translation is working properly now,

    Why..?

    Translation.cpp //is like this i'm integrating the C++, as i'm using the //QCoreApplication
    Translation::Translation(QQmlApplicationEngine *engines)
    {
    translator = new QTranslator;
    engine = engines;
    }

    void Translation::languageSelect(QString language)
    {
    qDebug()<<"Language"<<language;
    if(language == "German")
    {
    translator->load(":/translator/GermanTranslate_GE.qm");
    QCoreApplication::instance()->installTranslator(translator);
    engine->retranslate();
    }
    else if(language == "English")
    {
    translator->load("");
    QCoreApplication::instance()->installTranslator(translator);
    engine->retranslate();
    }
    }

    Qt Creator version : 5.10
    Platform : mac os

    1 Reply Last reply
    0
    • rrlopezR Offline
      rrlopezR Offline
      rrlopez
      wrote on last edited by
      #2

      I've had issues with translation before as well. Somehow, retranslate does not notify QML properly of the text changes, hence QML does not repaint all the strings correctly. There is a bug on QT that was fixed in 5.12:
      https://bugreports.qt.io/browse/QTBUG-68350

      However, there is a workaround for this. You can create a Q_PROPERTY with an empty string and define all your strings in terms of that empty string.
      i.e.

      readonly property string stringOne: qsTr("stringOne") + emptyStr

      Where emptyStr is a Q_PROPERTY with an empty string.

      Every time you run the reTranslate function, update this empty string with a new empty string. This will force QML to repaint all the strings and your translation will work fine.

      Lic-Ing. Rodrigo Lopez Gonzalez
      Embedded Software Engineer
      RidgeRun Engineering Ltd.
      www.ridgerun.com
      Email: rodrigo.lopez@ridgerun.com

      Kiranachari ShilpiK 2 Replies Last reply
      2
      • rrlopezR rrlopez

        I've had issues with translation before as well. Somehow, retranslate does not notify QML properly of the text changes, hence QML does not repaint all the strings correctly. There is a bug on QT that was fixed in 5.12:
        https://bugreports.qt.io/browse/QTBUG-68350

        However, there is a workaround for this. You can create a Q_PROPERTY with an empty string and define all your strings in terms of that empty string.
        i.e.

        readonly property string stringOne: qsTr("stringOne") + emptyStr

        Where emptyStr is a Q_PROPERTY with an empty string.

        Every time you run the reTranslate function, update this empty string with a new empty string. This will force QML to repaint all the strings and your translation will work fine.

        Kiranachari ShilpiK Offline
        Kiranachari ShilpiK Offline
        Kiranachari Shilpi
        wrote on last edited by
        #3

        hi @rrlopez Thank you for the information i tried this bug on both lower and 5.12 versions of Qt Creator , it was working fine in 5.12 version .

        1 Reply Last reply
        0
        • rrlopezR rrlopez

          I've had issues with translation before as well. Somehow, retranslate does not notify QML properly of the text changes, hence QML does not repaint all the strings correctly. There is a bug on QT that was fixed in 5.12:
          https://bugreports.qt.io/browse/QTBUG-68350

          However, there is a workaround for this. You can create a Q_PROPERTY with an empty string and define all your strings in terms of that empty string.
          i.e.

          readonly property string stringOne: qsTr("stringOne") + emptyStr

          Where emptyStr is a Q_PROPERTY with an empty string.

          Every time you run the reTranslate function, update this empty string with a new empty string. This will force QML to repaint all the strings and your translation will work fine.

          Kiranachari ShilpiK Offline
          Kiranachari ShilpiK Offline
          Kiranachari Shilpi
          wrote on last edited by
          #4

          @rrlopez I tried with QTBUG according to this BUG working correctly in Qt 5.12 , but with number of screens and components i'm using to create ListView, i want to use different list items every time for each and every screens, as i'm facing same issue for translation as i'm posted above.

          Two Components are like this

          Component1.qml //here i’m adding list items


          Component.onCompleted{
          var settingsMenu = [qsTr("Settings") , qsTr("Change Language") , qsTr(“Options”) , qsTr("Quit")]

          for(var i=0;i<settingsMenu.length;i++){
                       component2.addmenu(settingsMenu[i]);
                	}
          }
          

          Component2.qml


          //function call for appending the ListModel Elements
          Item{
          id:component2
          function addmenu(user){
          settingsModel.append({menu:user});
          }

          ListView{
          id:settingslist
          width: parent.width
          height:parent.height
          delegate:Rectangle{
          Text{
          text: menu
          }
          model: settingsModel
          }
          ListModel{
          id:settingsModel
          }
          }

          Qt Version: 5.12
          Platform : Windows

          Help me to reach out from this runtime error...
          Thanks In advance.

          1 Reply Last reply
          0
          • rrlopezR Offline
            rrlopezR Offline
            rrlopez
            wrote on last edited by
            #5

            Hi @Kiranachari-Shilpi, what I think its going on is that when you are appending the settingsMenu items to settingsModel, you are not directly creating a binding between the model and the data, hence any change on the language will not affect the settingsModel items. Javascript is not that good when you want to keep bindings on your QML, either properties or any other kind of change (like language changes in this case). I believe you would have to re-run your Component.onCompleted logic to make it re-translate and re-add the items to the settingsModel.
            Other way around that will not need this, is to append on the settingsMenu only the bare strings...
            i.e. var settingsMenu = ["Settings" , "Change Language" , “Options” , "Quit"]
            And on your QML file use qsTr(modelItem).

            Lic-Ing. Rodrigo Lopez Gonzalez
            Embedded Software Engineer
            RidgeRun Engineering Ltd.
            www.ridgerun.com
            Email: rodrigo.lopez@ridgerun.com

            Kiranachari ShilpiK 1 Reply Last reply
            2
            • rrlopezR rrlopez

              Hi @Kiranachari-Shilpi, what I think its going on is that when you are appending the settingsMenu items to settingsModel, you are not directly creating a binding between the model and the data, hence any change on the language will not affect the settingsModel items. Javascript is not that good when you want to keep bindings on your QML, either properties or any other kind of change (like language changes in this case). I believe you would have to re-run your Component.onCompleted logic to make it re-translate and re-add the items to the settingsModel.
              Other way around that will not need this, is to append on the settingsMenu only the bare strings...
              i.e. var settingsMenu = ["Settings" , "Change Language" , “Options” , "Quit"]
              And on your QML file use qsTr(modelItem).

              Kiranachari ShilpiK Offline
              Kiranachari ShilpiK Offline
              Kiranachari Shilpi
              wrote on last edited by
              #6

              Hi @rrlopez ,
              Sorry for the late response , Thank you so much for the reply,
              It was a very new concept i learned , thank you for your suggestions , my translation project is working perfectly now.

              1 Reply Last reply
              1

              • Login

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