1
0
forked from 0ad/0ad

Minor adjustments to i18n code

This was SVN commit r1144.
This commit is contained in:
Ykkrosh 2004-09-17 17:45:44 +00:00
parent baab0311e2
commit ca862b8332
5 changed files with 33 additions and 3 deletions

View File

@ -15,6 +15,7 @@ namespace I18n {
// These bits don't seem to work without the explicit namespace{}
template<> BufferVariable* NewBufferVariable<int>(int v) { return new BufferVariable_int(v); }
template<> BufferVariable* NewBufferVariable<float>(float v) { return new BufferVariable_double(v); }
template<> BufferVariable* NewBufferVariable<double>(double v) { return new BufferVariable_double(v); }
template<> BufferVariable* NewBufferVariable<Noun>(Noun v) { return new BufferVariable_string(v.value); }
template<> BufferVariable* NewBufferVariable<Name>(Name v) { return new BufferVariable_rawstring(v.value); }

View File

@ -194,9 +194,18 @@ bool CLocale::LoadDictionary(const char* data)
DictData& dict = Dictionaries[DictName];
if (dict.DictProperties.size() && PropertyCount != dict.DictProperties.size())
{
LOG(ERROR, LOG_CATEGORY, "I18n: Multiple dictionary files loaded with the name ('%ls') and different properties", DictName.c_str());
return false;
// TODO: Check headings to make sure they're identical (or handle them more cleverly)
}
// Read the names of the properties
for (int i = 0; i < PropertyCount; ++i)
int i;
for (i = 0; i < PropertyCount; ++i)
{
ReadWString8(Property);
dict.DictProperties[Property] = i;
@ -207,7 +216,7 @@ bool CLocale::LoadDictionary(const char* data)
// Read each 'value' (word + properties)
for (int i = 0; i < ValueCount; ++i)
for (i = 0; i < ValueCount; ++i)
{
ReadWString8(Word);
@ -223,13 +232,18 @@ bool CLocale::LoadDictionary(const char* data)
return true;
}
void CLocale::UnloadDictionaries()
{
Dictionaries.clear();
}
const CLocale::LookupType* CLocale::LookupWord(const Str& dictname, const Str& word)
{
std::map<Str, DictData>::const_iterator dictit = Dictionaries.find(dictname);
if (dictit == Dictionaries.end())
{
assert(! "invalid dictionary");
LOG(WARNING, LOG_CATEGORY, "I18n: Non-loaded dictionary '%ls' accessed", dictname.c_str());
return NULL;
}
std::map<Str, std::vector<Str> >::const_iterator wordit = dictit->second.DictWords.find(word);

View File

@ -59,6 +59,7 @@ namespace I18n
bool LoadFunctions(const char* filedata, size_t len, const char* filename);
bool LoadStrings(const char* filedata);
bool LoadDictionary(const char* filedata);
void UnloadDictionaries();
const StrImW CallFunction(const char* name, const std::vector<BufferVariable*>& vars, const std::vector<ScriptValue*>& params);

View File

@ -34,6 +34,8 @@ namespace I18n
// Needs .wrd files generated through tables.pl
virtual bool LoadDictionary(const char* filedata) = 0;
virtual void UnloadDictionaries() = 0;
virtual ~CLocale_interface() {}
};

View File

@ -15,8 +15,16 @@ template<typename T> void delete_fn(T* v) { delete v; }
using namespace I18n;
#ifdef I18NDEBUG
namespace I18n { bool g_UsedCache; }
#endif
I18n::StringBuffer::operator Str()
{
#ifdef I18NDEBUG
g_UsedCache = false;
#endif
if (Variables.size() != String.VarCount)
{
LOG(ERROR, LOG_CATEGORY, "I18n: Incorrect number of parameters passed to Translate");
@ -36,6 +44,10 @@ I18n::StringBuffer::operator Str()
{
// Found in cache
#ifdef I18NDEBUG
g_UsedCache = true;
#endif
// Clean up the current allocated data
std::for_each(Variables.begin(), Variables.end(), delete_fn<BufferVariable>);
// Return the cached string