core/Translator.cpp
changeset 663 b526b82e256e
parent 661 5c0988b9bf0c
child 664 41cd24906383
     1.1 --- a/core/Translator.cpp	Thu Apr 05 03:16:03 2007 +0000
     1.2 +++ b/core/Translator.cpp	Thu Apr 05 05:25:11 2007 +0000
     1.3 @@ -604,15 +604,30 @@
     1.4  	delete m_pStringTab;
     1.5  }
     1.6  
     1.7 -CoreConfigErr Translator::OnSourceModConfigChanged(const char *option, const char *value)
     1.8 +ConfigResult Translator::OnSourceModConfigChanged(const char *key, 
     1.9 +									  const char *value, 
    1.10 +									  ConfigSource source, 
    1.11 +									  char *error, 
    1.12 +									  size_t maxlength)
    1.13  {
    1.14 -	if (strcasecmp(option, "ServerLang") == 0)
    1.15 +	if (strcasecmp(value, "ServerLang") == 0)
    1.16  	{
    1.17 +		if (source == ConfigSource_Console)
    1.18 +		{
    1.19 +			unsigned int index;
    1.20 +			if (!GetLanguageByCode(value, &index))
    1.21 +			{
    1.22 +				UTIL_Format(error, maxlength, "Language code \"%s\" is not registered", value);
    1.23 +				return ConfigResult_Reject;
    1.24 +			}
    1.25 +		}
    1.26 +
    1.27  		strncopy(m_ServerLangCode, value, sizeof(m_ServerLangCode));
    1.28 -		return CoreConfig_Okay;
    1.29 +
    1.30 +		return ConfigResult_Accept;
    1.31  	}
    1.32  
    1.33 -	return CoreConfig_InvalidOption;
    1.34 +	return ConfigResult_Ignore;
    1.35  }
    1.36  
    1.37  void Translator::OnSourceModAllInitialized()
    1.38 @@ -837,7 +852,20 @@
    1.39  	return Trans_Okay;
    1.40  }
    1.41  
    1.42 -const char *Translator::GetServerLanguageCode() const
    1.43 +unsigned int Translator::GetServerLanguageCode()
    1.44  {
    1.45 -	return m_ServerLangCode;
    1.46 +	void *serverLang;
    1.47 +
    1.48 +	/* :TODO: there is absolutely no reason this shouldn't be cached
    1.49 +	 * I don't even know why it was returning a string originally
    1.50 +	 */
    1.51 +
    1.52 +	if (!sm_trie_retrieve(m_pLCodeLookup, m_ServerLangCode, &serverLang))
    1.53 +	{
    1.54 +		g_Logger.LogError("Server language was set to bad language \"%s\" -- reverting to English");
    1.55 +		strncopy(m_ServerLangCode, "en", sizeof(m_ServerLangCode));
    1.56 +		return 0;
    1.57 +	}
    1.58 +
    1.59 +	return (unsigned int)serverLang;
    1.60  }