Add FallbackTable for localized strings table to redirect missing texts into other language

This commit is contained in:
Wojciech Figat
2021-11-15 16:37:00 +01:00
parent 1107173e60
commit 80ef2befd5
4 changed files with 59 additions and 5 deletions

View File

@@ -258,20 +258,35 @@ void Localization::SetCurrentLanguageCulture(const CultureInfo& value)
String Localization::GetString(const String& id, const String& fallback)
{
String result;
const String* result = nullptr;
for (auto& e : Instance.LocalizedStringTables)
{
const auto table = e.Get();
const auto messages = table ? table->Entries.TryGet(id) : nullptr;
if (messages && messages->Count() != 0)
{
result = messages->At(0);
result = &messages->At(0);
break;
}
}
if (result.IsEmpty())
result = fallback;
return result;
if (!result)
{
// Try using fallback tables
for (auto& e : Instance.LocalizedStringTables)
{
const auto table = e.Get();
const auto fallbackTable = table ? table->FallbackTable.Get() : nullptr;
const auto messages = fallbackTable ? fallbackTable->Entries.TryGet(id) : nullptr;
if (messages && messages->Count() != 0)
{
result = &messages->At(0);
break;
}
}
}
if (!result)
result = &fallback;
return *result;
}
String Localization::GetPluralString(const String& id, int32 n, const String& fallback)
@@ -289,6 +304,21 @@ String Localization::GetPluralString(const String& id, int32 n, const String& fa
break;
}
}
if (!result)
{
// Try using fallback tables
for (auto& e : Instance.LocalizedStringTables)
{
const auto table = e.Get();
const auto fallbackTable = table ? table->FallbackTable.Get() : nullptr;
const auto messages = fallbackTable ? fallbackTable->Entries.TryGet(id) : nullptr;
if (messages && messages->Count() > n)
{
result = &messages->At(n);
break;
}
}
}
if (!result)
result = &fallback;
return String::Format(result->GetText(), n);