Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Translator Comments
QtWS25 Last Chance

Translator Comments

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.8k 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.
  • U Offline
    U Offline
    UTC_09_069
    wrote on last edited by
    #1

    Hi All,

    I am trying to put Translator Comments in the generated .ts file from the code through the Qt lupdate tool. I general the comments can be put in to the file by the following process
    http://doc.qt.io/qt-4.8/i18n-source-translation.html#translator-comments

    However in the file i am getting the following in the ts file,

    <message>
        <source>Status: Acknowledged</source>
        <extracomment>Translator Comments----------Translator Comments</extracomment>
        <translation type="unfinished"></translation>
    </message>
    

    in the code i have made the following change
    /*: Translator Comments */
    label->setText(QApplication::translate(" " , "Status: Acknowledged"));

    So what am i missing here? Any suggestions?

    raven-worxR 1 Reply Last reply
    0
    • U UTC_09_069

      Hi All,

      I am trying to put Translator Comments in the generated .ts file from the code through the Qt lupdate tool. I general the comments can be put in to the file by the following process
      http://doc.qt.io/qt-4.8/i18n-source-translation.html#translator-comments

      However in the file i am getting the following in the ts file,

      <message>
          <source>Status: Acknowledged</source>
          <extracomment>Translator Comments----------Translator Comments</extracomment>
          <translation type="unfinished"></translation>
      </message>
      

      in the code i have made the following change
      /*: Translator Comments */
      label->setText(QApplication::translate(" " , "Status: Acknowledged"));

      So what am i missing here? Any suggestions?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @UTC_09_069 said in Translator Comments:

      label->setText(QApplication::translate(" " , "Status: Acknowledged"));

      Instead of QApplication::translate() you should use QObject::tr():

      label->setText( tr("text-to-translate" , "comment") );
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • U Offline
        U Offline
        UTC_09_069
        wrote on last edited by
        #3

        Here is the output once i run the above code,

        <context>
        <name>QApplication</name>
        <message>
        <source>Status: Acknowledged</source>
        <comment>comment</comment>
        <extracomment>Translator Comments

        Translator Comments</extracomment>
        <translation type="unfinished"></translation>
        </message>
        </context>

        As you can see the comment that is coming is basically the disambiguation however the what we need is the extracomment and also want to avoid the context name QApplication ...

        raven-worxR 1 Reply Last reply
        0
        • U UTC_09_069

          Here is the output once i run the above code,

          <context>
          <name>QApplication</name>
          <message>
          <source>Status: Acknowledged</source>
          <comment>comment</comment>
          <extracomment>Translator Comments

          Translator Comments</extracomment>
          <translation type="unfinished"></translation>
          </message>
          </context>

          As you can see the comment that is coming is basically the disambiguation however the what we need is the extracomment and also want to avoid the context name QApplication ...

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @UTC_09_069
          ok got you now.
          See translator comments.

          //: this should be an extra comment
          

          The context comes from the class which the translate method is called on. But you can also change the context with the translator comments by adding meta-data?

          //~ Context MY_NEW_CONTEXT
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1
          • Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by Pablo J. Rogina
            #5

            @UTC_09_069 What I think you're looking for is using the "translator comments" by means of using the metadata syntax for translations (see documentation stated in previous post).

            //~ <field-name> <field-value>
            

            The key phrase from documentation is "For storage in TS files, the field name together with the prefix "extra-" will form an XML element name.". So for this source code snippet:

                //~ comment This is a comment for the translator
                Qstring txt = QString(tr("same label to translate"));
            

            you'll get the following in the .ts file:

               <message>
                   <location filename="mainwindow.cpp" line="9"/>
                   <source>same label to translate</source>
                   <translation type="unfinished"></translation>
                   <extra-comment>This is a comment for the translator</extra-comment>
               </message>
            

            Happy coding!

            PS: don't forget to mark your post as solved when you finally find the solution

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            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