Translator Comments



  • 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?


  • Moderators

    @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") );
    


  • 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 ...


  • Moderators

    @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
    


  • @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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.