# HG changeset patch # User David Anderson # Date 1223204928 25200 # Node ID d3f1f1676267e678de1e61bd5230cc39912af59b # Parent faa541e907182c4a6fec051768765546658439c4 Language files are now additive, and are sniffed from translations/[iso code]. This is so translations can be maintained easier without any merging pains on behalf of users or developers. diff -r faa541e90718 -r d3f1f1676267 core/Translator.cpp --- a/core/Translator.cpp Sun Oct 05 04:06:18 2008 -0700 +++ b/core/Translator.cpp Sun Oct 05 04:08:48 2008 -0700 @@ -152,6 +152,45 @@ g_Logger.LogError("[SM] Fatal error encountered parsing translation file \"%s\"", m_File.c_str()); g_Logger.LogError("[SM] Error (line %d, column %d): %s", states.line, states.col, msg); } + + const char *code; + for (unsigned int i = 1; i < m_LangCount; i++) + { + if (!m_pTranslator->GetLanguageInfo(i, &code, NULL)) + { + continue; + } + + g_SourceMod.BuildPath(Path_SM, + path, + PLATFORM_MAX_PATH, + "translations/%s/%s", + code, + m_File.c_str()); + + /* Speculatively load these. */ + if (!g_LibSys.PathExists(path)) + { + continue; + } + + if ((err=textparsers->ParseFile_SMC(path, this, &states)) != SMCError_Okay) + { + const char *msg = textparsers->GetSMCErrorString(err); + if (!msg) + { + msg = m_ParseError.c_str(); + } + + g_Logger.LogError("[SM] Fatal error encountered parsing translation file \"%s/%s\"", + code, + m_File.c_str()); + g_Logger.LogError("[SM] Error (line %d, column %d): %s", + states.line, + states.col, + msg); + } + } } void CPhraseFile::ReadSMC_ParseStart() @@ -178,21 +217,21 @@ m_ParseState = PPS_InPhrase; recognized = true; - phrase_t *pPhrase; - m_CurPhrase = m_pMemory->CreateMem(sizeof(phrase_t), (void **)&pPhrase); - - /* Create the reverse lookup */ - if (!sm_trie_insert(m_pPhraseLookup, name, reinterpret_cast(m_CurPhrase))) + void *value; + if (sm_trie_retrieve(m_pPhraseLookup, name, &value)) { - ParseWarning("Skipping duplicate phrase \"%s\" on line %d.", name, states->line); - /* :IDEA: prevent memory waste by seeking backwards in memtable? */ - m_CurPhrase = -1; - } - else + m_CurPhrase = reinterpret_cast(value); + } + else { + phrase_t *pPhrase; + + m_CurPhrase = m_pMemory->CreateMem(sizeof(phrase_t), (void **)&pPhrase); + sm_trie_insert(m_pPhraseLookup, name, reinterpret_cast(m_CurPhrase)); + /* Initialize new phrase */ trans_t *pTrans; - + pPhrase->fmt_count = 0; pPhrase->fmt_list = -1; @@ -202,13 +241,14 @@ pPhrase->translations = 0; pPhrase->fmt_bytes = 0; - + for (unsigned int i=0; iGetAddress(m_CurPhrase); - - if (key[0] == '#' && strcmp(key, "#format") == 0) + + /* Duplicate format keys get silently ignored. */ + if (key[0] == '#' + && strcmp(key, "#format") == 0 + && pPhrase->fmt_list == -1) { - if (pPhrase->fmt_list != -1) - { - ParseWarning("Ignoring duplicated #format property on line %d", states->line); - return SMCResult_Continue; - } - if (pPhrase->translations > 0) { ParseWarning("#format property should come before translations on line %d, ignoring", states->line);