From 57e5a091b2ed3c1bc963fa82c57eb572b31a12e6 Mon Sep 17 00:00:00 2001 From: Obani Gemini Date: Fri, 30 May 2025 22:10:13 +0200 Subject: [PATCH] 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 --------- Co-authored-by: Centronias --- .../EntitySystems/FrenchAccentSystem.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Content.Server/Speech/EntitySystems/FrenchAccentSystem.cs b/Content.Server/Speech/EntitySystems/FrenchAccentSystem.cs index d71655569c..1b7c46e13a 100644 --- a/Content.Server/Speech/EntitySystems/FrenchAccentSystem.cs +++ b/Content.Server/Speech/EntitySystems/FrenchAccentSystem.cs @@ -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; } -- 2.51.2