Core/Chat: Improve ingame language translation

Port From (https://github.com/TrinityCore/TrinityCore/commit/086632d8710ebf3d36aba6a596bc2a9ab4a94fa8)
This commit is contained in:
Hondacrx
2025-09-01 22:30:38 -04:00
parent a2d86ff4d2
commit 7faf096ba9
2 changed files with 25 additions and 4 deletions
+21
View File
@@ -376,6 +376,27 @@ namespace System
return false;
}
public static bool isLatin1Character(char 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;
}
public static bool isBasicLatinCharacter(char wchar)
{
if (wchar >= 'a' && wchar <= 'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
+4 -4
View File
@@ -100,7 +100,7 @@ namespace Game.Chat
if (!wordGroup.Empty())
{
uint wordHash = SStrHash(str, true);
byte idxInsideGroup = (byte)(wordHash % wordGroup.Count());
byte idxInsideGroup = (byte)(language * wordHash % wordGroup.Count());
string replacementWord = wordGroup[idxInsideGroup];
@@ -125,7 +125,7 @@ namespace Game.Chat
int length = Math.Min(str.Length, replacementWord.Length);
for (int i = 0; i < length; ++i)
{
if (char.IsUpper(str[i]))
if (str[i] != '\'' && char.IsUpper(str[i]))
result += char.ToUpper(replacementWord[i]);
else
result += char.ToLower(replacementWord[i]);
@@ -228,8 +228,8 @@ namespace Game.Chat
var chars = text.ToCharArray();
for (var i = 0; i < text.Length; ++i)
{
var w = chars[i];
if (!Extensions.isExtendedLatinCharacter(w) && !char.IsNumber(w) && w <= 0xFF && w != '\\')
var w = text[i];
if (!Extensions.isLatin1Character(w) && !char.IsNumber(w) && w <= 0xFF && w != '\\')
chars[i] = ' ';
}