TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches
GameCulture.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Diagnostics;
3using System.Globalization;
4using System.Linq;
5
7
8[DebuggerDisplay("{Name}")]
9public class GameCulture
10{
11 public enum CultureName
12 {
13 English = 1,
14 German = 2,
15 Italian = 3,
16 French = 4,
17 Spanish = 5,
18 Russian = 6,
19 Chinese = 7,
20 Portuguese = 8,
21 Polish = 9,
22 Unknown = 9999
23 }
24
26
28
30
31 public readonly int LegacyId;
32
34
35 public static GameCulture DefaultCulture { get; set; }
36
37 public bool IsActive => Language.ActiveCulture == this;
38
39 public string Name => CultureInfo.Name;
40
42 {
43 if (!_NamedCultures.ContainsKey(name))
44 {
45 return DefaultCulture;
46 }
47 return _NamedCultures[name];
48 }
49
50 public static GameCulture FromLegacyId(int id)
51 {
52 if (id < 1)
53 {
54 id = 1;
55 }
56 if (!_legacyCultures.ContainsKey(id))
57 {
58 return DefaultCulture;
59 }
60 return _legacyCultures[id];
61 }
62
63 public static GameCulture FromName(string name)
64 {
65 return _legacyCultures.Values.SingleOrDefault((GameCulture culture) => culture.Name == name) ?? DefaultCulture;
66 }
67
68 static GameCulture()
69 {
71 {
72 {
73 CultureName.English,
74 new GameCulture("en-US", 1)
75 },
76 {
77 CultureName.German,
78 new GameCulture("de-DE", 2)
79 },
80 {
81 CultureName.Italian,
82 new GameCulture("it-IT", 3)
83 },
84 {
85 CultureName.French,
86 new GameCulture("fr-FR", 4)
87 },
88 {
89 CultureName.Spanish,
90 new GameCulture("es-ES", 5)
91 },
92 {
93 CultureName.Russian,
94 new GameCulture("ru-RU", 6)
95 },
96 {
97 CultureName.Chinese,
98 new GameCulture("zh-Hans", 7)
99 },
100 {
101 CultureName.Portuguese,
102 new GameCulture("pt-BR", 8)
103 },
104 {
105 CultureName.Polish,
106 new GameCulture("pl-PL", 9)
107 }
108 };
110 }
111
112 public GameCulture(string name, int legacyId)
113 {
114 CultureInfo = new CultureInfo(name);
117 }
118
119 private static void RegisterLegacyCulture(GameCulture culture, int legacyId)
120 {
121 if (_legacyCultures == null)
122 {
124 }
125 _legacyCultures.Add(legacyId, culture);
126 }
127}
static GameCulture FromCultureName(CultureName name)
static GameCulture FromLegacyId(int id)
static IEnumerable< GameCulture > KnownCultures
static void RegisterLegacyCulture(GameCulture culture, int legacyId)
static GameCulture FromName(string name)
readonly CultureInfo CultureInfo
static Dictionary< int, GameCulture > _legacyCultures
static GameCulture DefaultCulture
GameCulture(string name, int legacyId)
static Dictionary< CultureName, GameCulture > _NamedCultures