Lrelease optimization: removal of unused translation
-
Hi All,
Good day, I am very new to QT and have a question about lrelease.
Currently, we have our own tool that generates TS files from a string database, all strings from this database and its translations are copied to the TS files. My question is, does lrelease has option to automatically excludes unused strings when generating the QM files?
Thank you very much
-
Hi @ozbum
What do you mean by unused strings? do mean that they do not need to be translated ?
with qt linguist when you need to translate a string you need to write it on your .cpp file in this way :
tr("your string");
if string does not need to be translated you have to wirte it without tr , just like this :
("your string");
then when
lupdate
will be executed he will search all strings marked with tr() and will on put it on your .ts fileAlso string that was used in the past , and that become no more used on the context can be marked obsolete , on your .ts file like this:
<message> <location filename="your source or ui file" line="190"/> <source>text need to translate</source> <translation type="obsolete">your translated text</translation> </message>
Or obsolete text will be ignored by
lrelease
,this can done automatically with qt linguist hmi assistant ,
I advise you to read more in this part of qt linguist doc :
for qt 4:
http://doc.qt.io/qt-4.8/linguist-translators.html#strings-window
for qt 5:
http://doc.qt.io/qt-5/linguist-translators.html#selecting-context-to-translate
Hope this will answer to your question
-
Hi Mostefa,
Thnak you for replying to my question.
All strings are translated by our in-house tool (we are not using QT Linguist) and all of them are generated in the TS file. The problem is, not all strings are needed by the application. Is there a way to exclude unused strings when generating the QM file? Please note that the custom TS generator does not know which string is being use by the application that is why all strings are generated in the TS file. Can't mark strings as obsolete because another application may be using it.
Regards,
-
Personally I would open a command prompt and use something like that:
lupdate.exe "MyProjDir" -ts "MyProjDir\myapp_fr_CH.ts" "MyProjDir\myapp_pt_BR.ts" "MyProjDir\myapp_ja.ts" -no-obsoleteThus all files containing strings to translate in my project directory will be updated in my .ts files (in this case the FR_CH, PT_BR and JP languages), but all the strings which are not included in my project will be discarded from the .tr files by the -no-obsolete option.
And only then, I would call the lresease tool.