Core/Chat: Improve ingame language translation (#30298)

This commit is contained in:
Meji
2024-10-05 11:11:13 +02:00
committed by GitHub
parent bfb6c95518
commit 086632d871
2 changed files with 27 additions and 10 deletions

View File

@@ -170,7 +170,7 @@ namespace
return;
for (wchar_t& w : wstrText)
if (!isExtendedLatinCharacter(w) && !isNumeric(w) && w <= 0xFF && w != L'\\')
if (!isLatin1Character(w) && !isNumeric(w) && w <= 0xFF && w != L'\'')
w = L' ';
WStrToUtf8(wstrText, text);
@@ -189,15 +189,11 @@ namespace
0xE3061AE7, 0xA39B0FA1, 0x9797F25F, 0xE4444563,
};
uint32 SStrHash(char const* string, bool caseInsensitive, uint32 seed = 0x7FED7FED)
uint32 SStrHash(std::string_view string, bool caseInsensitive, uint32 seed = 0x7FED7FED)
{
ASSERT(string);
uint32 shift = 0xEEEEEEEE;
while (*string)
for (char c : string)
{
char c = *string++;
if (caseInsensitive)
c = upper_backslash(c);
@@ -222,8 +218,8 @@ std::string LanguageMgr::Translate(std::string const& msg, uint32 language, Loca
uint32 wordLen = std::min(18u, uint32(str.length()));
if (LanguageMgr::WordList const* wordGroup = FindWordGroup(language, wordLen))
{
uint32 wordHash = SStrHash(str.data(), true);
uint8 idxInsideGroup = wordHash % wordGroup->size();
uint32 wordHash = SStrHash(str, true);
uint8 idxInsideGroup = language * wordHash % wordGroup->size();
char const* replacementWord = (*wordGroup)[idxInsideGroup];
@@ -251,7 +247,7 @@ std::string LanguageMgr::Translate(std::string const& msg, uint32 language, Loca
size_t length = std::min(wstrSourceWord.length(), strlen(replacementWord));
for (size_t i = 0; i < length; ++i)
{
if (isUpper(wstrSourceWord[i]))
if (wstrSourceWord[i] != L'\'' && isUpper(wstrSourceWord[i]))
result += charToUpper(replacementWord[i]);
else
result += charToLower(replacementWord[i]);