This is an automated email from the git hooks/post-receive script. x2go pushed a change to branch bugfix/translation in repository x2goclient. from 5f6565f Upgrade bundled VcXsrv from 1.15.2.6 to 1.17.0.0-1 new 36c2dd5 onmainwindow.cpp: follow-up to last translation fix. The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Summary of changes: debian/changelog | 2 ++ src/onmainwindow.cpp | 84 ++++++++++++++++++++++++++++++++++---------------- src/onmainwindow.h | 19 ++++++++++++ 3 files changed, 79 insertions(+), 26 deletions(-) -- Alioth's /srv/git/code.x2go.org/x2goclient.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2goclient.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch bugfix/translation in repository x2goclient. commit 36c2dd5c91a648f64a7219b8be66750be9e1fcbc Author: Mihai Moldovan <ionic@ionic.de> Date: Mon May 11 06:21:13 2015 +0200 onmainwindow.cpp: follow-up to last translation fix. Actually handle English locales correctly and don't duplicate code too much. --- debian/changelog | 2 ++ src/onmainwindow.cpp | 84 ++++++++++++++++++++++++++++++++++---------------- src/onmainwindow.h | 19 ++++++++++++ 3 files changed, 79 insertions(+), 26 deletions(-) diff --git a/debian/changelog b/debian/changelog index bd47e24..71c6316 100644 --- a/debian/changelog +++ b/debian/changelog @@ -382,6 +382,8 @@ x2goclient (4.0.4.0-0x2go1) UNRELEASED; urgency=low - config_win.bat: enable release by default, fetch command line parameter and compare against debug. Enable debug and console features in that case. + - onmainwindow.cpp: follow-up to last translation fix. Actually handle + English locales correctly and don't duplicate code too much. [ Fernando Pedemonte ] * New upstream release (4.0.4.0): diff --git a/src/onmainwindow.cpp b/src/onmainwindow.cpp index e5bea4b..c6d6a2e 100644 --- a/src/onmainwindow.cpp +++ b/src/onmainwindow.cpp @@ -546,56 +546,88 @@ void ONMainWindow::slotSyncX() } -void ONMainWindow::installTranslator () { - QTranslator *x2goclientTranslator = new QTranslator (); +bool get_translator (QString file_name_start, QTranslator **translator) { + QTranslator *tmp_translator = new QTranslator (); /* Qt 4.8.0 introduced a new overload for QTranslator::load(), taking a QLocale * object and loading up the UI language. * Additionally, a lower-cased version is automatically added to the search * list on case-sensitive file systems. - * We still need the original "compat" version for Qt < 4.8.0, though. + * We still need to iterate over the UI languages list in case an English + * locale is in there. As we do not ship a nop-English translation, loading + * an English translation will always fail and the next language in the list + * be preferred. + * We also still need the original "compat" version for Qt < 4.8.0. */ - QString filename = QString (":/i18n/x2goclient"); + QString filename = file_name_start; + QStringList ui_languages; #if QT_VERSION < 0x040800 filename = QString (filename + "_%1" ).arg (QLocale::system ().name ()); filename = filename.toLower (); -#endif +#else /* QT_VERSION < 0x040800 */ + ui_languages = QLocale::uiLanguages (); +#endif /* QT_VERSION < 0x040800 */ #if QT_VERSION < 0x040800 - if (!x2goclientTranslator->load (filename)) { -#else - if (!x2goclientTranslator->load (QLocale::system (), filename, "_")) { -#endif - x2goWarningf (1) << tr ("Can't load translator: ") + filename.toAscii (); + if (tmp_translator->load (filename)) { + *translator = tmp_translator; + x2goInfof (4) << tr ("Translator: ") + filename.toAscii () + tr (" found."); + return (true); } else { - QCoreApplication::installTranslator (x2goclientTranslator); - x2goInfof (4) << tr ("Translator: ") + filename.toAscii () + tr (" installed."); + x2goWarningf (1) << tr ("Can't load translator: ") + filename.toAscii (); + return (false); } +#else /* QT_VERSION < 0x040800 */ + QString load_filename = ""; + bool translator_found = false; + for (QStringList::const_iterator it = ui_languages.constBegin (); it != ui_languages.constEnd (); ++it) { + /* Respect English locales. Don't try to load any translation, because we do not ship nop-English translations. */ + if (*it.startsWith ("en") { + x2goWarningf (1) << tr ("English language requested, not loading translator"); + break; + } + else { + load_filename = filename.append ("_").append (*it); + if (tmp_ranslator->load (load_filename) { + /* Some translation successfully loaded. That's good enough. */ + x2goInfof (4) << tr ("Translator: ") + load_filename.toAscii () + tr (" found."); + translator_found = true; + *translator = tmp_translator; + break; + } + else { + x2goWarningf (1) << tr ("Non-fatal: can't load translator: ") + load_filename.toAscii (); + x2goWarningf (1) << tr ("Trying to load language with lower preference, if existent."); + } + } + } - QTranslator *qtTranslator = new QTranslator (); + return (translator_found); +#endif /* QT_VERSION < 0x040800 */ +} - filename = QString (":/i18n/qt"); -#if QT_VERSION < 0x040800 - filename = QString (filename + "_%1" ).arg (QLocale::system ().name ()); - filename = filename.toLower (); -#endif +void ONMainWindow::installTranslator () { + QTranslator *x2goclientTranslator = new QTranslator (); -#if QT_VERSION < 0x040800 - if (!qtTranslator->load (filename)) { -#else - if (!qtTranslator->load (QLocale::system (), filename, "_")) { -#endif - x2goWarningf (2) << tr ("Can't load translator: ") + filename.toAscii (); + bool translator_found = get_translator (QString (":/i18n/x2goclient"), &x2goclientTranslator); + + if (translator_found) { + QCoreApplication::installTranslator (x2goclientTranslator); } - else { + + QTranslator *qtTranslator = new QTranslator (); + + translator_found = get_translator (QString (":/i18n/qt"), &qtTranslator); + + if (translator_found) { QCoreApplication::installTranslator (qtTranslator); - x2goInfof (5) << tr ("Translator: ") + filename.toAscii () + tr (" installed."); } } + void ONMainWindow::initWidgetsEmbed() { #ifdef CFGPLUGIN diff --git a/src/onmainwindow.h b/src/onmainwindow.h index c54d549..10fb353 100644 --- a/src/onmainwindow.h +++ b/src/onmainwindow.h @@ -964,6 +964,25 @@ private: QMenu* initTrayAppMenu(QString text, QPixmap icon); void setTrayIconToSessionIcon(QString info); + /* + * Tries to get the most suitable translator for the running system. + * + * The first parameter file_name_start denotes the start of a potential + * translation file name. Locale values will be appended to this. + * + * On Qt 4.7 and lower, only tries to fetch a translator for the + * main language as returned by QLocale::system(). + * On Qt 4.8 and higher, tries to fetch the first available translator + * for the list returned by QLocale::uiLanguages(). + * + * If no translator is available OR the best available translator + * is for an English locale, returns false and doesn't touch + * the passed translator object. + * Otherwise returns true and sets the translator object to loaded + * translation. + */ + bool get_translator (QString file_name_start, QTranslator **translator); + protected: virtual void closeEvent ( QCloseEvent* event ); -- Alioth's /srv/git/code.x2go.org/x2goclient.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2goclient.git