Unsolved 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:
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()
orqsTranslate()
functions, but instead theqsTrId()
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:
For that reason I need a kind of function which is specifically compatible with the IDs system, and which supports the contexts.
-
@jeanmilost I don't think I quite understand your situation.
If I understand you correctly, you want to use
qsTrId
for translationsText { 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> \endcommentIn 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:
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?
-
Hi @jeanmilost ,
I've the same issue. Did you manage to get this done?