1
0
Fork 0

Improve debug output

This commit is contained in:
ThorstenB 2012-05-08 23:04:53 +02:00
parent 0b7b0f16a8
commit de6ac7153d

View file

@ -41,7 +41,7 @@ FGLocale::~FGLocale()
{ {
} }
#ifdef HAVE_WINDOWS_H #ifdef _WIN32
/** /**
* Determine locale/language settings on Windows. * Determine locale/language settings on Windows.
* *
@ -62,14 +62,20 @@ FGLocale::getUserLanguage()
LOCALE_SISO639LANGNAME, LOCALE_SISO639LANGNAME,
locale, sizeof(locale))) locale, sizeof(locale)))
{ {
SG_LOG(SG_GENERAL, SG_INFO, "Detected locale's language setting: " << locale);
size_t i = strlen(locale); size_t i = strlen(locale);
locale[i++] = '_'; locale[i++] = '_';
if (GetLocaleInfo(LOCALE_USER_DEFAULT, if (GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SISO3166CTRYNAME, LOCALE_SISO3166CTRYNAME,
locale+i, (int)(sizeof(locale)-i))) locale+i, (int)(sizeof(locale)-i)))
return locale; return locale;
locale[--i] = 0;
SG_LOG(SG_GENERAL, SG_INFO, "Failed to detected locale's country setting.");
return locale;
} }
SG_LOG(SG_GENERAL, SG_INFO, "Failed to obtain Windows locale information.");
return NULL; return NULL;
} }
#else #else
@ -87,8 +93,6 @@ FGLocale::getUserLanguage()
SGPropertyNode* SGPropertyNode*
FGLocale::findLocaleNode(const string& language) FGLocale::findLocaleNode(const string& language)
{ {
SG_LOG(SG_GENERAL, SG_INFO, "Searching language resource for locale: " << language);
SGPropertyNode* node = NULL; SGPropertyNode* node = NULL;
// remove character encoding from the locale spec, i.e. "de_DE.utf8" => "de_DE" // remove character encoding from the locale spec, i.e. "de_DE.utf8" => "de_DE"
@ -100,15 +104,7 @@ FGLocale::findLocaleNode(const string& language)
return node; return node;
} }
// try country's default resource, i.e. "de_DE" => "de" SG_LOG(SG_GENERAL, SG_INFO, "Searching language resource for locale: " << language);
pos = language.find("_");
if ((pos != string::npos)&&(pos>0))
{
node = findLocaleNode(language.substr(0, pos));
if (node)
return node;
}
// search locale using full string // search locale using full string
vector<SGPropertyNode_ptr> localeList = _intl->getChildren("locale"); vector<SGPropertyNode_ptr> localeList = _intl->getChildren("locale");
@ -119,9 +115,21 @@ FGLocale::findLocaleNode(const string& language)
for (size_t j = 0; j < langList.size(); j++) for (size_t j = 0; j < langList.size(); j++)
{ {
if (!language.compare(langList[j]->getStringValue())) if (!language.compare(langList[j]->getStringValue()))
{
SG_LOG(SG_GENERAL, SG_INFO, "Found language resource for: " << language);
return localeList[i]; return localeList[i];
} }
} }
}
// try country's default resource, i.e. "de_DE" => "de"
pos = language.find("_");
if ((pos != string::npos)&&(pos>0))
{
node = findLocaleNode(language.substr(0, pos));
if (node)
return node;
}
return NULL; return NULL;
} }
@ -133,12 +141,15 @@ FGLocale::selectLanguage(const char *language)
{ {
// Use system setting when no language is given. // Use system setting when no language is given.
if ((language == NULL)||(language[0]==0)) if ((language == NULL)||(language[0]==0))
{
language = getUserLanguage(); language = getUserLanguage();
SG_LOG(SG_GENERAL, SG_INFO, "System language: " << ((language) ? language : "<unavailable>"));
}
// Use plain C locale if nothing is available. // Use plain C locale if nothing is available.
if ((language == NULL)||(language[0]==0)) if ((language == NULL)||(language[0]==0))
{ {
SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect the language" ); SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect system language" );
language = "C"; language = "C";
} }