diff --git a/source/i18n/CLocale.cpp b/source/i18n/CLocale.cpp index 393e314389..707de2fb27 100755 --- a/source/i18n/CLocale.cpp +++ b/source/i18n/CLocale.cpp @@ -185,12 +185,14 @@ bool CLocale::LoadFunctions(const char* data, size_t len, const char* filename) } -bool CLocale::LoadDictionary(const char* data, const wchar_t* name) +bool CLocale::LoadDictionary(const char* data) { + ReadWString8(DictName); + u8 PropertyCount = *(u8*)data; data += 1; - DictData& dict = Dictionaries[name]; + DictData& dict = Dictionaries[DictName]; // Read the names of the properties diff --git a/source/i18n/CLocale.h b/source/i18n/CLocale.h index 0cb48783d3..a1124bdee5 100755 --- a/source/i18n/CLocale.h +++ b/source/i18n/CLocale.h @@ -23,20 +23,21 @@ All other methods are used internally by other I18n components. #include #include +// GCC requires an explicit hash function for wide strings #ifdef __GNUC__ namespace __gnu_cxx { - template<> struct hash - { - size_t operator()(const I18n::Str& s) const - { - const wchar_t* __s = s.c_str(); - unsigned long __h = 0; - for ( ; *__s; ++__s) - __h = 5*__h + *__s; - return size_t(__h); - } - }; + template<> struct hash + { + size_t operator()(const I18n::Str& s) const + { + const wchar_t* __s = s.c_str(); + unsigned long __h = 0; + for ( ; *__s; ++__s) + __h = 5*__h + *__s; + return size_t(__h); + } + }; } #endif // __GNUC__ @@ -57,7 +58,7 @@ namespace I18n bool LoadFunctions(const char* filedata, size_t len, const char* filename); bool LoadStrings(const char* filedata); - bool LoadDictionary(const char* filedata, const wchar_t* name); + bool LoadDictionary(const char* filedata); const StrImW CallFunction(const char* name, const std::vector& vars, const std::vector& params); diff --git a/source/i18n/DataTypes.h b/source/i18n/DataTypes.h index b4d684d4a5..44930f45dd 100755 --- a/source/i18n/DataTypes.h +++ b/source/i18n/DataTypes.h @@ -13,6 +13,10 @@ namespace I18n template Name(T d) : value(d) {} StrImW value; }; + + // Also allow I18n::Raw("english message"), which does the same + // non-translation but makes more sense when writing e.g. error messages + typedef Name Raw; } diff --git a/source/i18n/Interface.h b/source/i18n/Interface.h index e7190e1644..aaae70a31f 100755 --- a/source/i18n/Interface.h +++ b/source/i18n/Interface.h @@ -31,7 +31,7 @@ namespace I18n virtual bool LoadStrings(const char* filedata) = 0; // Needs .wrd files generated through tables.pl - virtual bool LoadDictionary(const char* filedata, const wchar_t* name) = 0; + virtual bool LoadDictionary(const char* filedata) = 0; virtual ~CLocale_interface() {} }; diff --git a/source/i18n/ScriptInterface.cpp b/source/i18n/ScriptInterface.cpp index bd5bee01e3..a3a3ac565c 100755 --- a/source/i18n/ScriptInterface.cpp +++ b/source/i18n/ScriptInterface.cpp @@ -149,6 +149,10 @@ static JSClass JSI_class_scriptglobal = { ScriptObject::ScriptObject(CLocale* locale, JSContext* cx) : Context(cx) { + // Don't do much if there's currently no scripting support + if (cx == NULL) + return; + // This should, in theory, never fail Object = JS_NewObject(Context, &JSI_class_scriptglobal, NULL, NULL); @@ -172,7 +176,8 @@ ScriptObject::ScriptObject(CLocale* locale, JSContext* cx) ScriptObject::~ScriptObject() { - JS_RemoveRoot(Context, &Object); + if (Context) + JS_RemoveRoot(Context, &Object); } bool ScriptObject::ExecuteCode(const jschar* data, size_t len, const char* filename)