Can I use tr(“”) and lupdate on *.xml files?

后端 未结 1 1892
青春惊慌失措
青春惊慌失措 2021-01-19 08:00

This is a shot in the dark but is there a way to use somehow qt(\"\") in an xml file? To generate the .ts files like this?:

lupdate myXML.xml -ts myML.ts


        
相关标签:
1条回答
  • 2021-01-19 08:47

    Ok so I found the solution using QT_TRANSLATE_NOOP:

    In the following xml text i do something like this:

    <root>
       <tag>QT_TRANSLATE_NOOP("context","value")</tag>
    </root>
    

    And when I want to fetch the value I do something like this in cpp:

        Q_INVOKABLE QString getTranslation(QString value){
            return QApplication::translate("context", value);
        }
    

    So to sum up in a few words. I put the macro QT_TRANSLATE_NOOP in my xml file containing a context string(you can choose whatever you want) and the value that I want it to be translated. So when I do lupdate myxml.xml -ts myTs.ts it generates a ts file having the value as the source text within the context specified in the macro. After that in cpp I must create a function that dynamically takes the translation from the context.

    0 讨论(0)
提交回复
热议问题