Skip to content

Commit

Permalink
Continued updates to translation layer
Browse files Browse the repository at this point in the history
  • Loading branch information
B3none committed Feb 17, 2024
1 parent 5147551 commit cac2202
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 48 deletions.
79 changes: 32 additions & 47 deletions Modules/Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@ public IEnumerable<LocalizedString> 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];
Expand All @@ -40,50 +48,27 @@ private string Translate(string key, params object[] arguments)
var translation = localizedString.Value;

// Handle translation colours
// return translation
// .Replace("[GREEN]", isHtml ? "<font color='green'>" : ChatColors.Green.ToString())
// .Replace("[RED]", isHtml ? "<font color='red'>" : ChatColors.Red.ToString())
// .Replace("[YELLOW]", isHtml ? "<font color='yellow'>" : ChatColors.Yellow.ToString())
// .Replace("[BLUE]", isHtml ? "<font color='blue'>" : ChatColors.Blue.ToString())
// .Replace("[PURPLE]", isHtml ? "<font color='purple'>" : ChatColors.Purple.ToString())
// .Replace("[ORANGE]", isHtml ? "<font color='orange'>" : ChatColors.Orange.ToString())
// .Replace("[WHITE]", isHtml ? "<font color='white'>" : ChatColors.White.ToString())
// .Replace("[NORMAL]", isHtml ? "<font color='white'>" : ChatColors.White.ToString())
// .Replace("[GREY]", isHtml ? "<font color='grey'>" : ChatColors.Grey.ToString())
// .Replace("[LIGHT_RED]", isHtml ? "<font color='lightred'>" : ChatColors.LightRed.ToString())
// .Replace("[LIGHT_BLUE]", isHtml ? "<font color='lightblue'>" : ChatColors.LightBlue.ToString())
// .Replace("[LIGHT_PURPLE]", isHtml ? "<font color='mediumpurple'>" : ChatColors.LightPurple.ToString())
// .Replace("[LIGHT_YELLOW]", isHtml ? "<font color='lightyellow'>" : ChatColors.LightYellow.ToString())
// .Replace("[DARK_RED]", isHtml ? "<font color='darkred'>" : ChatColors.DarkRed.ToString())
// .Replace("[DARK_BLUE]", isHtml ? "<font color='darkblue'>" : ChatColors.DarkBlue.ToString())
// .Replace("[BLUE_GREY]", isHtml ? "<font color='grey'>" : ChatColors.BlueGrey.ToString())
// .Replace("[OLIVE]", isHtml ? "<font color='olive'>" : ChatColors.Olive.ToString())
// .Replace("[LIME]", isHtml ? "<font color='lime'>" : ChatColors.Lime.ToString())
// .Replace("[GOLD]", isHtml ? "<font color='gold'>" : ChatColors.Gold.ToString())
// .Replace("[SILVER]", isHtml ? "<font color='silver'>" : ChatColors.Silver.ToString())
// .Replace("[MAGENTA]", isHtml ? "<font color='magenta'>" : 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 ? "<font color='green'>" : ChatColors.Green.ToString())
.Replace("[RED]", isCenter ? "" : isHtml ? "<font color='red'>" : ChatColors.Red.ToString())
.Replace("[YELLOW]", isCenter ? "" : isHtml ? "<font color='yellow'>" : ChatColors.Yellow.ToString())
.Replace("[BLUE]", isCenter ? "" : isHtml ? "<font color='blue'>" : ChatColors.Blue.ToString())
.Replace("[PURPLE]", isCenter ? "" : isHtml ? "<font color='purple'>" : ChatColors.Purple.ToString())
.Replace("[ORANGE]", isCenter ? "" : isHtml ? "<font color='orange'>" : ChatColors.Orange.ToString())
.Replace("[WHITE]", isCenter ? "" : isHtml ? "<font color='white'>" : ChatColors.White.ToString())
.Replace("[NORMAL]", isCenter ? "" : isHtml ? "<font color='white'>" : ChatColors.White.ToString())
.Replace("[GREY]", isCenter ? "" : isHtml ? "<font color='grey'>" : ChatColors.Grey.ToString())
.Replace("[LIGHT_RED]", isCenter ? "" : isHtml ? "<font color='lightred'>" : ChatColors.LightRed.ToString())
.Replace("[LIGHT_BLUE]", isCenter ? "" : isHtml ? "<font color='lightblue'>" : ChatColors.LightBlue.ToString())
.Replace("[LIGHT_PURPLE]", isCenter ? "" : isHtml ? "<font color='mediumpurple'>" : ChatColors.LightPurple.ToString())
.Replace("[LIGHT_YELLOW]", isCenter ? "" : isHtml ? "<font color='lightyellow'>" : ChatColors.LightYellow.ToString())
.Replace("[DARK_RED]", isCenter ? "" : isHtml ? "<font color='darkred'>" : ChatColors.DarkRed.ToString())
.Replace("[DARK_BLUE]", isCenter ? "" : isHtml ? "<font color='darkblue'>" : ChatColors.DarkBlue.ToString())
.Replace("[BLUE_GREY]", isCenter ? "" : isHtml ? "<font color='grey'>" : ChatColors.BlueGrey.ToString())
.Replace("[OLIVE]", isCenter ? "" : isHtml ? "<font color='olive'>" : ChatColors.Olive.ToString())
.Replace("[LIME]", isCenter ? "" : isHtml ? "<font color='lime'>" : ChatColors.Lime.ToString())
.Replace("[GOLD]", isCenter ? "" : isHtml ? "<font color='gold'>" : ChatColors.Gold.ToString())
.Replace("[SILVER]", isCenter ? "" : isHtml ? "<font color='silver'>" : ChatColors.Silver.ToString())
.Replace("[MAGENTA]", isCenter ? "" : isHtml ? "<font color='magenta'>" : ChatColors.Magenta.ToString());
}
}
2 changes: 1 addition & 1 deletion RetakesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit cac2202

Please sign in to comment.