Improved Spanish accent (#30551)
* Spanish and French comment * Added the interrobang * Make spanish accent use sting builder
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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 ;.
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user