aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorMeji <alvaro.megias@outlook.com>2024-10-05 11:11:13 +0200
committerGitHub <noreply@github.com>2024-10-05 11:11:13 +0200
commit086632d8710ebf3d36aba6a596bc2a9ab4a94fa8 (patch)
tree276f828d17c439b51ad6474921c1213b3081fdd4 /src/server
parentbfb6c9551870d2fadf789223e52c7799828b3f1b (diff)
Core/Chat: Improve ingame language translation (#30298)
Diffstat (limited to 'src/server')
-rw-r--r--src/server/game/Chat/LanguageMgr.cpp16
1 files changed, 6 insertions, 10 deletions
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]);