[PyQt] wrong context handling in pylupdate with inner classes
Matteo Bertini
naufraghi at develer.com
Mon Jan 20 11:48:50 GMT 2014
Hi all, I found a little bug in pylupdate, in case of inner classes the
generated ts files has the inner class as context.
Minimal example:
==> wrong_ts_context.py <==
class OuterClass(QObject):
def foo(self):
self.tr("in context OuterClass")
# comment with strange indentation
self.tr("in context OuterClass after comment with strange
indentation")
class _InnerClass(object):
pass
self.tr("in context OuterClass after _InnerClass")
==> wrong_ts_context.ts <==
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="2.0">
<context>
<name>OuterClass</name>
<message>
<location filename="wrong_ts_context.py" line="3"/>
<source>in context OuterClass</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="wrong_ts_context.py" line="5"/>
<source>in context OuterClass after comment with strange
indentation</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>_InnerClass</name>
<message>
<location filename="wrong_ts_context.py" line="10"/>
<source>in context OuterClass after _InnerClass</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
In big projects it is very hard to find the untranslated strings
because of this behaviour.
PySide fork of pylupdated used to have the same bug:
https://github.com/PySide/Tools/commit/365f37c4c2fef6226baf406576bd9f0d32d6d304
But it handles as indentation the comment lines too, resulting in a
different error:
==> wrong_ts_context.ts <==
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="2.0">
<context>
<name></name>
<message>
<location filename="wrong_ts_context.py" line="5"/>
<source>in context OuterClass after comment with strange
indentation</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="wrong_ts_context.py" line="10"/>
<source>in context OuterClass after _InnerClass</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>OuterClass</name>
<message>
<location filename="wrong_ts_context.py" line="3"/>
<source>in context OuterClass</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
I translated the fix in pyside adding a check for indent in comments,
the resulting diffs over 4.10.3 (and 5.2 without universal newline
backport) are attached.
==> wrong_ts_context.ts <==
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="2.0">
<context>
<name>OuterClass</name>
<message>
<location filename="wrong_ts_context.py" line="3"/>
<source>in context OuterClass</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="wrong_ts_context.py" line="5"/>
<source>in context OuterClass after comment with strange
indentation</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="wrong_ts_context.py" line="10"/>
<source>expected to be in context OuterClass but found in
_InnerClass</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Cheers,
Matteo Bertini
--
Matteo Bertini - naufraghi at develer.com
Develer S.r.l. - http://www.develer.com/
.hardware .software .innovation
Tel.: +39 055 3986627 - ext.: 211
-------------- next part --------------
A non-text attachment was scrubbed...
Name: backport-universal-newline.diff
Type: text/x-c++
Size: 4290 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140120/ec07d3b6/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-wrong-contex-with-inline-classes.diff
Type: text/x-c++
Size: 7951 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140120/ec07d3b6/attachment-0003.bin>
More information about the PyQt
mailing list