]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Improved Spanish accent (#30551)
authorTakoDragon <69509841+BackeTako@users.noreply.github.com>
Thu, 8 Aug 2024 03:08:28 +0000 (05:08 +0200)
committerGitHub <noreply@github.com>
Thu, 8 Aug 2024 03:08:28 +0000 (13:08 +1000)
* Spanish and French comment

* Added the interrobang

* Make spanish accent use sting builder

Content.Server/Speech/AccentSystem.cs
Content.Server/Speech/Components/FrenchAccentComponent.cs
Content.Server/Speech/Components/SpanishAccentComponent.cs
Content.Server/Speech/EntitySystems/FrenchAccentSystem.cs
Content.Server/Speech/EntitySystems/SpanishAccentSystem.cs

index 13f174c01ef9ff1fa439dc024b4dd0080ad08c4a..7e29f02caece20ea5b09a592df913672df56473c 100644 (file)
@@ -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()
         {
index f696c35ea03f45051b420e7362f4032c7f74ac7a..dfe584e267073d3b1138be3bfe060e9430b8aaff 100644 (file)
@@ -7,5 +7,4 @@ namespace Content.Server.Speech.Components;
 /// </summary>
 [RegisterComponent]
 [Access(typeof(FrenchAccentSystem))]
-public sealed partial class FrenchAccentComponent : Component
-{ }
+public sealed partial class FrenchAccentComponent : Component {}
index 16a2d188b68736e884fce7845f9aed7e621f00ff..b2eeddc0db27d376d57f2e3e1520c07540ea24ad 100644 (file)
@@ -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 {}
index f6d259c11532052ba2e187d9edeae63154faf6f4..d71655569cb63408ad567e36f1fff7f8d1112bc7 100644 (file)
@@ -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 ;.
index c8ac24a450efb94d45e11b82ec452c1ac5a4328c..08642014c90cafaae6454dc926775d1ea187623e 100644 (file)
@@ -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)