[PyKDE] Another translation question
Phil Thompson
phil at riverbankcomputing.co.uk
Wed Jul 5 22:07:59 BST 2006
On Wednesday 05 July 2006 6:07 pm, Andreas Pakulat wrote:
> On 05.07.06 17:28:59, Phil Thompson wrote:
> > On Thursday 29 June 2006 11:49 pm, Andreas Pakulat wrote:
> > > On 30.06.06 00:24:10, Andreas Pakulat wrote:
> > > > just had a look at generated code from pyuic4 and I'm curious:
> > > >
> > > > Shouldn't pyuic4 use
> > > > QtCore.QCoreApplication.translate(classname.objectName(),
> > > > <somestring>) in retranslateUi(self, classname)?
> > >
> > > Turns out it already does by redefining self.tr, however it's not
> > > completely right, because it uses self.uiname, which is the objectName
> > > of the class created.
> > >
> > > The attached classes uses self.toplevelWidget.uiclass for the context
> > > parameter. This makes translation of generated python code working and
> > > by this "workaround" you can translate ui-forms.
> >
> > Sorry for taking so long to get around to this...
> >
> > Can you remind me what problem this is trying to fix?
>
> The problem is: Translations extracted from the generated code of pyuic4
> don't work due to the "wrong" context. The context is set to the content
> of the <class> element in the ui file, however the classname of the
> generated class get's a Ui_ prepended, thus the translation file
> contains Ui_<classname> as context and the translation doesn't work.
>
> > Isn't changing the context name going to create problems sharing
> > translations between C++ and Python code?
>
> Indeed, that would be a problem. So maybe the right thing to do is to
> remove the Ui_ prefix from the classes when parsing a generated python
> file? If you always remove Ui_ from the classname to use the result as
> context for the translation file, you'll be in trouble when anybody
> wants to name his own classes Ui_foobar.
>
> Maybe an extra commandline parameter to use when listing generated
> python files, or pyuic4 could put a global variable into the generated
> code and pylupdate4 tries to read that?
>
> Or you could add the ui-parsing (btw, that patch from me needs an update
> then too, because I hardcoded a Ui_ prefix there) to pylupdate4 and
> forbid the parsing of generated python files via documentation. I guess
> that's the easiest solution.
I know what the root cause is - pylupdate isn't being clever enough when
parsing the code generated by pyuic. I'll fix it in the next day or two.
Phil
More information about the PyQt
mailing list