From 7ab4ba30412e012266f8ae5979ffbd31d3fab0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Fri, 27 Aug 2010 01:13:41 +0000 Subject: [PATCH] [GB.QT4] * BUG: Try to load translations better. git-svn-id: svn://localhost/gambas/trunk@3143 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.qt4/src/main.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/gb.qt4/src/main.cpp b/gb.qt4/src/main.cpp index 3d610dfc6..f6e12b286 100644 --- a/gb.qt4/src/main.cpp +++ b/gb.qt4/src/main.cpp @@ -142,7 +142,7 @@ GB_CLASS CLASS_SvgImage; static bool in_event_loop = false; static int _no_destroy = 0; -static QTranslator *qt = NULL; +static QTranslator *_translator = NULL; static bool _application_keypress = false; static GB_FUNCTION _application_keypress_func; static QWidget *_mouseGrabber = 0; @@ -622,6 +622,13 @@ static void QT_Init(void) init = true; } +static bool try_to_load_translation(QString &locale) +{ + return (!_translator->load(QString("qt_") + locale, QString(getenv("QTDIR")) + "/translations") + && !_translator->load(QString("qt_") + locale, QString("/usr/lib/qt4/translations")) + && !_translator->load(QString("qt_") + locale, QString("/usr/share/qt4/translations"))); +} + static void init_lang(QString locale, bool rtl) { int pos; @@ -629,16 +636,26 @@ static void init_lang(QString locale, bool rtl) pos = locale.lastIndexOf("."); if (pos >= 0) locale = locale.left(pos); - qt = new QTranslator(); - if (!qt->load(QString("qt") + locale, QString(getenv("QTDIR")) + "/translations") - && !qt->load(QString("qt") + locale, QString("/usr/lib/qt4/translations")) - && !qt->load(QString("qt") + locale, QString("/usr/share/qt4/translations"))) - { - qDebug("warning: unable to load Qt translation: %s", QT_ToUTF8(locale)); - } - else - qApp->installTranslator(qt); + _translator = new QTranslator(); + if (!try_to_load_translation(locale)) + goto __INSTALL_TRANSLATOR; + + pos = locale.lastIndexOf("_"); + if (pos >= 0) + { + locale = locale.left(pos); + if (!try_to_load_translation(locale)) + goto __INSTALL_TRANSLATOR; + } + + qDebug("warning: unable to load Qt translation: %s", QT_ToUTF8(locale)); + goto __SET_DIRECTION; + +__INSTALL_TRANSLATOR: + qApp->installTranslator(_translator); + +__SET_DIRECTION: if (rtl) qApp->setLayoutDirection(Qt::RightToLeft); }