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. Translation is not working through JavaScript function
Forum Updated to NodeBB v4.3 + New Features

Translation is not working through JavaScript function

Scheduled Pinned Locked Moved Solved QML and Qt Quick
11 Posts 3 Posters 1.3k 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.
  • D Offline
    D Offline
    dheerendra
    Qt Champions 2022
    wrote on 5 Dec 2018, 13:32 last edited by
    #2

    It could be issue with property binding. Binding has to re-evaluate for the translation to work. Do you have sample program for us to check ?

    Dheerendra
    @Community Service
    Certified Qt Specialist
    http://www.pthinks.com

    1 Reply Last reply
    0
    • O Offline
      O Offline
      ODБOï
      wrote on 5 Dec 2018, 13:34 last edited by
      #3

      Hi,
      You should show your function and how you are doing it in qml so someone can help..
      You can use QtLinguist for translations.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sanjeev Gudisagar
        wrote on 8 Dec 2018, 13:52 last edited by Sanjeev Gudisagar 12 Aug 2018, 13:54
        #4

        @dheerendra This is my sample code, Once the button is clicked i am calling JavaScript function, i am changing all the text values after that i am translating, the translation is not working

        Column {
                spacing: 10
                anchors.centerIn: parent
                Text {
                    id : t1
                    text :cm.buttonText + trans.lang
                }
                Text {
                    id : t2
                    text :cm.buttonT1 + trans.lang
                }
                Text {
                    id: t3
                    text :cm.buttonT2 + trans.lang
                }
                Button{
                    text : "German"
                    onClicked: {
                        MyScript.changeValue();
                        trans.selectLanguage("de");
                    }
                }
            }
        
        1 Reply Last reply
        1
        • D Offline
          D Offline
          dheerendra
          Qt Champions 2022
          wrote on 8 Dec 2018, 13:56 last edited by
          #5

          trans - Is it object coming from C++ side ? If yes, is this method is really called ?Can you confirm ? Can you show me your setLanguage method ?

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          1
          • S Offline
            S Offline
            Sanjeev Gudisagar
            wrote on 8 Dec 2018, 14:03 last edited by
            #6

            I have the following code in the function. this function is called i verified it with debugs.

                if(language == "de") {
                    qDebug() << Q_FUNC_INFO << " Germany Language " << endl;
                    translator->load("");
                    translator->load("://de.qm");
                    QCoreApplication::instance()->installTranslator(translator);
                    engine->retranslate();
                }
            
            1 Reply Last reply
            0
            • D Offline
              D Offline
              dheerendra
              Qt Champions 2022
              wrote on 8 Dec 2018, 14:06 last edited by dheerendra 12 Aug 2018, 14:07
              #7

              This method looks correct from translation perspective. I'm assuming that appropriate translations exist in de.qm files. what changes are you doing in changeValue() method ? Can you show the function ?

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Sanjeev Gudisagar
                wrote on 8 Dec 2018, 14:09 last edited by
                #8

                @dheerendra said in Translation is not working through JavaScript function:

                changeValue()
                Whatever i am changing in changeValue() function is not getting translated.

                function changeValue() {
                    t2.text = cm.buttonT4
                    t3.text = cm.buttonT5
                    t1.text = cm.buttonT3
                }
                
                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on 8 Dec 2018, 14:12 last edited by
                  #9

                  hmm. You are doing the property bindings in javascript methods. This will not work. Can you try the following ?

                  t2.text = Qt.binding(function() { return cm.buttonT4;})
                  

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  1 Reply Last reply
                  1
                  • S Offline
                    S Offline
                    Sanjeev Gudisagar
                    wrote on 8 Dec 2018, 14:17 last edited by
                    #10

                    After replacing this like above its working now... Thank you @dheerendra

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dheerendra
                      Qt Champions 2022
                      wrote on 8 Dec 2018, 14:18 last edited by
                      #11

                      Cool. If you want to property binding trigger, you should call Qt.binding explicitly. Since issue is resolved you can move the case to "SOLVED" state.

                      Dheerendra
                      @Community Service
                      Certified Qt Specialist
                      http://www.pthinks.com

                      1 Reply Last reply
                      0

                      11/11

                      8 Dec 2018, 14:18

                      • Login

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