Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-32850

qsTr() does not work with javascript libraries

    XMLWordPrintable

    Details

    • Commits:
      qtdeclarative/stable: 4d3a654dddbb648be97fe52c695601f6864f72a1

      Description

      I am trying to translate some strings from a .js library imported by my QMLs, the strings are found by lupdate but when I launch my app the qsTr function cannot find the translated string but it works with the strings in the QML files.

      Javascript “file.js”

          function func() {
              var temp = qsTr("TEST")
              return temp
          }
      

      QML

          import "file.js" as JSLIB
           
          Text{
                  text: JSLIB.func()
              }
      

      I have add some logs in qsTr() function in qtdeclarative/src/qml/qml/v8/qqmlbuiltinfunctions_p.h. The problem is qsTr() is looking the tag in a context with the file basename less the last character for .js files. I have modified manually the .ts file and it works:

      Old .ts generated by lupdate (NO WORKING):

      ...
      <context>
          <name>file</name>
      ...
      

      New .ts modified manually (WORKING):

      ...
      <context>
          <name>fil</name>
      ...
      

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            pepereto Manuel
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes