[PyQt] pyuic ignores translation comments

Phil Thompson phil at riverbankcomputing.com
Fri Dec 31 17:43:53 GMT 2010


On Fri, 31 Dec 2010 16:20:07 +0100, Sebastian Wiesner
<lunaryorn at googlemail.com> wrote:
> Hello,
> 
> the C++ "uic" extracts the value of the "comment" of "string"
> properties in UI files, and uses it as third argument "disambiguation"
> in the generated C++ code.  However, in PyQt 4.8.2 "pyuic" and
> "uic.loadUi" apparently ignore this attribute, and instead to always
> pass "None" for this third argument.  According to the documentation
> of "QCoreApplication.translate()" this argument is used to
> disambiguate identical messages used in different contexts, so I
> guess, that this behaviour actually introduces translation bugs, if a
> single object contains two identical messages with different context.
> 
> It certainly leads to translation bugs in PyKDE, which uses gettext
> instead of Qt's message format.  The standard KDE gettext toolchain
> extracts the contents of the "comment" attribute and uses them as
> message context ("msgctxt" field in gettext catalog files).  Now
> gettext considers two identical messages with different contexts as
> two different messages, and even more, it identifies messages through
> the context and the message id.  So if a message has a context
> attached, the context *must* also be given, when loading the
> translation in the source code.  For instance, given a message "foo"
> with context "bar", the message *must* be loaded using "i18nc("bar",
> "foo")" (i18nc is the KDE function to load a message with context,
> where the context is the first argument).  If just "i18n("foo")" is
> used, the translation is *not* found (i18n is the KDE function to load
> a message without context).
> 
> As uic now simply ignores this contexts, all messages in UI files,
> which have a "comment" attached, are incorrectly loaded in KDE
> applications, and consequently it can happen, that large parts of the
> user interface file simply remain untranslated.  I hit this bug in my
> program "synaptiks", and was forced to dig into the uic code and write
> a workaround [1], which modifies "uic" in such a way, that it respects
> the comments.  Concerning the implementation, "tr2i18n" is nothing
> special.  The line "return tr2i18n(text, comment)" could be replaced
> with "QtGui.QApplication.translate(self.uiname, text, comment.
> QtGui.QApplication.UnicodeUTF8)", I'm just using "tr2i18n", because it
> is shorter, and because it is the function, KDE uses in compiled UI
> files.
> 
> I consider this a bug in PyQt4.uic and I'd like to see it fixed.  Any
> other comments?
> 
> [1]
https://github.com/lunaryorn/synaptiks/blob/master/synaptiks/kde/uic.py

Should be fixed in tonight's snapshot.

Thanks,
Phil


More information about the PyQt mailing list