From: TakoDragon <69509841+BackeTako@users.noreply.github.com> Date: Thu, 8 Aug 2024 03:08:28 +0000 (+0200) Subject: Improved Spanish accent (#30551) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=929e6a2c002f5dd23633331100f0fa6a68b6de39;p=space-station-14.git Improved Spanish accent (#30551) * Spanish and French comment * Added the interrobang * Make spanish accent use sting builder --- diff --git a/Content.Server/Speech/AccentSystem.cs b/Content.Server/Speech/AccentSystem.cs index 13f174c01e..7e29f02cae 100644 --- a/Content.Server/Speech/AccentSystem.cs +++ b/Content.Server/Speech/AccentSystem.cs @@ -6,7 +6,7 @@ namespace Content.Server.Speech { public sealed class AccentSystem : EntitySystem { - public static readonly Regex SentenceRegex = new(@"(?<=[\.!\?])", RegexOptions.Compiled); + public static readonly Regex SentenceRegex = new(@"(?<=[\.!\?‽])(?![\.!\?‽])", RegexOptions.Compiled); public override void Initialize() { diff --git a/Content.Server/Speech/Components/FrenchAccentComponent.cs b/Content.Server/Speech/Components/FrenchAccentComponent.cs index f696c35ea0..dfe584e267 100644 --- a/Content.Server/Speech/Components/FrenchAccentComponent.cs +++ b/Content.Server/Speech/Components/FrenchAccentComponent.cs @@ -7,5 +7,4 @@ namespace Content.Server.Speech.Components; /// [RegisterComponent] [Access(typeof(FrenchAccentSystem))] -public sealed partial class FrenchAccentComponent : Component -{ } +public sealed partial class FrenchAccentComponent : Component {} diff --git a/Content.Server/Speech/Components/SpanishAccentComponent.cs b/Content.Server/Speech/Components/SpanishAccentComponent.cs index 16a2d188b6..b2eeddc0db 100644 --- a/Content.Server/Speech/Components/SpanishAccentComponent.cs +++ b/Content.Server/Speech/Components/SpanishAccentComponent.cs @@ -1,7 +1,4 @@ -namespace Content.Server.Speech.Components -{ - [RegisterComponent] - public sealed partial class SpanishAccentComponent : Component - { - } -} +namespace Content.Server.Speech.Components; + +[RegisterComponent] +public sealed partial class SpanishAccentComponent : Component {} diff --git a/Content.Server/Speech/EntitySystems/FrenchAccentSystem.cs b/Content.Server/Speech/EntitySystems/FrenchAccentSystem.cs index f6d259c115..d71655569c 100644 --- a/Content.Server/Speech/EntitySystems/FrenchAccentSystem.cs +++ b/Content.Server/Speech/EntitySystems/FrenchAccentSystem.cs @@ -27,10 +27,10 @@ public sealed class FrenchAccentSystem : EntitySystem msg = _replacement.ApplyReplacements(msg, "french"); - // replaces th with dz + // replaces th with z msg = RegexTh.Replace(msg, "'z"); - // removes the letter h from the start of words. + // replaces h with ' at the start of words. msg = RegexStartH.Replace(msg, "'"); // spaces out ! ? : and ;. diff --git a/Content.Server/Speech/EntitySystems/SpanishAccentSystem.cs b/Content.Server/Speech/EntitySystems/SpanishAccentSystem.cs index c8ac24a450..08642014c9 100644 --- a/Content.Server/Speech/EntitySystems/SpanishAccentSystem.cs +++ b/Content.Server/Speech/EntitySystems/SpanishAccentSystem.cs @@ -1,3 +1,4 @@ +using System.Text; using Content.Server.Speech.Components; namespace Content.Server.Speech.EntitySystems @@ -14,7 +15,7 @@ namespace Content.Server.Speech.EntitySystems // Insert E before every S message = InsertS(message); // If a sentence ends with ?, insert a reverse ? at the beginning of the sentence - message = ReplaceQuestionMark(message); + message = ReplacePunctuation(message); return message; } @@ -36,24 +37,32 @@ namespace Content.Server.Speech.EntitySystems return msg; } - private string ReplaceQuestionMark(string message) + private string ReplacePunctuation(string message) { var sentences = AccentSystem.SentenceRegex.Split(message); - var msg = ""; + var msg = new StringBuilder(); foreach (var s in sentences) { - if (s.EndsWith("?", StringComparison.Ordinal)) // We've got a question => add ¿ to the beginning + var toInsert = new StringBuilder(); + for (var i = s.Length - 1; i >= 0 && "?!‽".Contains(s[i]); i--) { - // Because we don't split by whitespace, we may have some spaces in front of the sentence. - // So we add the symbol before the first non space char - msg += s.Insert(s.Length - s.TrimStart().Length, "¿"); + toInsert.Append(s[i] switch + { + '?' => '¿', + '!' => '¡', + '‽' => '⸘', + _ => ' ' + }); } - else + if (toInsert.Length == 0) { - msg += s; + msg.Append(s); + } else + { + msg.Append(s.Insert(s.Length - s.TrimStart().Length, toInsert.ToString())); } } - return msg; + return msg.ToString(); } private void OnAccent(EntityUid uid, SpanishAccentComponent component, AccentGetEvent args)