forked from E-riCA0/StawdewValley
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalizedContentManager.cs
More file actions
201 lines (183 loc) · 6.24 KB
/
LocalizedContentManager.cs
File metadata and controls
201 lines (183 loc) · 6.24 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// Decompiled with JetBrains decompiler
// Type: StardewValley.LocalizedContentManager
// Assembly: Stardew Valley, Version=1.2.6400.27469, Culture=neutral, PublicKeyToken=null
// MVID: 77B7094A-F6F0-4ACC-91F4-E335E2733EDB
// Assembly location: D:\SteamLibrary\steamapps\common\Stardew Valley\Stardew Valley.exe
using Microsoft.Xna.Framework.Content;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
namespace StardewValley
{
public class LocalizedContentManager : ContentManager
{
public const string genderDialogueSplitCharacter = "¦";
private static LocalizedContentManager.LanguageCode _currentLangCode;
public CultureInfo CurrentCulture;
public string LanguageCodeOverride;
public static event LocalizedContentManager.LanguageChangedHandler OnLanguageChange;
public static LocalizedContentManager.LanguageCode CurrentLanguageCode
{
get
{
return LocalizedContentManager._currentLangCode;
}
set
{
if (LocalizedContentManager._currentLangCode == value)
return;
LocalizedContentManager._currentLangCode = value;
if (LocalizedContentManager.OnLanguageChange != null)
LocalizedContentManager.OnLanguageChange(LocalizedContentManager._currentLangCode);
Console.WriteLine("Changed language to: " + (object) value);
}
}
public static bool CurrentLanguageLatin
{
get
{
if (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.en && LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.es && LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.de)
return LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.pt;
return true;
}
}
public LocalizedContentManager(IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, string languageCodeOverride)
: base(serviceProvider, rootDirectory)
{
this.CurrentCulture = currentCulture;
this.LanguageCodeOverride = languageCodeOverride;
}
public LocalizedContentManager(IServiceProvider serviceProvider, string rootDirectory)
: this(serviceProvider, rootDirectory, Thread.CurrentThread.CurrentUICulture, (string) null)
{
}
public T LoadBase<T>(string assetName)
{
return base.Load<T>(assetName);
}
public override T Load<T>(string assetName)
{
if (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.en)
{
string assetName1 = assetName + "." + this.languageCode();
try
{
return base.Load<T>(assetName1);
}
catch (ContentLoadException ex)
{
}
}
return base.Load<T>(assetName);
}
private string languageCode()
{
if (this.LanguageCodeOverride != null)
return this.LanguageCodeOverride;
string str = "";
switch (LocalizedContentManager.CurrentLanguageCode)
{
case LocalizedContentManager.LanguageCode.ja:
str = "ja-JP";
break;
case LocalizedContentManager.LanguageCode.ru:
str = "ru-RU";
break;
case LocalizedContentManager.LanguageCode.zh:
str = "zh-CN";
break;
case LocalizedContentManager.LanguageCode.pt:
str = "pt-BR";
break;
case LocalizedContentManager.LanguageCode.es:
str = "es-ES";
break;
case LocalizedContentManager.LanguageCode.de:
str = "de-DE";
break;
case LocalizedContentManager.LanguageCode.th:
str = "th-TH";
break;
}
return str;
}
public LocalizedContentManager.LanguageCode GetCurrentLanguage()
{
return LocalizedContentManager.CurrentLanguageCode;
}
private string GetString(Dictionary<string, string> strings, string key)
{
string str;
if (strings.TryGetValue(key + ".desktop", out str))
return str;
return strings[key];
}
public string LoadString(string path, params object[] substitutions)
{
string assetName;
string key;
this.parseStringPath(path, out assetName, out key);
Dictionary<string, string> strings = this.Load<Dictionary<string, string>>(assetName);
if (strings == null || !strings.ContainsKey(key))
return this.LoadBaseString(path, substitutions);
string format = this.GetString(strings, key);
if (format.Contains("¦"))
format = !Game1.player.IsMale ? format.Substring(format.IndexOf("¦") + 1) : format.Substring(0, format.IndexOf("¦"));
if (substitutions.Length == 0)
return format;
try
{
return string.Format(format, substitutions);
}
catch (Exception ex)
{
return format;
}
}
public string LoadBaseString(string path, params object[] substitutions)
{
string assetName;
string key;
this.parseStringPath(path, out assetName, out key);
Dictionary<string, string> strings = base.Load<Dictionary<string, string>>(assetName);
if (strings == null || !strings.ContainsKey(key))
return path;
string format = this.GetString(strings, key);
if (substitutions.Length == 0)
return format;
try
{
return string.Format(format, substitutions);
}
catch (Exception ex)
{
return format;
}
}
private void parseStringPath(string path, out string assetName, out string key)
{
int length = path.IndexOf(':');
if (length == -1)
throw new ContentLoadException("Unable to parse string path: " + path);
assetName = path.Substring(0, length);
key = path.Substring(length + 1, path.Length - length - 1);
}
public LocalizedContentManager CreateTemporary()
{
return new LocalizedContentManager(this.ServiceProvider, this.RootDirectory, this.CurrentCulture, this.LanguageCodeOverride);
}
public delegate void LanguageChangedHandler(LocalizedContentManager.LanguageCode code);
public enum LanguageCode
{
en,
ja,
ru,
zh,
pt,
es,
de,
th,
}
}
}