core/Translator.cpp
changeset 2340 d3f1f1676267
parent 2289 44045ead61cd
child 2478 1899f97aded6
     1.1 --- a/core/Translator.cpp	Sun Oct 05 04:06:18 2008 -0700
     1.2 +++ b/core/Translator.cpp	Sun Oct 05 04:08:48 2008 -0700
     1.3 @@ -152,6 +152,45 @@
     1.4  		g_Logger.LogError("[SM] Fatal error encountered parsing translation file \"%s\"", m_File.c_str());
     1.5  		g_Logger.LogError("[SM] Error (line %d, column %d): %s", states.line, states.col, msg);
     1.6  	}
     1.7 +
     1.8 +	const char *code;
     1.9 +	for (unsigned int i = 1; i < m_LangCount; i++)
    1.10 +	{
    1.11 +		if (!m_pTranslator->GetLanguageInfo(i, &code, NULL))
    1.12 +		{
    1.13 +			continue;
    1.14 +		}
    1.15 +
    1.16 +		g_SourceMod.BuildPath(Path_SM, 
    1.17 +			path,
    1.18 +			PLATFORM_MAX_PATH,
    1.19 +			"translations/%s/%s",
    1.20 +			code,
    1.21 +			m_File.c_str());
    1.22 +
    1.23 +		/* Speculatively load these. */
    1.24 +		if (!g_LibSys.PathExists(path))
    1.25 +		{
    1.26 +			continue;
    1.27 +		}
    1.28 +
    1.29 +		if ((err=textparsers->ParseFile_SMC(path, this, &states)) != SMCError_Okay)
    1.30 +		{
    1.31 +			const char *msg = textparsers->GetSMCErrorString(err);
    1.32 +			if (!msg)
    1.33 +			{
    1.34 +				msg = m_ParseError.c_str();
    1.35 +			}
    1.36 +
    1.37 +			g_Logger.LogError("[SM] Fatal error encountered parsing translation file \"%s/%s\"", 
    1.38 +				code, 
    1.39 +				m_File.c_str());
    1.40 +			g_Logger.LogError("[SM] Error (line %d, column %d): %s",
    1.41 +				states.line,
    1.42 +				states.col,
    1.43 +				msg);
    1.44 +		}
    1.45 +	}
    1.46  }
    1.47  
    1.48  void CPhraseFile::ReadSMC_ParseStart()
    1.49 @@ -178,21 +217,21 @@
    1.50  		m_ParseState = PPS_InPhrase;
    1.51  		recognized = true;
    1.52  
    1.53 -		phrase_t *pPhrase;
    1.54 -		m_CurPhrase = m_pMemory->CreateMem(sizeof(phrase_t), (void **)&pPhrase);
    1.55 -
    1.56 -		/* Create the reverse lookup */
    1.57 -		if (!sm_trie_insert(m_pPhraseLookup, name, reinterpret_cast<void *>(m_CurPhrase)))
    1.58 +		void *value;
    1.59 +		if (sm_trie_retrieve(m_pPhraseLookup, name, &value))
    1.60  		{
    1.61 -			ParseWarning("Skipping duplicate phrase \"%s\" on line %d.", name, states->line);
    1.62 -			/* :IDEA: prevent memory waste by seeking backwards in memtable? */
    1.63 -			m_CurPhrase = -1;
    1.64 -		} 
    1.65 -		else 
    1.66 +			m_CurPhrase = reinterpret_cast<int>(value);
    1.67 +		}
    1.68 +		else
    1.69  		{
    1.70 +			phrase_t *pPhrase;
    1.71 +
    1.72 +			m_CurPhrase = m_pMemory->CreateMem(sizeof(phrase_t), (void **)&pPhrase);
    1.73 +			sm_trie_insert(m_pPhraseLookup, name, reinterpret_cast<void *>(m_CurPhrase));
    1.74 +
    1.75  			/* Initialize new phrase */
    1.76  			trans_t *pTrans;
    1.77 -	
    1.78 +
    1.79  			pPhrase->fmt_count = 0;
    1.80  			pPhrase->fmt_list = -1;
    1.81  
    1.82 @@ -202,13 +241,14 @@
    1.83  
    1.84  			pPhrase->translations = 0;
    1.85  			pPhrase->fmt_bytes = 0;
    1.86 -	
    1.87 +
    1.88  			for (unsigned int i=0; i<m_LangCount; i++)
    1.89  			{
    1.90  				pTrans[i].stridx = -1;
    1.91  			}
    1.92 -			m_LastPhraseString.assign(name);
    1.93  		}
    1.94 +
    1.95 +		m_LastPhraseString.assign(name);
    1.96  	} 
    1.97  	else if (m_ParseState == PPS_InPhrase) 
    1.98  	{
    1.99 @@ -233,15 +273,12 @@
   1.100  	}
   1.101  
   1.102  	phrase_t *pPhrase = (phrase_t *)m_pMemory->GetAddress(m_CurPhrase);
   1.103 -	
   1.104 -	if (key[0] == '#' && strcmp(key, "#format") == 0)
   1.105 +
   1.106 +	/* Duplicate format keys get silently ignored. */
   1.107 +	if (key[0] == '#' 
   1.108 +		&& strcmp(key, "#format") == 0
   1.109 +		&& pPhrase->fmt_list == -1)
   1.110  	{
   1.111 -		if (pPhrase->fmt_list != -1)
   1.112 -		{
   1.113 -			ParseWarning("Ignoring duplicated #format property on line %d", states->line);
   1.114 -			return SMCResult_Continue;
   1.115 -		}
   1.116 -
   1.117  		if (pPhrase->translations > 0)
   1.118  		{
   1.119  			ParseWarning("#format property should come before translations on line %d, ignoring", states->line);