[PyKDE] Phil: Any chance of getting the TR (translate) method working?
Boudewijn Rempt
boud at rempt.xs4all.nl
Thu Aug 30 21:23:17 BST 2001
On Thursday 30 August 2001 21:00, Boudewijn Rempt wrote:
> On Thursday 02 August 2001 00:31, you 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
>
> Would it be possible to have pyuic generate tr() strings with double quotes
> around them? That would meant that the standard lupdate tool in Qt3/Qt
> Linguist would stand a fair chance of actually finding the strings - the
> single-quoted string pyuic produces are ignored...
>
Er, yes, it is possible: at least, this version of the fixString function
works:
// fixString is only used in conjunction with tr(). We need to write out the
// string in utf8 and make sure it's converted from utf8 when created.
static QString fixString( const QString &str )
{
QString s( str );
s.replace( QRegExp( "\\\\" ), "\\\\" );
s.replace( QRegExp( "\"" ), "\\\"" );
s.replace( QRegExp( "\n" ), "\\n" );
s.replace( QRegExp( "\r" ), "\\r" );
s.replace( QRegExp( "\"" ), "\\\"" );
bool onlyAscii = TRUE;
unsigned int i;
for ( i = 0; i < s.length(); i++ ) {
if ( s.at(i).unicode() >= 0x80 ) {
onlyAscii = FALSE;
break;
}
}
if ( onlyAscii )
s = "\"" + s + "\"";
else
s = "QString.fromUtf8(\"" + s + "\")";
return s;
}
More information about the PyQt
mailing list