Improved Spanish accent (#30551)
* Spanish and French comment * Added the interrobang * Make spanish accent use sting builder
This commit is contained in:
@@ -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