PDA

View Full Version : LayoutDirection autodetection



momesana
19th January 2008, 04:32
Hi,
Is there a way to find out what layoutDirection best suits a translation file when loading it during programm execution?
Lets consider persian as a language. If I change the language of the application to persian, I want to the layoutDirection to be Qt::RightToLeft. The programm however should be able to deduce the suitable LayoutDirection from the provided *.qm file.
Is this possible?
Probably not but I wanted to know for sure.

thanx in advance

wysota
19th January 2008, 09:56
It is possible to determine that. QApplication does that, so you may been at its code to see how to run the check again or simply code the needed code to a place where you load new translations. But first check if this isn't done automatically.

elcuco
19th January 2008, 11:16
... and how does QApplication automatically detect the best layout direction...?

The best way I have seen, is by translating a meta-string and in RTL translations set it to RTL and in all other languages translate it to LTR. This is what KDE is doing and what Qt does (nothing is done automatically).

momesana
19th January 2008, 15:25
QApplication does that, so you may been at its code to see how to run the check again or simply code the needed code to a place where you load new translations. But first check if this isn't done automatically.
I will take a look at QApplications implementation. Can you please where specifically to look for that code? And it seems like it is not done automatically by Qt since after loading the persian *.qm file the layout direction is still the same. Furthermore there is no signal or whatever suggesting a LayoutDirection change that I could react to.



The best way I have seen, is by translating a meta-string and in RTL translations set it to RTL and in all other languages translate it to LTR. This is what KDE is doing and what Qt does (nothing is done automatically).

Could you elaborate on this? What do you mean by translating a meta-string? Maybe a piece of code to demonstrate that?

jpn
19th January 2008, 15:32
From src/gui/kernel/qapplication.cpp:


#ifndef QT_NO_TRANSLATION
static bool qt_detectRTLLanguage()
{
return force_reverse ^
QApplication::tr("QT_LAYOUT_DIRECTION",
"Translate this string to the string 'LTR' in left-to-right"
" languages or to 'RTL' in right-to-left languages (such as Hebrew"
" and Arabic) to get proper widget layout.") == QLatin1String("RTL");
}
#endif
If you don't want to translate a separate qt_xy.ts, you can add

QT_TRANSLATE_NOOP("QApplication", "QT_LAYOUT_DIRECTION")
to your app and translate it to either "LTR" or "RTL".