mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Chat: Improve ingame language translation (#30298)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user