PDA

View Full Version : How to mark Property name in Q_PROPERTY for language change??



Ankitha Varsha
13th April 2010, 05:14
Hi,

We have tr(), QT_TRANSLATE_NOOP, QT_TR_NOOP for marking a string to be eligible for translation.

I am facing problem when I want to mark a property name for language change.

For ex:
Q_PROPERTY(QString Width READ width WRITE setWidth)

If I change the language to say German, the property name should actually be "Weite" and not "Width".

How can I mark the type name or property name for language change?

Regards,

JohannesMunk
13th April 2010, 11:08
I have never used translations before, so I can't be of big help. But have you looked at, how qt translates its ui-files? It uses QApplication::translate with some context. You could do the same. You probably would have to insert/mark the translations manually though, or find out how qt does that for UI-captions ..

What I can help you with, is, that "Width" translates to "Breite" in german. "Weite" is not used in that context.

Johannes

Ankitha Varsha
13th April 2010, 18:23
Hi Johannes,

Thanks for the reply.

I set lang to 'de' and launched the Designer to check whether the property names have been translated correctly to German.
I placed a pushbutton on the form and checked whether the property names are changed to German. Unfortunately, none of the property names are translated. But, when I expand any property, for example "Geometry", then the items under that( height and width )are translated to German. I am confused now.

Regards,
Ankitha

JohannesMunk
13th April 2010, 19:00
Mmh.. well that seems to be a problem in designer.. But still you could try and look up the sourcecode of designer to see how the subproperties get translated!

Why do you want to translate the properties anyway? Are you building a propertyeditor for the enduser? Or do you want to use the translated-properties in QtScript?

Good luck!

Johannes

Ankitha Varsha
14th April 2010, 05:53
Yeah, I want to provide a property editor to the end user.
I shall look into designer's code to check how subproperties get translated there.

wysota
14th April 2010, 12:14
Unfortunately, none of the property names are translated.
Property names can't be translated because they are identifiers. Just as you don't translate C++ keywords, variable and function names to german when you compile using a compiler with german locale.


But, when I expand any property, for example "Geometry", then the items under that( height and width )are translated to German.
That's because these are not properties but fields for property types that are interpreted by Designer (that's why they can be translated).

I would really advise against trying to override this behaviour unless you consider yourself an expert on Designer property sheet extensions and you will be the only one using the widget you wish to translate properties for (or your users will get a headache trying to reference a "breite" property in their code instead of "width".

JohannesMunk
14th April 2010, 12:23
Hi Wysota!

I think its not about using those translated properties in code, but to provide the end-user a runtime property editor for some objects. And this property editor shall use translated property names.

I suggested to use QCoreApplication::translate manually on each property name, when the property editor is populated. That would imply to manually add the translations..

Can you think of a more elegant way? At least to mark/make the required strings available to linguist..

Johannes

wysota
14th April 2010, 13:22
I think its not about using those translated properties in code, but to provide the end-user a runtime property editor for some objects.

To do it in a sane way you'd have to reprogram half of Designer. This is of course possible but it's much easier to use QtPropertyBrowser solution if you don't require the actual "design" capabilities of Designer.


Can you think of a more elegant way?
Yes, implement a "Designer Property Sheet Extension".


At least to mark/make the required strings available to linguist..

Linguist will happily use QT_TR_NOOP or strings from the property sheet extension.