/* Copyright (C) 2015 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #include "precompiled.h" #include "JSInterface_L10n.h" #include "i18n/L10n.h" #include "lib/utf8.h" // 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(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(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(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(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(g_L10n.TranslateLines(utf8_from_wstring(sourceString))); } // Return a translated version of the items in the specified array. std::vector JSI_L10n::TranslateArray(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::vector sourceArray) { std::vector translatedArray; for (const std::wstring& elem : sourceArray) translatedArray.push_back(wstring_from_utf8(g_L10n.Translate(utf8_from_wstring(elem)))); return translatedArray; } std::wstring JSI_L10n::GetFallbackToAvailableDictLocale(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string 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(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(g_L10n.FormatDecimalNumberIntoString(number)); } std::vector JSI_L10n::GetSupportedLocaleBaseNames(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { return g_L10n.GetSupportedLocaleBaseNames(); } std::vector JSI_L10n::GetSupportedLocaleDisplayNames(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { return g_L10n.GetSupportedLocaleDisplayNames(); } std::string JSI_L10n::GetCurrentLocale(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { return g_L10n.GetCurrentLocaleString(); } bool JSI_L10n::UseLongStrings(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { return g_L10n.UseLongStrings(); } std::vector JSI_L10n::GetAllLocales(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { return g_L10n.GetAllLocales(); } std::string JSI_L10n::GetDictionaryLocale(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string configLocale) { return g_L10n.GetDictionaryLocale(configLocale); } std::vector JSI_L10n::GetDictionariesForLocale(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { return g_L10n.GetDictionariesForLocale(locale); } std::string JSI_L10n::GetLocaleLanguage(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { return g_L10n.GetLocaleLanguage(locale); } std::string JSI_L10n::GetLocaleBaseName(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { return g_L10n.GetLocaleBaseName(locale); } std::string JSI_L10n::GetLocaleCountry(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { return g_L10n.GetLocaleCountry(locale); } std::string JSI_L10n::GetLocaleScript(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { return g_L10n.GetLocaleScript(locale); } bool JSI_L10n::ValidateLocale(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { return g_L10n.ValidateLocale(locale); } bool JSI_L10n::SaveLocale(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale) { return g_L10n.SaveLocale(locale); } void JSI_L10n::ReevaluateCurrentLocaleAndReload(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { g_L10n.ReevaluateCurrentLocaleAndReload(); } void JSI_L10n::RegisterScriptFunctions(ScriptInterface& scriptInterface) { scriptInterface.RegisterFunction("Translate"); scriptInterface.RegisterFunction("TranslateWithContext"); scriptInterface.RegisterFunction("TranslatePlural"); scriptInterface.RegisterFunction("TranslatePluralWithContext"); scriptInterface.RegisterFunction("TranslateLines"); scriptInterface.RegisterFunction, std::vector, &TranslateArray>("TranslateArray"); scriptInterface.RegisterFunction("FormatMillisecondsIntoDateString"); scriptInterface.RegisterFunction("FormatDecimalNumberIntoString"); scriptInterface.RegisterFunction, &GetSupportedLocaleBaseNames>("GetSupportedLocaleBaseNames"); scriptInterface.RegisterFunction, &GetSupportedLocaleDisplayNames>("GetSupportedLocaleDisplayNames"); scriptInterface.RegisterFunction("GetCurrentLocale"); scriptInterface.RegisterFunction, &GetAllLocales>("GetAllLocales"); scriptInterface.RegisterFunction("GetDictionaryLocale"); scriptInterface.RegisterFunction, std::string, &GetDictionariesForLocale>("GetDictionariesForLocale"); scriptInterface.RegisterFunction("UseLongStrings"); scriptInterface.RegisterFunction("GetLocaleLanguage"); scriptInterface.RegisterFunction("GetLocaleBaseName"); scriptInterface.RegisterFunction("GetLocaleCountry"); scriptInterface.RegisterFunction("GetLocaleScript"); scriptInterface.RegisterFunction("GetFallbackToAvailableDictLocale"); scriptInterface.RegisterFunction("ValidateLocale"); scriptInterface.RegisterFunction("SaveLocale"); scriptInterface.RegisterFunction("ReevaluateCurrentLocaleAndReload"); }