-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLocalizationService.cs
More file actions
242 lines (233 loc) · 10.4 KB
/
Copy pathLocalizationService.cs
File metadata and controls
242 lines (233 loc) · 10.4 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace GeneralUpdate.Tools.Services;
/// <summary>
/// Simple dictionary-based localization. Supports zh-CN and en-US.
/// Usage: LocalizationService.Instance["Patch.Title"]
/// </summary>
public class LocalizationService : INotifyPropertyChanged
{
public static LocalizationService Instance { get; } = new();
private string _locale = "zh-CN";
public string Locale
{
get => _locale;
set
{
if (_locale != value)
{
_locale = value;
OnPropertyChanged();
OnPropertyChanged("Item");
}
}
}
public string this[string key]
{
get
{
if (_strings.TryGetValue(_locale, out var langDict) && langDict.TryGetValue(key, out var val))
return val;
// Fallback to zh-CN
if (_locale != "zh-CN" && _strings.TryGetValue("zh-CN", out var fallback) &&
fallback.TryGetValue(key, out var fb))
return fb;
return key;
}
}
private readonly Dictionary<string, Dictionary<string, string>> _strings = new()
{
["zh-CN"] = new()
{
["App.Title"] = "GeneralUpdate Tools",
["Nav.Patch"] = "补丁包",
["Nav.Extension"] = "扩展包",
["Nav.OSS"] = "OSS配置",
["Patch.Title"] = "补丁包生成",
["Patch.CorePaths"] = "核心路径",
["Patch.OldDir"] = "旧版本目录",
["Patch.NewDir"] = "新版本目录",
["Patch.Select"] = "选择",
["Patch.OldPlaceholder"] = "选择旧版本应用目录...",
["Patch.NewPlaceholder"] = "选择新版本发布目录...",
["Patch.PackageInfo"] = "包信息",
["Patch.PackageName"] = "包名",
["Patch.Version"] = "版本",
["Patch.OutputDir"] = "输出目录",
["Patch.OutputPlaceholder"] = "桌面 (默认)",
["Patch.Build"] = "开始构建",
["Patch.Ready"] = "就绪",
["Patch.ValidateDirs"] = "请选择新旧版本目录",
["Patch.Building"] = "正在生成差分补丁...",
["Patch.Comparing"] = "对比目录差异 + 生成补丁...",
["Patch.PatchDone"] = "补丁生成完成",
["Patch.Packing"] = "打包: {0}",
["Patch.Success"] = "成功: {0} ({1:F1} KB)",
["Patch.Failed"] = "失败: {0}",
["Patch.Error"] = "错误: {0}",
["Patch.OldSelected"] = "旧版本: {0}",
["Patch.NewSelected"] = "新版本: {0}",
["Patch.TempDir"] = "临时目录: {0}",
["Ext.Title"] = "扩展包生成",
["Ext.BasicInfo"] = "基本信息",
["Ext.Name"] = "名称",
["Ext.Version"] = "版本",
["Ext.Description"] = "描述",
["Ext.DescPlaceholder"] = "扩展功能描述...",
["Ext.Publisher"] = "发布者",
["Ext.License"] = "许可证",
["Ext.LicensePlaceholder"] = "MIT",
["Ext.Paths"] = "路径",
["Ext.ExtDir"] = "扩展目录",
["Ext.ExportDir"] = "导出目录",
["Ext.CustomProps"] = "自定义属性",
["Ext.Key"] = "Key",
["Ext.Value"] = "Value",
["Ext.AddProp"] = "+ 添加",
["Ext.Generate"] = "生成扩展包",
["Ext.ValidateNameVer"] = "请填写扩展名称和版本",
["Ext.ValidateDir"] = "请选择有效的扩展目录",
["Ext.Building"] = "正在生成扩展包...",
["Ext.Success"] = "成功: {0}",
["Ext.Failed"] = "失败: {0}",
["OSS.Title"] = "OSS 配置生成",
["OSS.NewEntry"] = "新建条目",
["OSS.PacketName"] = "包名",
["OSS.Version"] = "版本",
["OSS.Url"] = "URL",
["OSS.SHA256"] = "SHA256",
["OSS.ComputeHash"] = "计算",
["OSS.AddToList"] = "添加到列表",
["OSS.ConfigList"] = "配置列表",
["OSS.Clear"] = "清空",
["OSS.Export"] = "导出 JSON",
["OSS.Added"] = "已添加",
["OSS.Cleared"] = "已清空",
["OSS.Exported"] = "导出: {0} 条",
["OSS.HashResult"] = "SHA256: {0}",
["Theme.Light"] = "浅色",
["Theme.Dark"] = "深色",
["Theme.Toggle"] = "切换主题",
["Nav.Simulate"] = "模拟更新",
["Sim.Title"] = "模拟更新",
["Sim.TestTarget"] = "测试目标",
["Sim.OldAppDir"] = "旧版本应用目录",
["Sim.PatchFile"] = "补丁包文件",
["Sim.Select"] = "选择",
["Sim.UpdateConfig"] = "更新配置",
["Sim.CurrentVer"] = "当前版本",
["Sim.TargetVer"] = "目标版本",
["Sim.Platform"] = "平台",
["Sim.AppType"] = "应用类型",
["Sim.AppSecret"] = "应用密钥",
["Sim.ProductId"] = "产品ID",
["Sim.Output"] = "输出",
["Sim.OutputDir"] = "模拟目录",
["Sim.Start"] = "开始模拟",
["Sim.SelectAppDir"] = "选择旧版本应用目录",
["Sim.SelectPatch"] = "选择补丁包",
["Sim.SelectOutput"] = "选择模拟输出目录",
["Sim.ValidateDirs"] = "请填写所有必填项",
["Sim.DotnetCheck"] = "需要 .NET 10.0 SDK,请先安装",
},
["en-US"] = new()
{
["App.Title"] = "GeneralUpdate Tools",
["Nav.Patch"] = "Patch",
["Nav.Extension"] = "Extension",
["Nav.OSS"] = "OSS Config",
["Patch.Title"] = "Patch Package",
["Patch.CorePaths"] = "Core Paths",
["Patch.OldDir"] = "Old Directory",
["Patch.NewDir"] = "New Directory",
["Patch.Select"] = "Select",
["Patch.OldPlaceholder"] = "Select old version directory...",
["Patch.NewPlaceholder"] = "Select new version directory...",
["Patch.PackageInfo"] = "Package Info",
["Patch.PackageName"] = "Package Name",
["Patch.Version"] = "Version",
["Patch.OutputDir"] = "Output Directory",
["Patch.OutputPlaceholder"] = "Desktop (default)",
["Patch.Build"] = "Build",
["Patch.Ready"] = "Ready",
["Patch.ValidateDirs"] = "Please select both old and new directories",
["Patch.Building"] = "Generating diff patch...",
["Patch.Comparing"] = "Comparing directories + generating patches...",
["Patch.PatchDone"] = "Patch generation complete",
["Patch.Packing"] = "Packing: {0}",
["Patch.Success"] = "Success: {0} ({1:F1} KB)",
["Patch.Failed"] = "Failed: {0}",
["Patch.Error"] = "Error: {0}",
["Patch.OldSelected"] = "Old version: {0}",
["Patch.NewSelected"] = "New version: {0}",
["Patch.TempDir"] = "Temp directory: {0}",
["Ext.Title"] = "Extension Package",
["Ext.BasicInfo"] = "Basic Info",
["Ext.Name"] = "Name",
["Ext.Version"] = "Version",
["Ext.Description"] = "Description",
["Ext.DescPlaceholder"] = "Extension description...",
["Ext.Publisher"] = "Publisher",
["Ext.License"] = "License",
["Ext.LicensePlaceholder"] = "MIT",
["Ext.Paths"] = "Paths",
["Ext.ExtDir"] = "Extension Directory",
["Ext.ExportDir"] = "Export Directory",
["Ext.CustomProps"] = "Custom Properties",
["Ext.Key"] = "Key",
["Ext.Value"] = "Value",
["Ext.AddProp"] = "+ Add",
["Ext.Generate"] = "Generate Extension",
["Ext.ValidateNameVer"] = "Please fill in extension name and version",
["Ext.ValidateDir"] = "Please select a valid extension directory",
["Ext.Building"] = "Generating extension package...",
["Ext.Success"] = "Success: {0}",
["Ext.Failed"] = "Failed: {0}",
["OSS.Title"] = "OSS Config Generator",
["OSS.NewEntry"] = "New Entry",
["OSS.PacketName"] = "Package Name",
["OSS.Version"] = "Version",
["OSS.Url"] = "URL",
["OSS.SHA256"] = "SHA256",
["OSS.ComputeHash"] = "Compute",
["OSS.AddToList"] = "Add to List",
["OSS.ConfigList"] = "Config List",
["OSS.Clear"] = "Clear",
["OSS.Export"] = "Export JSON",
["OSS.Added"] = "Added",
["OSS.Cleared"] = "Cleared",
["OSS.Exported"] = "Exported: {0} entries",
["OSS.HashResult"] = "SHA256: {0}",
["Theme.Light"] = "Light",
["Theme.Dark"] = "Dark",
["Theme.Toggle"] = "Toggle Theme",
["Nav.Simulate"] = "Simulate",
["Sim.Title"] = "Simulate Update",
["Sim.TestTarget"] = "Test Target",
["Sim.OldAppDir"] = "Old App Directory",
["Sim.PatchFile"] = "Patch Package",
["Sim.Select"] = "Select",
["Sim.UpdateConfig"] = "Update Config",
["Sim.CurrentVer"] = "Current Version",
["Sim.TargetVer"] = "Target Version",
["Sim.Platform"] = "Platform",
["Sim.AppType"] = "App Type",
["Sim.AppSecret"] = "App Secret",
["Sim.ProductId"] = "Product ID",
["Sim.Output"] = "Output",
["Sim.OutputDir"] = "Simulate Directory",
["Sim.Start"] = "Start Simulation",
["Sim.SelectAppDir"] = "Select old version directory",
["Sim.SelectPatch"] = "Select patch package",
["Sim.SelectOutput"] = "Select simulation output directory",
["Sim.ValidateDirs"] = "Please fill in all required fields",
["Sim.DotnetCheck"] = ".NET 10.0 SDK is required. Please install it first.",
}
};
public event PropertyChangedEventHandler? PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string? name = null) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
public string T(string key) => this[key];
public string T(string key, params object[] args) => string.Format(this[key], args);
}