Changed: unsupported language code default fallback

--HG--
branch : compatibility-develop
hg/compatibility-develop
Inky 6 years ago
parent 377ed0152a
commit 63b58b0c84

@ -58,14 +58,14 @@ void CI18N::initLanguages()
_LanguageCodes.push_back("en"); _LanguageCodes.push_back("en");
_LanguageCodes.push_back("fr"); _LanguageCodes.push_back("fr");
_LanguageCodes.push_back("de"); _LanguageCodes.push_back("de");
// _LanguageCodes.push_back("ru"); _LanguageCodes.push_back("ru");
// _LanguageCodes.push_back("es"); _LanguageCodes.push_back("es");
_LanguageNames.push_back(ucstring("English")); _LanguageNames.push_back(ucstring("English"));
_LanguageNames.push_back(ucstring("French")); _LanguageNames.push_back(ucstring("French"));
_LanguageNames.push_back(ucstring("German")); _LanguageNames.push_back(ucstring("German"));
// _LanguageNames.push_back(ucstring("Russian")); _LanguageNames.push_back(ucstring("Russian"));
// _LanguageNames.push_back(ucstring("Spanish")); _LanguageNames.push_back(ucstring("Spanish"));
_LanguagesNamesLoaded = true; _LanguagesNamesLoaded = true;
} }

@ -2019,30 +2019,43 @@ void CClientConfig::init(const string &configFileName)
// now we can continue loading and parsing the config file // now we can continue loading and parsing the config file
// if the config file will be modified, it calls automatically the function setValuesOnFileChange() // if the config file will be modified, it calls automatically the function setValuesOnFileChange()
ClientCfg.ConfigFile.setCallback (CClientConfig::setValuesOnFileChange); ClientCfg.ConfigFile.setCallback (CClientConfig::setValuesOnFileChange);
// load the config files // load the config files
ClientCfg.ConfigFile.load (configFileName); ClientCfg.ConfigFile.load (configFileName);
CConfigFile::CVar *pCV;
// check language code is supported
pCV = ClientCfg.ConfigFile.getVarPtr("LanguageCode");
if (pCV)
{
std::string lang = pCV->asString();
if (!CI18N::isLanguageCodeSupported(lang))
{
nlinfo("Unsupported language code \"%s\" fallback on default", lang.c_str());
// fallback to default language
ClientCfg.LanguageCode = CI18N::getSystemLanguageCode();
// update ConfigFile variable
pCV->setAsString(ClientCfg.LanguageCode);
ClientCfg.ConfigFile.save();
}
}
// update the ConfigFile variable in the config file // update the ConfigFile variable in the config file
CConfigFile::CVar *varPtr = ClientCfg.ConfigFile.getVarPtr ("ClientVersion"); pCV = ClientCfg.ConfigFile.getVarPtr("ClientVersion");
if (varPtr) if (pCV)
{ {
string str = varPtr->asString (); std::string str = pCV->asString ();
if (str != getVersion() && ClientCfg.SaveConfig) if (str != getVersion() && ClientCfg.SaveConfig)
{ {
nlinfo ("Update and save the ClientVersion variable in config file %s -> %s", str.c_str(), getVersion().c_str()); nlinfo ("Update and save the ClientVersion variable in config file %s -> %s", str.c_str(), getVersion().c_str());
varPtr->setAsString (getVersion()); pCV->setAsString(getVersion());
ClientCfg.ConfigFile.save (); ClientCfg.ConfigFile.save();
} }
} }
else else
{
nlwarning ("There's no ClientVersion variable in the config file!"); nlwarning ("There's no ClientVersion variable in the config file!");
}
}// init // }// init //

Loading…
Cancel
Save