Results 1 to 5 of 5

Thread: LayoutDirection autodetection

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default LayoutDirection autodetection

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: LayoutDirection autodetection

    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.

  3. #3
    Join Date
    Jan 2006
    Posts
    371
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: LayoutDirection autodetection

    ... 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).

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: LayoutDirection autodetection

    Quote Originally Posted by wysota
    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.

    Quote Originally Posted by elcuco View Post
    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?

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: LayoutDirection autodetection

    From src/gui/kernel/qapplication.cpp:
    Qt Code:
    1. #ifndef QT_NO_TRANSLATION
    2. static bool qt_detectRTLLanguage()
    3. {
    4. return force_reverse ^
    5. QApplication::tr("QT_LAYOUT_DIRECTION",
    6. "Translate this string to the string 'LTR' in left-to-right"
    7. " languages or to 'RTL' in right-to-left languages (such as Hebrew"
    8. " and Arabic) to get proper widget layout.") == QLatin1String("RTL");
    9. }
    10. #endif
    To copy to clipboard, switch view to plain text mode 
    If you don't want to translate a separate qt_xy.ts, you can add
    Qt Code:
    1. QT_TRANSLATE_NOOP("QApplication", "QT_LAYOUT_DIRECTION")
    To copy to clipboard, switch view to plain text mode 
    to your app and translate it to either "LTR" or "RTL".
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    momesana (19th January 2008)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.