From 559890c482f5973f06aafdfec9550fee5ba3c7f2 Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 09 十一月 2026 17:02:15 +0800
Subject: [PATCH] feat: CAN 模拟器 TCP 化 + 多设备并发调试 + 后台生命周期管理
---
HMI.Core/Util/LangUtil.cs | 65 ++++++++++++--------------------
1 files changed, 24 insertions(+), 41 deletions(-)
diff --git a/HMI.Core/Util/LangUtil.cs b/HMI.Core/Util/LangUtil.cs
index ce6f069..bed038e 100644
--- a/HMI.Core/Util/LangUtil.cs
+++ b/HMI.Core/Util/LangUtil.cs
@@ -13,8 +13,9 @@
{
public class LangUtil
{
+ public const string DefaultLang = "zh-CN";
public static List<LangInfo> langs = new List<LangInfo>() {
- new LangInfo("zh-CN","涓枃"),
+ new LangInfo(DefaultLang,"涓枃"),
new LangInfo("en-US","English")
};
@@ -32,7 +33,7 @@
private static string GetLang()
{
var lang = SystemSetting.Instance.CurrentLanguage;
- if (string.IsNullOrEmpty(lang)) lang = CultureInfo.CurrentUICulture.ToString();
+ if (string.IsNullOrEmpty(lang)) lang = "zh-CN";
return lang;
}
@@ -57,10 +58,7 @@
{
try
{
- /// 鎸塉son鍔犺浇
- //LoadAllDataByJson();
- /// 涓嬮潰鏄寜xaml鍔犺浇
- LoadAllDataByXaml();
+ LoadAllData();
LoadLang();
}
finally
@@ -132,56 +130,41 @@
ResourceMap[lang] = resource;
}
-
- private static void LoadDataByXaml(string lang)
+ private static void LoadXamlFromJson2(string lang)
{
- string langFolder = PathHelper.LangFolder;
- string folder = Path.Combine(langFolder, lang);
- if (!Directory.Exists(folder))
+ LoadDataByJson(lang);
+
+ if (!JsonMap.ContainsKey(lang)) return;
+ JObject json = JsonMap[lang];
+ var resource = new ResourceDictionary();
+ foreach (var item in json)
{
- return;
+ resource.Add(item.Key, item.Value.ToString());
}
-
- string[] files = Directory.GetFiles(folder, "*.xaml", SearchOption.AllDirectories);
-
- foreach (var path in files)
+ ResourceMap[lang] = resource;
+ if (lang != DefaultLang)
{
- try
+ var defaultMap = new ResourceDictionary();
+ foreach (var item in json)
{
- using (FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read))
- {
- var resource = (ResourceDictionary)XamlReader.Load(stream);
- if (!ResourceMap.ContainsKey(lang))
- {
- ResourceMap[lang] = resource;
- }
- else
- {
- ResourceMap[lang].MergedDictionaries.Add(resource);
- }
- }
+ defaultMap.Add(item.Key, item.Key);
}
- catch
- {
- }
+ ResourceMap[DefaultLang] = defaultMap;
}
}
- private static void LoadAllDataByJson()
- {
- foreach (var lang in langs)
- {
- LoadDataByJson(lang.Code);
- }
- }
-
- private static void LoadAllDataByXaml()
+ private static void LoadAllData()
{
foreach (var lang in langs)
{
LoadXamlFromJson(lang.Code);
}
}
+
+ public static string Format(string key, params object[] datas)
+ {
+ return string.Format(Get(key), datas);
+ }
}
public static class LangReader
--
Gitblit v1.9.1