From: ThorstenB Date: Wed, 18 Apr 2012 13:43:42 +0000 (+0200) Subject: Be more tolerant about locale name when detecting the default language, X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=201d9d78529ea096af3d2e407555229aeece9ffe;p=flightgear.git Be more tolerant about locale name when detecting the default language, i.e. consider the German resource provided for "de_DE" or "de" when locale name is "de_DE.utf8". --- diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 8f1141c26..6c255bdc1 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -149,6 +149,24 @@ string fgBasePackageVersion() { return version; } +// +// Select the proper language based on the given locale/language name. +// +static SGPropertyNode* findLocale(SGPropertyNode *intl, const char* language) +{ + vector localeList = intl->getChildren("locale"); + for (unsigned int i = 0; i < localeList.size(); i++) { + + vector lang = localeList[i]->getChildren("lang"); + for (unsigned int j = 0; j < lang.size(); j++) { + + if (!strcmp(lang[j]->getStringValue(), language)) { + return localeList[i]; + } + } + } + return NULL; +} // Initialize the localization SGPropertyNode *fgInitLocale(const char *language) { @@ -161,20 +179,20 @@ SGPropertyNode *fgInitLocale(const char *language) { if (!intl) return NULL; - // - // Select the proper language from the list - // - vector locale = intl->getChildren("locale"); - for (unsigned int i = 0; i < locale.size(); i++) { - - vector lang = locale[i]->getChildren("lang"); - for (unsigned int j = 0; j < lang.size(); j++) { - - if (!strcmp(lang[j]->getStringValue(), language)) { - c_node = locale[i]; - break; - } - } + c_node = findLocale(intl, language); + if (!c_node) + { + /* be tolerant about locale names, i.e. instead of "de_DE.utf8" also + * consider "de_DE" ... */ + string l = language; + size_t pos = l.find("."); + if ((pos != string::npos)&&(pos>0)) + c_node = findLocale(intl, l.substr(0, pos).c_str()); + + /* finally consider country alone, i.e. "de" */ + pos = l.find("_"); + if ((!c_node)&&(pos != string::npos)&&(pos>0)) + c_node = findLocale(intl, l.substr(0, pos).c_str()); }