diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 1e4a674080..a8840ca903 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -1263,7 +1263,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec XMBElement grandchild = grandchildren.Item(i); if (grandchild.GetNodeName() == elmt_translate) { - code += L10n::Instance().Translate(grandchild.GetText()); + code += g_L10n.Translate(grandchild.GetText()); } else if (grandchild.GetNodeName() == elmt_keep) { @@ -1304,12 +1304,12 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec CStr context(child.GetAttributes().GetNamedItem(attr_context)); // Read the context if any. if (!context.empty()) { - CStr translatedValue(L10n::Instance().TranslateWithContext(context, value)); + CStr translatedValue(g_L10n.TranslateWithContext(context, value)); object->SetSetting(attributeName, translatedValue.UnescapeBackslashes().FromUTF8(), true); } else { - CStr translatedValue(L10n::Instance().Translate(value)); + CStr translatedValue(g_L10n.Translate(value)); object->SetSetting(attributeName, translatedValue.UnescapeBackslashes().FromUTF8(), true); } } @@ -1332,7 +1332,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec XMBElement grandchild = grandchildren.Item(i); if (grandchild.GetNodeName() == elmt_translate) { - translatedValue += L10n::Instance().Translate(grandchild.GetText()); + translatedValue += g_L10n.Translate(grandchild.GetText()); } else if (grandchild.GetNodeName() == elmt_keep) { diff --git a/source/gui/COList.cpp b/source/gui/COList.cpp index 9c9b9cdb13..09ff828b72 100644 --- a/source/gui/COList.cpp +++ b/source/gui/COList.cpp @@ -203,12 +203,12 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile CStr context(grandchild.GetAttributes().GetNamedItem(attr_context)); // Read the context if any. if (!context.empty()) { - CStr translatedValue(L10n::Instance().TranslateWithContext(context, value)); + CStr translatedValue(g_L10n.TranslateWithContext(context, value)); oDef.m_Heading = translatedValue.FromUTF8(); } else { - CStr translatedValue(L10n::Instance().Translate(value)); + CStr translatedValue(g_L10n.Translate(value)); oDef.m_Heading = translatedValue.FromUTF8(); } } diff --git a/source/gui/GUIRenderer.cpp b/source/gui/GUIRenderer.cpp index 5e39ebf1e6..75b133aa1f 100644 --- a/source/gui/GUIRenderer.cpp +++ b/source/gui/GUIRenderer.cpp @@ -201,7 +201,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName, if (!(*cit)->m_TextureName.empty()) { - CTextureProperties textureProps(L10n::Instance().LocalizePath((*cit)->m_TextureName)); + CTextureProperties textureProps(g_L10n.LocalizePath((*cit)->m_TextureName)); textureProps.SetWrap((*cit)->m_WrapMode); CTexturePtr texture = g_Renderer.GetTextureManager().CreateTexture(textureProps); texture->Prefetch(); diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp index f76e3e7dfc..904d89e1d8 100644 --- a/source/gui/scripting/ScriptFunctions.cpp +++ b/source/gui/scripting/ScriptFunctions.cpp @@ -789,31 +789,31 @@ std::wstring GetBuildTimestamp(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), i char buf[200]; if (mode == -1) // Date, time and revision. { - UDate dateTime = L10n::Instance().ParseDateTime(__DATE__ " " __TIME__, "MMM d yyyy HH:mm:ss", Locale::getUS()); - std::string dateTimeString = L10n::Instance().LocalizeDateTime(dateTime, L10n::DateTime, SimpleDateFormat::DATE_TIME); + UDate dateTime = g_L10n.ParseDateTime(__DATE__ " " __TIME__, "MMM d yyyy HH:mm:ss", Locale::getUS()); + std::string dateTimeString = g_L10n.LocalizeDateTime(dateTime, L10n::DateTime, SimpleDateFormat::DATE_TIME); char svnRevision[32]; sprintf_s(svnRevision, ARRAY_SIZE(svnRevision), "%ls", svn_revision); if (strcmp(svnRevision, "custom build") == 0) { // Translation: First item is a date and time, item between parenthesis is the Subversion revision number of the current build. - sprintf_s(buf, ARRAY_SIZE(buf), L10n::Instance().Translate("%s (custom build)").c_str(), dateTimeString.c_str()); + sprintf_s(buf, ARRAY_SIZE(buf), g_L10n.Translate("%s (custom build)").c_str(), dateTimeString.c_str()); } else { // Translation: First item is a date and time, item between parenthesis is the Subversion revision number of the current build. - sprintf_s(buf, ARRAY_SIZE(buf), L10n::Instance().Translate("%s (%ls)").c_str(), dateTimeString.c_str(), svn_revision); + sprintf_s(buf, ARRAY_SIZE(buf), g_L10n.Translate("%s (%ls)").c_str(), dateTimeString.c_str(), svn_revision); } } else if (mode == 0) // Date. { - UDate dateTime = L10n::Instance().ParseDateTime(__DATE__, "MMM d yyyy", Locale::getUS()); - std::string dateTimeString = L10n::Instance().LocalizeDateTime(dateTime, L10n::Date, SimpleDateFormat::MEDIUM); + UDate dateTime = g_L10n.ParseDateTime(__DATE__, "MMM d yyyy", Locale::getUS()); + std::string dateTimeString = g_L10n.LocalizeDateTime(dateTime, L10n::Date, SimpleDateFormat::MEDIUM); sprintf_s(buf, ARRAY_SIZE(buf), "%s", dateTimeString.c_str()); } else if (mode == 1) // Time. { - UDate dateTime = L10n::Instance().ParseDateTime(__TIME__, "HH:mm:ss", Locale::getUS()); - std::string dateTimeString = L10n::Instance().LocalizeDateTime(dateTime, L10n::Time, SimpleDateFormat::MEDIUM); + UDate dateTime = g_L10n.ParseDateTime(__TIME__, "HH:mm:ss", Locale::getUS()); + std::string dateTimeString = g_L10n.LocalizeDateTime(dateTime, L10n::Time, SimpleDateFormat::MEDIUM); sprintf_s(buf, ARRAY_SIZE(buf), "%s", dateTimeString.c_str()); } else if (mode == 2) // Revision. @@ -822,7 +822,7 @@ std::wstring GetBuildTimestamp(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), i sprintf_s(svnRevision, ARRAY_SIZE(svnRevision), "%ls", svn_revision); if (strcmp(svnRevision, "custom build") == 0) { - sprintf_s(buf, ARRAY_SIZE(buf), "%s", L10n::Instance().Translate("custom build").c_str()); + sprintf_s(buf, ARRAY_SIZE(buf), "%s", g_L10n.Translate("custom build").c_str()); } else { diff --git a/source/i18n/L10n.cpp b/source/i18n/L10n.cpp index 5b5b6be71e..45614b5493 100644 --- a/source/i18n/L10n.cpp +++ b/source/i18n/L10n.cpp @@ -36,12 +36,6 @@ #include "ps/GameSetup/GameSetup.h" -L10n& L10n::Instance() -{ - static L10n m_instance; - return m_instance; -} - L10n::L10n() : currentLocaleIsOriginalGameLocale(false), useLongStrings(false), dictionary(new tinygettext::Dictionary()) { diff --git a/source/i18n/L10n.h b/source/i18n/L10n.h index 4863742d1f..d0a287e7ac 100644 --- a/source/i18n/L10n.h +++ b/source/i18n/L10n.h @@ -32,12 +32,16 @@ #include "lib/file/vfs/vfs_path.h" +#include "ps/Singleton.h" + +#define g_L10n L10n::GetSingleton() + /** * %Singleton for internationalization and localization. * * @sa http://trac.wildfiregames.com/wiki/Internationalization_and_Localization */ -class L10n +class L10n : public Singleton { /** * Marks the L10n class as ‘noncopyable’. @@ -76,14 +80,6 @@ public: Time ///< Only time. }; - /** - * Returns the running instance of the internationalization and localization - * singleton. - * - * If there is no instance yet, Instance() creates one and returns it. - */ - static L10n& Instance(); - /** * Returns the current locale. * diff --git a/source/i18n/scripting/JSInterface_L10n.cpp b/source/i18n/scripting/JSInterface_L10n.cpp index e6db3e9071..45a7210287 100644 --- a/source/i18n/scripting/JSInterface_L10n.cpp +++ b/source/i18n/scripting/JSInterface_L10n.cpp @@ -26,31 +26,31 @@ // Returns a translation of the specified English string into the current language. std::wstring JSI_L10n::Translate(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring sourceString) { - return wstring_from_utf8(L10n::Instance().Translate(utf8_from_wstring(sourceString))); + return wstring_from_utf8(g_L10n.Translate(utf8_from_wstring(sourceString))); } // Returns a translation of the specified English string, for the specified context. std::wstring JSI_L10n::TranslateWithContext(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string context, std::wstring sourceString) { - return wstring_from_utf8(L10n::Instance().TranslateWithContext(context, utf8_from_wstring(sourceString))); + return wstring_from_utf8(g_L10n.TranslateWithContext(context, utf8_from_wstring(sourceString))); } // Return a translated version of the given strings (singular and plural) depending on an integer value. std::wstring JSI_L10n::TranslatePlural(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring singularSourceString, std::wstring pluralSourceString, int number) { - return wstring_from_utf8(L10n::Instance().TranslatePlural(utf8_from_wstring(singularSourceString), utf8_from_wstring(pluralSourceString), number)); + return wstring_from_utf8(g_L10n.TranslatePlural(utf8_from_wstring(singularSourceString), utf8_from_wstring(pluralSourceString), number)); } // Return a translated version of the given strings (singular and plural) depending on an integer value, for the specified context. std::wstring JSI_L10n::TranslatePluralWithContext(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string context, std::wstring singularSourceString, std::wstring pluralSourceString, int number) { - return wstring_from_utf8(L10n::Instance().TranslatePluralWithContext(context, utf8_from_wstring(singularSourceString), utf8_from_wstring(pluralSourceString), number)); + return wstring_from_utf8(g_L10n.TranslatePluralWithContext(context, utf8_from_wstring(singularSourceString), utf8_from_wstring(pluralSourceString), number)); } // Return a translated version of the given string, localizing it line by line. std::wstring JSI_L10n::TranslateLines(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring sourceString) { - return wstring_from_utf8(L10n::Instance().TranslateLines(utf8_from_wstring(sourceString))); + return wstring_from_utf8(g_L10n.TranslateLines(utf8_from_wstring(sourceString))); } // Return a translated version of the items in the specified array. @@ -59,96 +59,96 @@ std::vector JSI_L10n::TranslateArray(ScriptInterface::CxPrivate* U std::vector translatedArray; for (std::vector::iterator iterator = sourceArray.begin(); iterator != sourceArray.end(); ++iterator) { - translatedArray.push_back(wstring_from_utf8(L10n::Instance().Translate(utf8_from_wstring(*iterator)))); + translatedArray.push_back(wstring_from_utf8(g_L10n.Translate(utf8_from_wstring(*iterator)))); } return translatedArray; } std::wstring JSI_L10n::GetFallbackToAvailableDictLocale(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { - return L10n::Instance().GetFallbackToAvailableDictLocale(locale); + return g_L10n.GetFallbackToAvailableDictLocale(locale); } // Return a localized version of a time given in milliseconds. std::wstring JSI_L10n::FormatMillisecondsIntoDateString(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), UDate milliseconds, std::wstring formatString) { - return wstring_from_utf8(L10n::Instance().FormatMillisecondsIntoDateString(milliseconds, utf8_from_wstring(formatString))); + return wstring_from_utf8(g_L10n.FormatMillisecondsIntoDateString(milliseconds, utf8_from_wstring(formatString))); } // Return a localized version of the given decimal number. std::wstring JSI_L10n::FormatDecimalNumberIntoString(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), double number) { - return wstring_from_utf8(L10n::Instance().FormatDecimalNumberIntoString(number)); + return wstring_from_utf8(g_L10n.FormatDecimalNumberIntoString(number)); } std::vector JSI_L10n::GetSupportedLocaleBaseNames(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - return L10n::Instance().GetSupportedLocaleBaseNames(); + return g_L10n.GetSupportedLocaleBaseNames(); } std::vector JSI_L10n::GetSupportedLocaleDisplayNames(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - return L10n::Instance().GetSupportedLocaleDisplayNames(); + return g_L10n.GetSupportedLocaleDisplayNames(); } std::string JSI_L10n::GetCurrentLocale(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - return L10n::Instance().GetCurrentLocaleString(); + return g_L10n.GetCurrentLocaleString(); } bool JSI_L10n::UseLongStrings(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - return L10n::Instance().UseLongStrings(); + return g_L10n.UseLongStrings(); } std::vector JSI_L10n::GetAllLocales(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - return L10n::Instance().GetAllLocales(); + return g_L10n.GetAllLocales(); } std::string JSI_L10n::GetDictionaryLocale(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string configLocale) { - return L10n::Instance().GetDictionaryLocale(configLocale); + return g_L10n.GetDictionaryLocale(configLocale); } std::vector JSI_L10n::GetDictionariesForLocale(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { - return L10n::Instance().GetDictionariesForLocale(locale); + return g_L10n.GetDictionariesForLocale(locale); } std::string JSI_L10n::GetLocaleLanguage(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { - return L10n::Instance().GetLocaleLanguage(locale); + return g_L10n.GetLocaleLanguage(locale); } std::string JSI_L10n::GetLocaleBaseName(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { - return L10n::Instance().GetLocaleBaseName(locale); + return g_L10n.GetLocaleBaseName(locale); } std::string JSI_L10n::GetLocaleCountry(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { - return L10n::Instance().GetLocaleCountry(locale); + return g_L10n.GetLocaleCountry(locale); } std::string JSI_L10n::GetLocaleScript(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { - return L10n::Instance().GetLocaleScript(locale); + return g_L10n.GetLocaleScript(locale); } bool JSI_L10n::ValidateLocale(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { - return L10n::Instance().ValidateLocale(locale); + return g_L10n.ValidateLocale(locale); } bool JSI_L10n::SaveLocale(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { - return L10n::Instance().SaveLocale(locale); + return g_L10n.SaveLocale(locale); } void JSI_L10n::ReevaluateCurrentLocaleAndReload(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - L10n::Instance().ReevaluateCurrentLocaleAndReload(); + g_L10n.ReevaluateCurrentLocaleAndReload(); } diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index e046c7770b..7933621a3e 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -45,6 +45,7 @@ #include "gui/GUI.h" #include "gui/GUIManager.h" #include "gui/scripting/ScriptFunctions.h" +#include "i18n/L10n.h" #include "maths/MathUtil.h" #include "network/NetServer.h" #include "network/NetClient.h" @@ -730,6 +731,8 @@ void Shutdown(int flags) //delete g_DebuggingServer; //TIMER_END(L"shutdown DebuggingServer (if active)"); + delete &g_L10n; + from_config: TIMER_BEGIN(L"shutdown ConfigDB"); delete &g_ConfigDB; @@ -950,6 +953,8 @@ bool Init(const CmdLineArgs& args, int flags) } } + new L10n; + // before scripting // JS debugger temporarily disabled during the SpiderMonkey upgrade (check trac ticket #2348 for details) //if (g_JSDebuggerEnabled) diff --git a/source/ps/SavedGame.cpp b/source/ps/SavedGame.cpp index e409f7adb0..007dcb23d1 100644 --- a/source/ps/SavedGame.cpp +++ b/source/ps/SavedGame.cpp @@ -126,7 +126,7 @@ Status SavedGames::Save(const std::wstring& name, const std::wstring& descriptio OsPath realPath; WARN_RETURN_STATUS_IF_ERR(g_VFS->GetRealPath(filename, realPath)); - LOGMESSAGERENDER(wstring_from_utf8(L10n::Instance().Translate("Saved game to '%ls'") + "\n").c_str(), realPath.string().c_str()); + LOGMESSAGERENDER(wstring_from_utf8(g_L10n.Translate("Saved game to '%ls'") + "\n").c_str(), realPath.string().c_str()); return INFO::OK; } diff --git a/source/ps/Util.cpp b/source/ps/Util.cpp index 18a021def3..3817112e4b 100644 --- a/source/ps/Util.cpp +++ b/source/ps/Util.cpp @@ -241,7 +241,7 @@ void WriteScreenshot(const VfsPath& extension) { OsPath realPath; g_VFS->GetRealPath(filename, realPath); - LOGMESSAGERENDER(wstring_from_utf8(L10n::Instance().Translate("Screenshot written to '%ls'")).c_str(), realPath.string().c_str()); + LOGMESSAGERENDER(wstring_from_utf8(g_L10n.Translate("Screenshot written to '%ls'")).c_str(), realPath.string().c_str()); } else LOGERROR(L"Error writing screenshot to '%ls'", filename.string().c_str()); @@ -374,7 +374,7 @@ void WriteBigScreenshot(const VfsPath& extension, int tiles) { OsPath realPath; g_VFS->GetRealPath(filename, realPath); - LOGMESSAGERENDER(wstring_from_utf8(L10n::Instance().Translate("Screenshot written to '%ls'")).c_str(), realPath.string().c_str()); + LOGMESSAGERENDER(wstring_from_utf8(g_L10n.Translate("Screenshot written to '%ls'")).c_str(), realPath.string().c_str()); } else LOGERROR(L"Error writing screenshot to '%ls'", filename.string().c_str());