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>
This commit is contained in:
Dirk Hohndel 2013-10-10 12:26:03 -07:00
parent 3b691d5d6e
commit 8bd26af44e

View file

@ -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;
}
}