[PyKDE] Phil: Any chance of getting the TR (translate) method
working?
Phil Thompson
phil at river-bank.demon.co.uk
Sun Sep 2 19:06:27 BST 2001
Boudewijn Rempt wrote:
>
> On Fri, 31 Aug 2001, Phil Thompson wrote:
>
> > Boudewijn Rempt wrote:
> > >
> > > On Thursday 02 August 2001 00:31, Phil Thompson wrote:
> > > > Bryan Brunton wrote:
> > > > > (Reposting due to no response from previous post)
> > > > >
> > > > > Does anyone have the QObject.tr() method working?
> > > > >
> > > > > You can use the .qm file from the QT 2.3.1 i8ln example to test the code
> > > > > down below. The QApplication.translate method will correctly translate.
> > > > > The tr method of the MyWidget object will not.
> > > >
> > > > Which version of PyQt? It's broken in 2.4 but should be fixed in the 2.5
> > > > pre-releases. (But note that the 2.5 releases will only compile against
> > > > Qt 2.3.1 - but that has been fixed in the CVS.)
> > > >
> > > > Phil
> > > >
> > > >
> > >
> > > I'm now also working on this topic, and I found that even with PyQt 2.5,
> > > the tr function doesn't work - a bit of a wrench, since that's the last bit
> > > I need to finish the last-but-one chapter of Part III!
> >
> > Hmm, I tested 2.5 with the test case that Bryan provided and it seemed
> > to work Ok. Do you have a test case that demonstrates the problem?
> >
>
> I used exactly the same testcase - but did you remove the app.translate
> line? That one was meant just to show that the translate() function
> worked, but the tr not:
>
> import sys
> from qt import *
>
> class MyWidget(QMainWindow):
> def __init__(self):
> QMainWindow.__init__(self,None,'',Qt.WDestructiveClose)
> self.setCaption( self.tr("Internationalization Example" ) );
>
> if __name__ == '__main__':
> a = QApplication(sys.argv)
> QObject.connect(a,SIGNAL('lastWindowClosed()'),a,SLOT('quit()'))
>
> translator = QTranslator(None)
> translator.load( "mywidget_fr.qm", "." )
> a.installTranslator( translator )
>
> print(translator.contains("MyWidget", "Internationalization Example"))
> print(QTextCodec.locale())
> w = MyWidget()
> # comment this one out to actually test the problem
> #w.setCaption(a.translate("MyWidget", "Internationalization Example"))
> a.setMainWidget(w)
> w.show()
> a.exec_loop()
The equivalent C++ program (attached) does exactly the same thing - so
(if there is a bug) I'm not convinced it is with PyQt.
Phil
-------------- next part --------------
#include <stdio.h>
#include <qapplication.h>
#include <qtranslator.h>
#include <qmainwindow.h>
class MyWidget : public QMainWindow
{
public:
MyWidget() : QMainWindow()
{
setCaption(tr("Internationalization Example"));
}
};
int main(int argc,char **argv)
{
QApplication *a = new QApplication(argc,argv);
QObject::connect(a,SIGNAL(lastWindowClosed()),a,SLOT(quit()));
QTranslator *translator = new QTranslator(a);
translator -> load("mywidget_fr.qm",".");
a -> installTranslator(translator);
printf("%d\n",translator -> contains("MyWidget","Internationalization Example"));
MyWidget *w = new MyWidget();
// comment this one out to show what should happen
//w -> setCaption(a -> translate("MyWidget","Internationalization Example"));
a -> setMainWidget(w);
w -> show();
a -> exec();
}
More information about the PyQt
mailing list