From 8bd26af44e03d20659ac76f927479713e14fad15 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Thu, 10 Oct 2013 12:26:03 -0700 Subject: [PATCH] Work around a Qt Locale bug on Mac With Qt4.8.5 Locale::uiLanguages() sometimes doesn't return the country, just the language. This works around this by recreating the locale if this has happened. Signed-off-by: Dirk Hohndel --- qt-gui.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/qt-gui.cpp b/qt-gui.cpp index e0cff0b2b..30afebed9 100644 --- a/qt-gui.cpp +++ b/qt-gui.cpp @@ -87,21 +87,29 @@ void init_ui(int *argcp, char ***argvp) xslt_path = strdup(getSubsurfaceDataPath("xslt").toAscii().data()); QLocale loc; + QString uiLang = loc.uiLanguages().first(); + // there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info + if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) { + QLocale loc2(loc.bcp47Name()); + loc = loc2; + uiLang = loc2.uiLanguages().first(); + } + // we don't have translations for English - if we don't check for this // Qt will proceed to load the second language in preference order - not what we want // on Linux this tends to be en-US, but on the Mac it's just en - if (!loc.uiLanguages().first().startsWith("en")) { + if (!uiLang.startsWith("en")) { qtTranslator = new QTranslator; if (qtTranslator->load(loc,"qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { application->installTranslator(qtTranslator); } else { - qDebug() << "can't find Qt localization for locale" << loc.uiLanguages().first(); + qDebug() << "can't find Qt localization for locale" << uiLang; } ssrfTranslator = new QTranslator; if (ssrfTranslator->load(loc,"subsurface", "_")) { application->installTranslator(ssrfTranslator); } else { - qDebug() << "can't find Subsurface localization for locale" << loc.uiLanguages().first(); + qDebug() << "can't find Subsurface localization for locale" << uiLang; } }