Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Translations - How to add a context in Linguist from an id-based translation?



  • For my translations, I'm interested to create specific contexts in Linguist, in order to help the translators to achieve the process.

    For example, consider this code:

    title: qsTranslate("a context", "Multi-language app")
    

    In Linguist it will produce the following result:
    73b0fc7a-f8bb-44e8-84c3-4396cc79e5f3-image.png

    This work well for string based translations, however in my project I'm using ID based translations. For that reason I'm not using the qsTr() or qsTranslate() functions, but instead the qsTrId() ones.

    I spent several days searching if there was a similar function working as described above, but based on ID, however I never found one which may produce the same result in Linguist.

    So my question is: Is there a translation function based on ID, e.g something like qsTranslateId(), although this function doesn't exist, which may also define a context while imported in Linguist, as shown in the above image?



  • @jeanmilost what if you use the qsTranslate() function, using context and the text Id instead of the string. So your example:

    title: qsTranslate("a context", "Multi-language app")
    

    will be:

    title: qsTranslate("a context", "ID_Multi_language_app")
    


  • @Pablo-J-Rogina said in Translations - How to add a context in Linguist from an id-based translation?:

    what if you use the qsTranslate() function, using context and the text Id instead of the string

    In fact I tried, but this solution doesn't work, unfortunately, because I need to declare that I use IDs instead of strings while .ts files are updated with lupdate.exe. In a such context, all functions which are not intended to be used with IDs are discarded, and as a result I get errors in the console, and my string isn't added to the .ts translation file, as you can see below:
    76f3bd75-264f-4c98-8fdd-50662049152e-image.png

    For that reason I need a kind of function which is specifically compatible with the IDs system, and which supports the contexts.


  • Moderators

    @jeanmilost I don't think I quite understand your situation.

    If I understand you correctly, you want to use qsTrId for translations

    Text { text: qsTrId("hello_id") }
    

    and add additional context for the translator.

    According to the documentation, you could do that via:

    //% <string>
    

    or

    \begincomment% <string> \endcomment
    

    ->

    Text {
        //% "hello"
        text: qsTrId("hello_id")
    }
    

    taken from here:
    https://doc.qt.io/qt-5/qml-qtqml-qt.html#qsTrId-method



  • @J-Hilk said in Translations - How to add a context in Linguist from an id-based translation?:

    According to the documentation, you could do that via:
    //% <string>

    or
    \begincomment% <string> \endcomment

    In fact I already use these special comments, at least the first one (//%) but their purpose is other for me. AFAIK they are used to show the source text the ID represents, which will be used by the translator to translate the final text, as you can see on the screenshot below:
    79e56bd2-8581-4ada-b571-37874c1959be-image.png

    But my purpose is to add a context, in addition to the source text and the developer comment, which will appear in Linguist on the left column, and thus to differentiate group of texts, as it's possible with the qrTranslation() function.

    NOTE I'm aware that the notion of context may be unclear in Qt Translations, because it may designate several different things.

    NOTE The second comment (/begincomment /endcomment) just doesn't work for me, or I don't know how to use it (the documentation is very unclear about it). Have you a working example about how to use it?


Log in to reply