From cac2202420eb105b47626291e7aa7f4ae996724b Mon Sep 17 00:00:00 2001 From: B3none Date: Sat, 17 Feb 2024 15:18:08 +0000 Subject: [PATCH] Continued updates to translation layer --- Modules/Translator.cs | 79 ++++++++++++++++++------------------------- RetakesPlugin.cs | 2 +- 2 files changed, 33 insertions(+), 48 deletions(-) diff --git a/Modules/Translator.cs b/Modules/Translator.cs index 19a9d2f..9d0db53 100644 --- a/Modules/Translator.cs +++ b/Modules/Translator.cs @@ -21,13 +21,21 @@ public IEnumerable GetAllStrings(bool includeParentCultures) public string this[string name, params object[] arguments] => Translate(name, arguments); + private const string CenterModifier = "center."; + private const string HtmlModifier = "html."; + private string Translate(string key, params object[] arguments) { - var centerModifier = "center."; - var isCenter = key.StartsWith(centerModifier); + var isCenter = key.StartsWith(CenterModifier); + var isHtml = key.StartsWith(HtmlModifier); + if (isCenter) { - key = key.Substring(centerModifier.Length); + key = key.Substring(CenterModifier.Length); + } + else if (isHtml) + { + key = key.Substring(HtmlModifier.Length); } var localizedString = _stringLocalizerImplementation[key, arguments]; @@ -40,50 +48,27 @@ private string Translate(string key, params object[] arguments) var translation = localizedString.Value; // Handle translation colours - // return translation - // .Replace("[GREEN]", isHtml ? "" : ChatColors.Green.ToString()) - // .Replace("[RED]", isHtml ? "" : ChatColors.Red.ToString()) - // .Replace("[YELLOW]", isHtml ? "" : ChatColors.Yellow.ToString()) - // .Replace("[BLUE]", isHtml ? "" : ChatColors.Blue.ToString()) - // .Replace("[PURPLE]", isHtml ? "" : ChatColors.Purple.ToString()) - // .Replace("[ORANGE]", isHtml ? "" : ChatColors.Orange.ToString()) - // .Replace("[WHITE]", isHtml ? "" : ChatColors.White.ToString()) - // .Replace("[NORMAL]", isHtml ? "" : ChatColors.White.ToString()) - // .Replace("[GREY]", isHtml ? "" : ChatColors.Grey.ToString()) - // .Replace("[LIGHT_RED]", isHtml ? "" : ChatColors.LightRed.ToString()) - // .Replace("[LIGHT_BLUE]", isHtml ? "" : ChatColors.LightBlue.ToString()) - // .Replace("[LIGHT_PURPLE]", isHtml ? "" : ChatColors.LightPurple.ToString()) - // .Replace("[LIGHT_YELLOW]", isHtml ? "" : ChatColors.LightYellow.ToString()) - // .Replace("[DARK_RED]", isHtml ? "" : ChatColors.DarkRed.ToString()) - // .Replace("[DARK_BLUE]", isHtml ? "" : ChatColors.DarkBlue.ToString()) - // .Replace("[BLUE_GREY]", isHtml ? "" : ChatColors.BlueGrey.ToString()) - // .Replace("[OLIVE]", isHtml ? "" : ChatColors.Olive.ToString()) - // .Replace("[LIME]", isHtml ? "" : ChatColors.Lime.ToString()) - // .Replace("[GOLD]", isHtml ? "" : ChatColors.Gold.ToString()) - // .Replace("[SILVER]", isHtml ? "" : ChatColors.Silver.ToString()) - // .Replace("[MAGENTA]", isHtml ? "" : ChatColors.Magenta.ToString()); - return translation - .Replace("[GREEN]", isCenter ? "" : ChatColors.Green.ToString()) - .Replace("[RED]", isCenter ? "" : ChatColors.Red.ToString()) - .Replace("[YELLOW]", isCenter ? "" : ChatColors.Yellow.ToString()) - .Replace("[BLUE]", isCenter ? "" : ChatColors.Blue.ToString()) - .Replace("[PURPLE]", isCenter ? "" : ChatColors.Purple.ToString()) - .Replace("[ORANGE]", isCenter ? "" : ChatColors.Orange.ToString()) - .Replace("[WHITE]", isCenter ? "" : ChatColors.White.ToString()) - .Replace("[NORMAL]", isCenter ? "" : ChatColors.White.ToString()) - .Replace("[GREY]", isCenter ? "" : ChatColors.Grey.ToString()) - .Replace("[LIGHT_RED]", isCenter ? "" : ChatColors.LightRed.ToString()) - .Replace("[LIGHT_BLUE]", isCenter ? "" : ChatColors.LightBlue.ToString()) - .Replace("[LIGHT_PURPLE]", isCenter ? "" : ChatColors.LightPurple.ToString()) - .Replace("[LIGHT_YELLOW]", isCenter ? "" : ChatColors.LightYellow.ToString()) - .Replace("[DARK_RED]", isCenter ? "" : ChatColors.DarkRed.ToString()) - .Replace("[DARK_BLUE]", isCenter ? "" : ChatColors.DarkBlue.ToString()) - .Replace("[BLUE_GREY]", isCenter ? "" : ChatColors.BlueGrey.ToString()) - .Replace("[OLIVE]", isCenter ? "" : ChatColors.Olive.ToString()) - .Replace("[LIME]", isCenter ? "" : ChatColors.Lime.ToString()) - .Replace("[GOLD]", isCenter ? "" : ChatColors.Gold.ToString()) - .Replace("[SILVER]", isCenter ? "" : ChatColors.Silver.ToString()) - .Replace("[MAGENTA]", isCenter ? "" : ChatColors.Magenta.ToString()); + .Replace("[GREEN]", isCenter ? "" : isHtml ? "" : ChatColors.Green.ToString()) + .Replace("[RED]", isCenter ? "" : isHtml ? "" : ChatColors.Red.ToString()) + .Replace("[YELLOW]", isCenter ? "" : isHtml ? "" : ChatColors.Yellow.ToString()) + .Replace("[BLUE]", isCenter ? "" : isHtml ? "" : ChatColors.Blue.ToString()) + .Replace("[PURPLE]", isCenter ? "" : isHtml ? "" : ChatColors.Purple.ToString()) + .Replace("[ORANGE]", isCenter ? "" : isHtml ? "" : ChatColors.Orange.ToString()) + .Replace("[WHITE]", isCenter ? "" : isHtml ? "" : ChatColors.White.ToString()) + .Replace("[NORMAL]", isCenter ? "" : isHtml ? "" : ChatColors.White.ToString()) + .Replace("[GREY]", isCenter ? "" : isHtml ? "" : ChatColors.Grey.ToString()) + .Replace("[LIGHT_RED]", isCenter ? "" : isHtml ? "" : ChatColors.LightRed.ToString()) + .Replace("[LIGHT_BLUE]", isCenter ? "" : isHtml ? "" : ChatColors.LightBlue.ToString()) + .Replace("[LIGHT_PURPLE]", isCenter ? "" : isHtml ? "" : ChatColors.LightPurple.ToString()) + .Replace("[LIGHT_YELLOW]", isCenter ? "" : isHtml ? "" : ChatColors.LightYellow.ToString()) + .Replace("[DARK_RED]", isCenter ? "" : isHtml ? "" : ChatColors.DarkRed.ToString()) + .Replace("[DARK_BLUE]", isCenter ? "" : isHtml ? "" : ChatColors.DarkBlue.ToString()) + .Replace("[BLUE_GREY]", isCenter ? "" : isHtml ? "" : ChatColors.BlueGrey.ToString()) + .Replace("[OLIVE]", isCenter ? "" : isHtml ? "" : ChatColors.Olive.ToString()) + .Replace("[LIME]", isCenter ? "" : isHtml ? "" : ChatColors.Lime.ToString()) + .Replace("[GOLD]", isCenter ? "" : isHtml ? "" : ChatColors.Gold.ToString()) + .Replace("[SILVER]", isCenter ? "" : isHtml ? "" : ChatColors.Silver.ToString()) + .Replace("[MAGENTA]", isCenter ? "" : isHtml ? "" : ChatColors.Magenta.ToString()); } } diff --git a/RetakesPlugin.cs b/RetakesPlugin.cs index 16e830c..89d24b2 100644 --- a/RetakesPlugin.cs +++ b/RetakesPlugin.cs @@ -17,7 +17,7 @@ namespace RetakesPlugin; [MinimumApiVersion(154)] public class RetakesPlugin : BasePlugin { - private const string Version = "1.3.28"; + private const string Version = "1.3.29"; #region Plugin info public override string ModuleName => "Retakes Plugin";