mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
Make Spanish accent more linguistically accurate (#38249)
* Update SpanishAccentSystem.cs Use RegEx in accordance with the phonotactics of the Spanish language. * Allow SH * Addressing review comments * better comment * conflict --------- Co-authored-by: AJCM-git <ajcm_mail@disroot.org>
This commit is contained in:
parent
e7897d76a4
commit
e26ed1fe30
2 changed files with 18 additions and 20 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using System.Text.RegularExpressions;
|
||||
using System.Text;
|
||||
using Content.Server.Speech.Components;
|
||||
using Content.Shared.Speech.EntitySystems;
|
||||
|
|
@ -6,9 +7,17 @@ namespace Content.Server.Speech.EntitySystems;
|
|||
|
||||
public sealed class SpanishAccentSystem : RelayAccentSystem<SpanishAccentComponent>
|
||||
{
|
||||
// for words in all lowercase (multiple "s" are allowed)
|
||||
private static readonly Regex RegexLower = new(@"(?<!\w)(s+h*[bcdfgjklmnpqrtvwxz])");
|
||||
// For Capitalized Words (Station -> Estation; Capital "S" Is Replaced Directly, Multiple "S" Are Allowed)
|
||||
private static readonly Regex RegexCaps = new(@"(?<!\w)S(s*h*[bcdfgjklmnpqrtvwxz])");
|
||||
// FOR WORDS IN ALL UPPERCASE (ONLY ONE "S" IS ALLOWED, ASSUMING IT'S NOT AN ACRONYM)
|
||||
private static readonly Regex RegexUpper = new(@"(?<!\w)(SH*[BCDFGJKLMNPQRTVWXZ])");
|
||||
|
||||
public override string Accentuate(string message, Entity<SpanishAccentComponent>? ent = null)
|
||||
{
|
||||
// Insert E before every S
|
||||
// Insert E before every S that is followed by a consonant that makes a distinct sound
|
||||
// (H is excluded because [sh] is a single sound)
|
||||
message = InsertS(message);
|
||||
// If a sentence ends with ?, insert a reverse ? at the beginning of the sentence
|
||||
message = ReplacePunctuation(message);
|
||||
|
|
@ -17,20 +26,11 @@ public sealed class SpanishAccentSystem : RelayAccentSystem<SpanishAccentCompone
|
|||
|
||||
private string InsertS(string message)
|
||||
{
|
||||
// Replace every new Word that starts with s/S
|
||||
var msg = message.Replace(" s", " es").Replace(" S", " Es");
|
||||
|
||||
// Still need to check if the beginning of the message starts
|
||||
if (msg.StartsWith("s", StringComparison.Ordinal))
|
||||
{
|
||||
return msg.Remove(0, 1).Insert(0, "es");
|
||||
}
|
||||
else if (msg.StartsWith("S", StringComparison.Ordinal))
|
||||
{
|
||||
return msg.Remove(0, 1).Insert(0, "Es");
|
||||
}
|
||||
|
||||
return msg;
|
||||
// Replace every new Word that starts with s/S and a consonant
|
||||
message = RegexLower.Replace(message, "e$1");
|
||||
message = RegexCaps.Replace(message, "Es$1");
|
||||
message = RegexUpper.Replace(message, "E$1");
|
||||
return message;
|
||||
}
|
||||
|
||||
private string ReplacePunctuation(string message)
|
||||
|
|
@ -51,13 +51,11 @@ public sealed class SpanishAccentSystem : RelayAccentSystem<SpanishAccentCompone
|
|||
});
|
||||
}
|
||||
if (toInsert.Length == 0)
|
||||
{
|
||||
msg.Append(s);
|
||||
} else
|
||||
{
|
||||
else
|
||||
msg.Append(s.Insert(s.Length - s.TrimStart().Length, toInsert.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
return msg.ToString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ trait-french-name = French accent
|
|||
trait-french-desc = Your accent seems to have a certain «je ne sais quoi».
|
||||
|
||||
trait-spanish-name = Spanish accent
|
||||
trait-spanish-desc = Hola señor, donde esta la biblioteca.
|
||||
trait-spanish-desc = Hola señor, ¿dónde está la biblioteca?
|
||||
|
||||
trait-scottish-name = Scottish accent
|
||||
trait-scottish-desc = Ye're speaking like ae proper Scot!
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue