forked from B3none/cs2-instadefuse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Translator.cs
59 lines (49 loc) · 2.34 KB
/
Translator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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());
}
}