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".
This commit is contained in:
parent
516d92c077
commit
201d9d7852
1 changed files with 31 additions and 13 deletions
|
@ -149,6 +149,24 @@ string fgBasePackageVersion() {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Select the proper language based on the given locale/language name.
|
||||||
|
//
|
||||||
|
static SGPropertyNode* findLocale(SGPropertyNode *intl, const char* language)
|
||||||
|
{
|
||||||
|
vector<SGPropertyNode_ptr> localeList = intl->getChildren("locale");
|
||||||
|
for (unsigned int i = 0; i < localeList.size(); i++) {
|
||||||
|
|
||||||
|
vector<SGPropertyNode_ptr> 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
|
// Initialize the localization
|
||||||
SGPropertyNode *fgInitLocale(const char *language) {
|
SGPropertyNode *fgInitLocale(const char *language) {
|
||||||
|
@ -161,20 +179,20 @@ SGPropertyNode *fgInitLocale(const char *language) {
|
||||||
if (!intl)
|
if (!intl)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
//
|
c_node = findLocale(intl, language);
|
||||||
// Select the proper language from the list
|
if (!c_node)
|
||||||
//
|
{
|
||||||
vector<SGPropertyNode_ptr> locale = intl->getChildren("locale");
|
/* be tolerant about locale names, i.e. instead of "de_DE.utf8" also
|
||||||
for (unsigned int i = 0; i < locale.size(); i++) {
|
* 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());
|
||||||
|
|
||||||
vector<SGPropertyNode_ptr> lang = locale[i]->getChildren("lang");
|
/* finally consider country alone, i.e. "de" */
|
||||||
for (unsigned int j = 0; j < lang.size(); j++) {
|
pos = l.find("_");
|
||||||
|
if ((!c_node)&&(pos != string::npos)&&(pos>0))
|
||||||
if (!strcmp(lang[j]->getStringValue(), language)) {
|
c_node = findLocale(intl, l.substr(0, pos).c_str());
|
||||||
c_node = locale[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue