Add workaround for testing long strings with the separate po. ICU wouldn't accept a non-existing language.

This was SVN commit r14969.
This commit is contained in:
sanderd17 2014-04-22 11:38:15 +00:00
parent 9dd4e71f1d
commit 21362de6ac
5 changed files with 64 additions and 13 deletions

View File

@ -7,13 +7,23 @@ function init()
var currentLocale = Engine.GetCurrentLocale();
var currentLocaleBaseName = Engine.GetLocaleBaseName(currentLocale);
var currentLocaleLanguage = Engine.GetLocaleLanguage(currentLocale);
if (languageList.list_data.indexOf(currentLocaleBaseName) != -1)
languageList.selected = languageList.list_data.indexOf(currentLocaleBaseName);
else if (languageList.list_data.indexOf(currentLocaleLanguage) != -1)
languageList.selected = languageList.list_data.indexOf(currentLocaleLanguage);
var useLongStrings = Engine.UseLongStrings();
var index = -1;
if (useLongStrings)
index = languageList.list_data.indexOf("long");
if (index == -1)
index = languageList.list_data.indexOf(currentLocaleBaseName);
if (index == -1)
index = languageList.list_data.indexOf(currentLocaleLanguage);
if (index != -1)
languageList.selected = index;
var localeText = Engine.GetGUIObjectByName("localeText");
localeText.caption = currentLocale;
if (useLongStrings)
localeText.caption = "long";
else
localeText.caption = currentLocale;
}
function cancelSetup()
@ -37,7 +47,9 @@ function languageSelectionChanged()
{
var languageList = Engine.GetGUIObjectByName("languageList");
var locale = languageList.list_data[languageList.selected];
if(!Engine.ValidateLocale(locale))
if (locale == "long")
warn("'long' is not an actual language, just a collection of all longest strings extracted from some languages");
else if(!Engine.ValidateLocale(locale))
warn("Selected locale is not valid! This is not expected, please report the issue.");
var localeText = Engine.GetGUIObjectByName("localeText");
localeText.caption = locale;

View File

@ -43,7 +43,7 @@ L10n& L10n::Instance()
}
L10n::L10n()
: currentLocaleIsOriginalGameLocale(false), dictionary(new tinygettext::Dictionary())
: currentLocaleIsOriginalGameLocale(false), useLongStrings(false), dictionary(new tinygettext::Dictionary())
{
LoadListOfAvailableLocales();
ReevaluateCurrentLocaleAndReload();
@ -63,11 +63,16 @@ Locale L10n::GetCurrentLocale()
bool L10n::SaveLocale(const std::string& localeCode)
{
if (localeCode == "long" && InDevelopmentCopy())
{
g_ConfigDB.SetValueString(CFG_USER, "locale", "long");
return true;
}
return SaveLocale(Locale(Locale::createCanonical(localeCode.c_str())));
}
bool L10n::SaveLocale(Locale locale)
{
{
// TODO: Use the ConfigDB functions exposed to js to change the config value
// Save the new locale in the settings file.
if (!ValidateLocale(locale))
@ -179,9 +184,20 @@ void L10n::ReevaluateCurrentLocaleAndReload()
{
std::string locale;
CFG_GET_VAL("locale", String, locale);
GetDictionaryLocale(locale, currentLocale);
currentLocaleIsOriginalGameLocale = (currentLocale == Locale::getUS()) == TRUE;
if (locale == "long")
{
// Set ICU to en_US to have a valid language for displaying dates
currentLocale = Locale::getUS();
currentLocaleIsOriginalGameLocale = false;
useLongStrings = true;
}
else
{
GetDictionaryLocale(locale, currentLocale);
currentLocaleIsOriginalGameLocale = (currentLocale == Locale::getUS()) == true;
useLongStrings = false;
}
LoadDictionaryForCurrentLocale();
}
@ -197,6 +213,11 @@ std::vector<std::string> L10n::GetAllLocales()
}
bool L10n::UseLongStrings()
{
return useLongStrings;
};
std::vector<std::string> L10n::GetSupportedLocaleBaseNames()
{
std::vector<std::string> supportedLocaleCodes;
@ -396,8 +417,17 @@ void L10n::LoadDictionaryForCurrentLocale()
dictionary = new tinygettext::Dictionary();
VfsPaths filenames;
if (vfs::GetPathnames(g_VFS, L"l10n/", (wstring_from_utf8(currentLocale.getBaseName()) + L".*.po").c_str(), filenames) < 0)
return;
if (useLongStrings)
{
if (vfs::GetPathnames(g_VFS, L"l10n/", L"long.*.po", filenames) < 0)
return;
}
else
{
if (vfs::GetPathnames(g_VFS, L"l10n/", (wstring_from_utf8(currentLocale.getBaseName()) + L".*.po").c_str(), filenames) < 0)
return;
}
// If not matching country is found, try to fall back to a matching language
if (filenames.size() == 0)

View File

@ -55,6 +55,7 @@ public:
std::string GetLocaleBaseName(const std::string& locale);
std::string GetLocaleCountry(const std::string& locale);
std::string GetLocaleScript(const std::string& locale);
bool UseLongStrings();
std::vector<std::wstring> GetDictionariesForDictLocale(const std::string& locale);
std::string GetDictionaryLocale(std::string configLocaleString);
void GetDictionaryLocale(std::string configLocaleString, Locale& outLocale);
@ -82,6 +83,7 @@ private:
Locale currentLocale;
std::vector<Locale*> availableLocales;
bool currentLocaleIsOriginalGameLocale;
bool useLongStrings;
Locale AutoDetectLocale();
void LoadDictionaryForCurrentLocale();

View File

@ -97,6 +97,11 @@ std::string JSI_L10n::GetCurrentLocale(ScriptInterface::CxPrivate* UNUSED(pCxPri
return L10n::Instance().GetCurrentLocaleString();
}
bool JSI_L10n::UseLongStrings(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
{
return L10n::Instance().UseLongStrings();
}
std::vector<std::string> JSI_L10n::GetAllLocales(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
{
return L10n::Instance().GetAllLocales();
@ -167,6 +172,7 @@ void JSI_L10n::RegisterScriptFunctions(ScriptInterface& scriptInterface)
scriptInterface.RegisterFunction<std::string, std::string, &GetDictionaryLocale>("GetDictionaryLocale");
scriptInterface.RegisterFunction<std::vector<std::wstring>, std::string, &GetDictionariesForDictLocale>("GetDictionariesForDictLocale");
scriptInterface.RegisterFunction<bool, &UseLongStrings>("UseLongStrings");
scriptInterface.RegisterFunction<std::string, std::string, &GetLocaleLanguage>("GetLocaleLanguage");
scriptInterface.RegisterFunction<std::string, std::string, &GetLocaleBaseName>("GetLocaleBaseName");
scriptInterface.RegisterFunction<std::string, std::string, &GetLocaleCountry>("GetLocaleCountry");

View File

@ -46,6 +46,7 @@ namespace JSI_L10n
std::string GetLocaleBaseName(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale);
std::string GetLocaleCountry(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale);
std::string GetLocaleScript(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale);
bool UseLongStrings(ScriptInterface::CxPrivate* UNUSED(pCxPrivate));
bool ValidateLocale(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale);
bool SaveLocale(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string locale);