I hope this is the right forum to ask this question. If it is not, please redirect me to a more suitable forum.
I am trying to understand the format of a Qt Linguist TS file. I have modified a file and when I try to open it I get the error message "Duplicate messages found in ...". The file contains indeed one context with two messages that have
- the same source
- a location with the same file name but different line numbers
- different translation
Here is the source code of a minimal file that gives this error:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="es">
<context>
<name>MyContext</name>
<message>
<location filename="../../../../../MyFile.cpp" line="605"/>
<source>Delete</source>
<translatorcomment>Menu option</translatorcomment>
<translation type="unfinished">&Borrar</translation>
</message>
<message>
<location filename="../../../../../MyFile.cpp" line="1572"/>
<source>Delete</source>
<translation>Eliminar</translation>
</message>
</context>
</TS>
To my knowledge, each message is identified by context, source and location so this should not be a problem because the line numbers are different. Notice also that you cannot combine the two message elements into one, because they contain different translation texts.
So it is not clear to me what can cause the error message. I am using Qt version 4.6.2. I have looked in the following documents: Qt Linguist Manual: Translator, Qt Linguist Manual: Programmers, Linguist TS file format, but in none of them I have found the information I am looking for, namely how each message is identified and what could cause the error message in Qt Linguist.
If you do not know the answer to this question, a link to further, more detailed information on the TS format would also be helpful.
UPDATE
I have found out that by using the optional tag TS/context/message/comment it is possible to have different translation texts for the same context/message/source, e.g.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="es">
<context>
<name>MyContext</name>
<message>
<location filename="../../../../../MyFile.cpp" line="605"/>
<source>Delete</source>
<comment>Comment 1</comment>
<translatorcomment>Menu option</translatorcomment>
<translation type="unfinished">&Borrar</translation>
</message>
<message>
<location filename="../../../../../MyFile.cpp" line="1572"/>
<source>Delete</source>
<comment>Comment 2</comment>
<translation>Eliminar</translation>
</message>
</context>
</TS>
The above file can be opened without errors.
This seems to solve my problem but it would be good to have some precise documentation about this format.
The error message reported by Qt linguist is meaningfull.
Try this modified version of your TS file:
Duplicates are identified by context (i.e. MyContext vs. MyOtherContext) and source (Delete).
Edit:
I have scrutinized Qt Linguist's source code. As far as I can tell it never make use of
ts.dtd
for validation purpose, everything is hardcoded (See the TSReader class in ts.cpp).The moral is: you can do every manipulation you want if and only if the resulting
ts
file can be loaded again by Qt Linguist and accepted by lupdate (to resync the application).