From d1b72117058f1131046b6aa3add8e3ccfae033d8 Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 09 十一月 2026 10:36:07 +0800
Subject: [PATCH] docs: CAN 模拟器独立 TCP 服务进程设计规格(统一 CanDeviceDriver + 双工推送协议)

---
 HMI.Core/Util/LangUtil.cs |   70 +++++++++++++---------------------
 1 files changed, 27 insertions(+), 43 deletions(-)

diff --git a/HMI.Core/Util/LangUtil.cs b/HMI.Core/Util/LangUtil.cs
index abda81f..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,14 +58,12 @@
         {
             try
             {
-                /// 鎸塉son鍔犺浇
-                //LoadAllDataByJson();
-                /// 涓嬮潰鏄寜xaml鍔犺浇
-                LoadAllDataByXaml();
+                LoadAllData();
                 LoadLang();
             }
-            finally { 
-                
+            finally
+            {
+
             }
         }
 
@@ -131,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