diff options
author | Meji <alvaro.megias@outlook.com> | 2024-10-05 11:11:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-05 11:11:13 +0200 |
commit | 086632d8710ebf3d36aba6a596bc2a9ab4a94fa8 (patch) | |
tree | 276f828d17c439b51ad6474921c1213b3081fdd4 | |
parent | bfb6c9551870d2fadf789223e52c7799828b3f1b (diff) |
Core/Chat: Improve ingame language translation (#30298)
-rw-r--r-- | src/common/Utilities/Util.h | 21 | ||||
-rw-r--r-- | src/server/game/Chat/LanguageMgr.cpp | 16 |
2 files changed, 27 insertions, 10 deletions
diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h index 799b64eb893..c85fd858806 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -151,6 +151,27 @@ inline bool isExtendedLatinCharacter(wchar_t wchar) return false; } +inline bool isLatin1Character(wchar_t wchar) +{ + if (isBasicLatinCharacter(wchar)) + return true; + if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS + return true; + if (wchar >= 0x00D8 && wchar <= 0x00DD) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER Y WITH ACUTE + return true; + if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S + return true; + if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS + return true; + if (wchar >= 0x00F8 && wchar <= 0x00FD) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER Y WITH ACUTE + return true; + if (wchar == 0x00FF) // LATIN SMALL LETTER Y WITH DIAERESIS + return true; + if (wchar == 0x0178) // LATIN CAPITAL LETTER Y WITH DIAERESIS + return true; + return false; +} + inline bool isCyrillicCharacter(wchar_t wchar) { if (wchar >= 0x0410 && wchar <= 0x044F) // CYRILLIC CAPITAL LETTER A - CYRILLIC SMALL LETTER YA diff --git a/src/server/game/Chat/LanguageMgr.cpp b/src/server/game/Chat/LanguageMgr.cpp index 9fc877944bc..07181d986a5 100644 --- a/src/server/game/Chat/LanguageMgr.cpp +++ b/src/server/game/Chat/LanguageMgr.cpp @@ -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]); |