Hi Pritpal,
I'm try to understand and use QT translation.
I assume we want write multi language programs, so QLocale and QTranslator are known about their usage...
anyway everyone can find useful
https://groups.google.com/forum/?hl=it&fromgroups#!searchin/qtcontribs/translation/qtcontribs/_VCn0rKbamQ/s-LMEureujcJAs I understand there are (basically) three way:
a) QApplication:translate( const char * context, const char * sourceText, const char * disambiguation, Encoding encoding, int n )
b) QObject:tr( const char * sourceText, const char * disambiguation = 0, int n = -1 )
c) QObject:trUtf8( const char * sourceText, const char * disambiguation = 0, int n = -1 )
Everyone of us can write his custom translation file .ts, below a little example:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="es">
<context>
<name>Global</name>
<message>
<source>File</source>
<translation>Fichero</translation>
</message>
</context>
</TS>
About
a) using HbQt can be like this:
LOCAL oLabel
WITH OBJECT oLabel := QLabel()
:setText( QApplication():translate( "Global", "File" ) )
....
END WITH
About
b) or
c) using HbQt can be like this:
LOCAL oLabel
WITH OBJECT oLabel := QLabel()
:setText( :tr( "File" ) ) or :setText( :trUtf8( "File" ) )
....
END WITH
But about
b) and c) there is a big problem:
AFAIK, QT uses the object className as reference / context, infact there isn't "const char * context" as parameter. In this scenario, with my .ts the translator fails.
Following QT docs, I must change context as below
<context>
<name>QLabel</name> But if you have more QLabel objects your program (most probably) shows wrong lable text.
Perhaps using <comment> tag this problem can be solved... but reading QT docs they often write "...using subclass...".
In this scenario, the HbQt class inheritance must work very fine. Why?1) I write .ts file as
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="es">
<context>
<name>myLabel1</name>
<message>
<source>File</source>
<translation>Fichero</translation>
</message>
</context>
<context>
<name>OtherLabel2</name>
<message>
<source>File</source>
<translation>Salir</translation>
</message>
</context>
</TS>2) I use classes
CREATE CLASS myLabel1 INHERIT hb_QLabel
...
CREATE CLASS OtherLabel2 INHERIT hb_QLabel
...3) I can write my program as
LOCAL oLabel1, oLabel2
WITH OBJECT oLabel1 := myLabel1():New()
:setText( :tr( "File" ) ) <<==>> you will see "Fichero"
....
END WITH
WITH OBJECT oLabel2 := OtherLabel2():New()
:setText( :tr( "File" ) ) <<==>> you will see "Salir"
....
END WITH First of all: can you confirm this behaviour?
If yes, we can have problems because (I remember) some objects have class inheritance problem (ie QTabWidget when inserTab used and the object is inherited from QWidget: always QWidget object is inserted and loose user object class name).
I hope is read as costructive post.Cheers
Luigi Ferraris