diff --git a/Content.Server/Chat/Systems/ChatSystem.cs b/Content.Server/Chat/Systems/ChatSystem.cs index 09064bd634..0c9ebe4790 100644 --- a/Content.Server/Chat/Systems/ChatSystem.cs +++ b/Content.Server/Chat/Systems/ChatSystem.cs @@ -1,3 +1,4 @@ +using System.Globalization; using System.Linq; using System.Text; using Content.Server.Administration.Logs; @@ -199,8 +200,11 @@ public sealed partial class ChatSystem : SharedChatSystem bool shouldCapitalize = (desiredType != InGameICChatType.Emote); bool shouldPunctuate = _configurationManager.GetCVar(CCVars.ChatPunctuation); + // Capitalizing the word I only happens in English, so we check language here + bool shouldCapitalizeTheWordI = (!CultureInfo.CurrentCulture.IsNeutralCulture && CultureInfo.CurrentCulture.Parent.Name == "en") + || (CultureInfo.CurrentCulture.IsNeutralCulture && CultureInfo.CurrentCulture.Name == "en"); - message = SanitizeInGameICMessage(source, message, out var emoteStr, shouldCapitalize, shouldPunctuate); + message = SanitizeInGameICMessage(source, message, out var emoteStr, shouldCapitalize, shouldPunctuate, shouldCapitalizeTheWordI); // Was there an emote in the message? If so, send it. if (player != null && emoteStr != message && emoteStr != null) @@ -677,11 +681,13 @@ public sealed partial class ChatSystem : SharedChatSystem } // ReSharper disable once InconsistentNaming - private string SanitizeInGameICMessage(EntityUid source, string message, out string? emoteStr, bool capitalize = true, bool punctuate = false) + private string SanitizeInGameICMessage(EntityUid source, string message, out string? emoteStr, bool capitalize = true, bool punctuate = false, bool capitalizeTheWordI = true) { var newMessage = message.Trim(); if (capitalize) newMessage = SanitizeMessageCapital(newMessage); + if (capitalizeTheWordI) + newMessage = SanitizeMessageCapitalizeTheWordI(newMessage, "i"); if (punctuate) newMessage = SanitizeMessagePeriod(newMessage); diff --git a/Content.Shared/Chat/SharedChatSystem.cs b/Content.Shared/Chat/SharedChatSystem.cs index 0517cfd2b9..24cf1c4649 100644 --- a/Content.Shared/Chat/SharedChatSystem.cs +++ b/Content.Shared/Chat/SharedChatSystem.cs @@ -162,4 +162,33 @@ public abstract class SharedChatSystem : EntitySystem message = char.ToUpper(message[0]) + message.Remove(0, 1); return message; } + + public string SanitizeMessageCapitalizeTheWordI(string message, string theWordI = "i") + { + if (string.IsNullOrEmpty(message)) + return message; + + for + ( + var index = message.IndexOf(theWordI); + index != -1; + index = message.IndexOf(theWordI, index + 1) + ) + { + // Stops the code If It's tryIng to capItalIze the letter I In the mIddle of words + // Repeating the code twice is the simplest option + if (index + 1 < message.Length && char.IsLetter(message[index + 1])) + continue; + if (index - 1 >= 0 && char.IsLetter(message[index - 1])) + continue; + + var beforeTarget = message.Substring(0, index); + var target = message.Substring(index, theWordI.Length); + var afterTarget = message.Substring(index + theWordI.Length); + + message = beforeTarget + target.ToUpper() + afterTarget; + } + + return message; + } }