From 701f91e4fed443aaa52f0199ce4a73f66c4fad74 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 5 Jan 2016 23:41:30 -0800 Subject: [PATCH] Try harder to find the language name that includes country code It seems that the first language in the list of languages isn't always the one that specifies the country code. So try the first three to see which one is the first to contain a country code. Signed-off-by: Dirk Hohndel --- subsurface-core/qthelper.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/subsurface-core/qthelper.cpp b/subsurface-core/qthelper.cpp index bddfd7608..b89fac4c3 100644 --- a/subsurface-core/qthelper.cpp +++ b/subsurface-core/qthelper.cpp @@ -839,8 +839,16 @@ QString uiLanguage(QLocale *callerLoc) } else { loc = QLocale(QLocale().uiLanguages().first()); } - - QString uiLang = loc.uiLanguages().first(); + QStringList languages = loc.uiLanguages(); + QString uiLang; + if (languages[0].contains('-')) + uiLang = languages[0]; + else if (languages.count() > 1 && languages[1].contains('-')) + uiLang = languages[1]; + else if (languages.count() > 2 && languages[2].contains('-')) + uiLang = languages[2]; + else + uiLang = languages[0]; GET_BOOL("time_format_override", time_format_override); GET_BOOL("date_format_override", date_format_override); GET_TXT("time_format", time_format); @@ -852,7 +860,13 @@ QString uiLanguage(QLocale *callerLoc) if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) { QLocale loc2(loc.bcp47Name()); loc = loc2; - uiLang = loc2.uiLanguages().first(); + QStringList languages = loc2.uiLanguages(); + if (languages[0].contains('-')) + uiLang = languages[0]; + else if (languages.count() > 1 && languages[1].contains('-')) + uiLang = languages[1]; + else if (languages.count() > 2 && languages[2].contains('-')) + uiLang = languages[2]; } if (callerLoc) *callerLoc = loc;