diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-10-10 12:26:03 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-10-10 13:00:23 -0700 |
commit | 8bd26af44e03d20659ac76f927479713e14fad15 (patch) | |
tree | 45e236414e1f746a4a16cca70d871d5fced998cb /qt-gui.cpp | |
parent | 3b691d5d6e9e4f90cac806cccc151637f13c4ad5 (diff) | |
download | subsurface-8bd26af44e03d20659ac76f927479713e14fad15.tar.gz |
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 <dirk@hohndel.org>
Diffstat (limited to 'qt-gui.cpp')
-rw-r--r-- | qt-gui.cpp | 14 |
1 files 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; } } |