Qt-interest Archive, June 2007
tr() and static fields
Message 1 in thread
Hello,
I'm trying to create a class that would contain all my translatable strings
in static QString fields like so:
In the header file:
const static QString NO;
Then in the source file:
const QString strings::NO(tr("No"));
I can run lupdate on the source file and I see my string to translate, and
the translator seems to load and install fine, but I don't get my
translation, only the untranslated text, either displayed on a widget or
printed on the console.
Is what I'm trying to do possible? The only way I can get a translation to
show up is if the tr() call is in the code that displays it like (on a
QLabel) setText(tr("No")).
Thanks in advance.
Derek
--
[ signature omitted ]
Message 2 in thread
This is probably because your application (and with it the "desired"
language) isn't set up yet when your static variable initializers are
called (remember, this is before main() is called).
But i think you might find it much easier to just do it "the Qt way",
i.e. just call tr() everywhere when you need translated texts.
(the performance loss should usually be affordable)
Cheers,
Peter
> Hello,
>
> I'm trying to create a class that would contain all my translatable
> strings
> in static QString fields like so:
>
> In the header file:
> const static QString NO;
>
> Then in the source file:
> const QString strings::NO(tr("No"));
>
> I can run lupdate on the source file and I see my string to translate,
and
> the translator seems to load and install fine, but I don't get my
> translation, only the untranslated text, either displayed on a widget
or
> printed on the console.
>
> Is what I'm trying to do possible? The only way I can get a
translation to
> show up is if the tr() call is in the code that displays it like (on a
> QLabel) setText(tr("No")).
>
> Thanks in advance.
> Derek
--
[ signature omitted ]
Message 3 in thread
Rather then making it a static table... Why not make it an QObject
derived class that contains a const to the strings is setup at runtime.
This way when the change in language is done, your sure the correct
signals and slots occur.
Scott
> -----Original Message-----
> From: Baker, Derek [mailto:Derek-Baker@xxxxxxxxx]
> Sent: Tuesday, June 05, 2007 7:28 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: tr() and static fields
>
> Hello,
>
> I'm trying to create a class that would contain all my translatable
> strings
> in static QString fields like so:
>
> In the header file:
> const static QString NO;
>
> Then in the source file:
> const QString strings::NO(tr("No"));
>
> I can run lupdate on the source file and I see my string to translate,
and
> the translator seems to load and install fine, but I don't get my
> translation, only the untranslated text, either displayed on a widget
or
> printed on the console.
>
> Is what I'm trying to do possible? The only way I can get a
translation to
> show up is if the tr() call is in the code that displays it like (on a
> QLabel) setText(tr("No")).
>
> Thanks in advance.
> Derek
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 4 in thread
Could you give an example of that? I'm not sure I follow.
Thanks for your time.
Derek
-----Original Message-----
From: Scott Aron Bloom [mailto:scott@xxxxxxxxxxxx]
Sent: Tue 6/5/2007 10:47 AM
To: Baker, Derek; qt-interest@xxxxxxxxxxxxx
Subject: RE: tr() and static fields
Rather then making it a static table... Why not make it an QObject
derived class that contains a const to the strings is setup at runtime.
This way when the change in language is done, your sure the correct
signals and slots occur.
Scott
> -----Original Message-----
> From: Baker, Derek [mailto:Derek-Baker@xxxxxxxxx]
> Sent: Tuesday, June 05, 2007 7:28 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: tr() and static fields
>
> Hello,
>
> I'm trying to create a class that would contain all my translatable
> strings
> in static QString fields like so:
>
> In the header file:
> const static QString NO;
>
> Then in the source file:
> const QString strings::NO(tr("No"));
>
> I can run lupdate on the source file and I see my string to translate,
and
> the translator seems to load and install fine, but I don't get my
> translation, only the untranslated text, either displayed on a widget
or
> printed on the console.
>
> Is what I'm trying to do possible? The only way I can get a
translation to
> show up is if the tr() call is in the code that displays it like (on a
> QLabel) setText(tr("No")).
>
> Thanks in advance.
> Derek
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 5 in thread
NP... this is being done in outlook, so I have no idea if it will work
:) And DO NOT try to get it to compile directly... I haven't had my
morning coffee yet...
I had thought about the same problem, primarily, its way too easy to
have a typo in your tr code, and not get it translated, or not running
lupdate correctly (more of a problem in 3.X days)
In your header, something like
class CLanguageTable : public QObject
{
Public:
static CLanguageTable * table( QObject * parent = NULL );
QString No() const;
QString Yes() const;
Private:
CLanguageTable( QObject * parent = NULL );
CLanguageTable * mTable;
};
In your cpp file
CLanugageTable::CLanugageTable ( QObject * parent = NULL ) :
QObject( parent )
{
}
CLanugageTable * CLanugageTable::table( QObject * parent = NULL )
{
If ( ! mTable )
mTable = new CLanguageTable( parent );
return mTable;
}
CLanugageTable::No() const
{
return tr( "No" );
}
CLanugageTable::Yes() const
{
return tr( "Yes" );
}
Then rather then calling tr directly, you would call
CLanguageTable::table()->No()
I would call the table function with the app as the parent some where in
main.
Hope this helps.
Scott
> -----Original Message-----
> From: Baker, Derek [mailto:Derek-Baker@xxxxxxxxx]
> Sent: Tuesday, June 05, 2007 7:50 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: RE: tr() and static fields
>
> Could you give an example of that? I'm not sure I follow.
>
> Thanks for your time.
> Derek
>
>
> -----Original Message-----
> From: Scott Aron Bloom [mailto:scott@xxxxxxxxxxxx]
> Sent: Tue 6/5/2007 10:47 AM
> To: Baker, Derek; qt-interest@xxxxxxxxxxxxx
> Subject: RE: tr() and static fields
>
> Rather then making it a static table... Why not make it an QObject
> derived class that contains a const to the strings is setup at
runtime.
>
> This way when the change in language is done, your sure the correct
> signals and slots occur.
>
> Scott
>
> > -----Original Message-----
> > From: Baker, Derek [mailto:Derek-Baker@xxxxxxxxx]
> > Sent: Tuesday, June 05, 2007 7:28 AM
> > To: qt-interest@xxxxxxxxxxxxx
> > Subject: tr() and static fields
> >
> > Hello,
> >
> > I'm trying to create a class that would contain all my translatable
> > strings
> > in static QString fields like so:
> >
> > In the header file:
> > const static QString NO;
> >
> > Then in the source file:
> > const QString strings::NO(tr("No"));
> >
> > I can run lupdate on the source file and I see my string to
translate,
> and
> > the translator seems to load and install fine, but I don't get my
> > translation, only the untranslated text, either displayed on a
widget
> or
> > printed on the console.
> >
> > Is what I'm trying to do possible? The only way I can get a
> translation to
> > show up is if the tr() call is in the code that displays it like (on
a
> > QLabel) setText(tr("No")).
> >
> > Thanks in advance.
> > Derek
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
with
> > "unsubscribe" in the subject or the body.
> > List archive and information:
http://lists.trolltech.com/qt-interest/
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]