Improved French accent (th sound) (#33630)

* Improved French accent

* Remove the double consonna part to simplify the code and behaviour

* French accent: clarify a comment

Co-authored-by: Centronias <charlie.t.santos@gmail.com>

---------

Co-authored-by: Centronias <charlie.t.santos@gmail.com>
This commit is contained in:
Obani Gemini
2025-05-30 22:10:13 +02:00
committed by GitHub
parent 3906754853
commit 57e5a091b2

View File

@@ -27,14 +27,28 @@ public sealed class FrenchAccentSystem : EntitySystem
msg = _replacement.ApplyReplacements(msg, "french");
// replaces th with z
msg = RegexTh.Replace(msg, "'z");
// replaces h with ' at the start of words.
msg = RegexStartH.Replace(msg, "'");
// spaces out ! ? : and ;.
msg = RegexSpacePunctuation.Replace(msg, " $&");
// replaces th with 'z or 's depending on the case
foreach (Match match in RegexTh.Matches(msg))
{
var uppercase = msg.Substring(match.Index, 2).Contains("TH");
var Z = uppercase ? "Z" : "z";
var S = uppercase ? "S" : "s";
var idxLetter = match.Index + 2;
// If th is alone, just do 'z
if (msg.Length <= idxLetter) {
msg = msg.Substring(0, match.Index) + "'" + Z;
} else {
var c = "aeiouy".Contains(msg.Substring(idxLetter, 1).ToLower()) ? Z : S;
msg = msg.Substring(0, match.Index) + "'" + c + msg.Substring(idxLetter);
}
}
return msg;
}