Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.5.1
-
testing on Windows 7 configured for mingw compiler.
Description
If you us qsTr with the ID comment, all contexts of the same ID are joined together. lupdate thus favors the first context it finds (I think this might happen alphabetically by file name) all other uses of the same ID are added as Locations of use of the Message, and all seems well.
Until you add translations... In the example below foo.qml will always show the reference text for bar, because qsTr does not look in the baz context.
BUG:
in the example below, both foo and baz are listed as Locations where the "bar" Message is used. When the language is set to en_GB, baz.qml will show "pub" while foo.qml will show "bar", meaning foo.qml is not actually using the Message.
I suspect it is in-fact looking in it's default context of "foo" for the Message and not finding it, because the //=bar ID tag in foo gets grouped together with the other //=bar ID tag in baz and thus the message only exists in the baz context, yet qsTr will only look in the default "foo" context from foo.qml.
EXAMPLE:
//=bar
text = qsTr(bar);
//=bar
text = qsTr(bar);
run lupdate
<context> <name>baz</name> <message> <location filename="baz.qml" line=27"/> <location filename="foo.qml" line="24"/> <translation>bar</translation> </message> </context>
later get translations:
<context> <name>baz</name> <message> <location filename="baz.qml" line=27"/> <location filename="foo.qml" line="24"/> <translation>pub</translation> </message> </context>
WORK AROUND:
Its possible to use qsTranslate to specify the "baz" context from foo, although lupdate could choose any context as the first it sees for an ID (if it is done alphabetically a new class starting with "a" would become the new context for the ID). To be safe you would have to use qsTranslate everywhere that you use the ID comment, including foo.qml and baz.qml in the example above. If you use qsTranslate everywhere to define the context manually... Then what have you gained by using //= to add an ID?