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