-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
83 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using CounterStrikeSharp.API.Modules.Utils; | ||
using Microsoft.Extensions.Localization; | ||
|
||
namespace InstadefusePlugin.Modules; | ||
|
||
public class Translator | ||
{ | ||
private IStringLocalizer _stringLocalizerImplementation; | ||
|
||
public Translator(IStringLocalizer localizer) | ||
{ | ||
_stringLocalizerImplementation = localizer; | ||
} | ||
|
||
public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures) | ||
{ | ||
return _stringLocalizerImplementation.GetAllStrings(includeParentCultures); | ||
} | ||
|
||
public string this[string name] => Translate(name); | ||
|
||
public string this[string name, params object[] arguments] => Translate(name, arguments); | ||
|
||
private string Translate(string key, params object[] arguments) | ||
{ | ||
var localizedString = _stringLocalizerImplementation[key, arguments]; | ||
|
||
if (localizedString == null || localizedString.ResourceNotFound) | ||
{ | ||
return key; | ||
} | ||
|
||
var translation = localizedString.Value; | ||
|
||
// Handle translation colours | ||
return translation | ||
.Replace("[GREEN]", ChatColors.Green.ToString()) | ||
.Replace("[RED]", ChatColors.Red.ToString()) | ||
.Replace("[YELLOW]", ChatColors.Yellow.ToString()) | ||
.Replace("[BLUE]", ChatColors.Blue.ToString()) | ||
.Replace("[PURPLE]", ChatColors.Purple.ToString()) | ||
.Replace("[ORANGE]", ChatColors.Orange.ToString()) | ||
.Replace("[WHITE]", ChatColors.White.ToString()) | ||
.Replace("[NORMAL]", ChatColors.White.ToString()) | ||
.Replace("[GREY]", ChatColors.Grey.ToString()) | ||
.Replace("[LIGHT_RED]", ChatColors.LightRed.ToString()) | ||
.Replace("[LIGHT_BLUE]", ChatColors.LightBlue.ToString()) | ||
.Replace("[LIGHT_PURPLE]", ChatColors.LightPurple.ToString()) | ||
.Replace("[LIGHT_YELLOW]", ChatColors.LightYellow.ToString()) | ||
.Replace("[DARK_RED]", ChatColors.DarkRed.ToString()) | ||
.Replace("[DARK_BLUE]", ChatColors.DarkBlue.ToString()) | ||
.Replace("[BLUE_GREY]", ChatColors.BlueGrey.ToString()) | ||
.Replace("[OLIVE]", ChatColors.Olive.ToString()) | ||
.Replace("[LIME]", ChatColors.Lime.ToString()) | ||
.Replace("[GOLD]", ChatColors.Gold.ToString()) | ||
.Replace("[SILVER]", ChatColors.Silver.ToString()) | ||
.Replace("[MAGENTA]", ChatColors.Magenta.ToString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"instadefuse.prefix": "[[GREEN]Retakes[NORMAL]] ", | ||
|
||
"instadefuse.unsuccessful": "{0} was [DARK_RED]{1} seconds[WHITE] away from defusing.", | ||
"instadefuse.successful": "{0} defused with [GREEN]{1} seconds[WHITE] left on the bomb.", | ||
"instadefuse.not_possible": "Instant Defuse not possible because a grenade threat is active!" | ||
} |