-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalization.cs
More file actions
69 lines (62 loc) · 2.88 KB
/
Localization.cs
File metadata and controls
69 lines (62 loc) · 2.88 KB
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
60
61
62
63
64
65
66
67
68
69
using Rage;
using System.Collections.Generic;
using System.Globalization;
namespace DeleteThatEntity
{
public class Localization
{
private readonly string locale;
private readonly Dictionary<string, Dictionary<string, string>> strings = new Dictionary<string, Dictionary<string, string>>
{
{"en",
new Dictionary<string, string>{
{ "updateAvailable", "~y~Update available!" },
{ "entitySelected", "Entity ~b~:selectedEntity~w~ selected." },
{ "selectionConfirmation", "Press ~y~Delete~w~ to delete this entity, or ~y~Enter~w~ to cancel" },
{ "selectionConfirmationController", "Press ~y~Delete~w~/~INPUT_SPRINT~ to delete this entity, or ~y~Enter~w~/~INPUT_RELOAD~ to cancel" },
{ "nothingFound", "~o~Nothing found" },
{ "unableToDelete", "~o~Unable to delete this entity" },
{ "entityDeleted", "~g~Entity deleted" }
}
},
{"fr",
new Dictionary<string, string>{
{ "updateAvailable", "~y~Mise à jour disponible !" },
{ "entitySelected", "Entité ~b~:selectedEntity~w~ sélectionnée." },
{ "selectionConfirmation", "Appuyez sur ~y~Suppr~w~ pour confirmer, ou ~y~Entrer~w~ pour annuler" },
{ "selectionConfirmationController", "Appuyez sur ~y~Suppr~w~/~INPUT_SPRINT~ pour confirmer, ou ~y~Entrer~w~/~INPUT_RELOAD~ pour annuler" },
{ "nothingFound", "~o~Aucune entité trouvée" },
{ "unableToDelete", "~o~Impossible de supprimer cette entité" },
{ "entityDeleted", "~g~Entité supprimée" },
}
}
};
public Localization(string locale = "auto")
{
if (locale == "auto")
locale = CultureInfo.InstalledUICulture.Name.Split('-')[0];
else
locale = locale.Split('-')[0];
if (!strings.ContainsKey(locale))
locale = "en";
Game.LogTrivial($"Localization: Using locale '{locale.ToUpper()}'");
this.locale = locale;
}
public string GetString(string key, params (string key, object value)[] replace)
{
string localizedString;
if (strings[this.locale].ContainsKey(key))
localizedString = strings[this.locale][key];
else
{
localizedString = key;
Game.LogTrivial($"Localization: Missing translation for key '{key}'");
}
foreach (var replacement in replace)
{
localizedString = localizedString.Replace($":{replacement.key}", replacement.value?.ToString() ?? "");
}
return localizedString;
}
}
}