From 9211ec11c112e18cd99e77f889a01110a70031ce Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期一, 24 十一月 2025 17:47:15 +0800
Subject: [PATCH] 优化项目结构

---
 HMI.Core/Util/LangUtil.cs |   37 ++++++++++++++++++++++++++-----------
 1 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/HMI.Core/Util/LangUtil.cs b/HMI.Core/Util/LangUtil.cs
index 6a97afc..ce6f069 100644
--- a/HMI.Core/Util/LangUtil.cs
+++ b/HMI.Core/Util/LangUtil.cs
@@ -4,8 +4,8 @@
 using Newtonsoft.Json.Linq;
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.IO;
-using System.Runtime.InteropServices.ComTypes;
 using System.Windows;
 using System.Windows.Markup;
 
@@ -28,9 +28,17 @@
         {
 
         }
-        public static void LoadLang()
+
+        private static string GetLang()
         {
             var lang = SystemSetting.Instance.CurrentLanguage;
+            if (string.IsNullOrEmpty(lang)) lang = CultureInfo.CurrentUICulture.ToString();
+            return lang;
+        }
+
+        public static void LoadLang()
+        {
+            var lang = GetLang();
             if (!ResourceMap.ContainsKey(lang)) return;
             var newLang = ResourceMap[lang];
             if (currentResource == newLang)
@@ -47,16 +55,23 @@
 
         public static void Load()
         {
-            /// 鎸塉son鍔犺浇
-            //LoadAllDataByJson();
-            /// 涓嬮潰鏄寜xaml鍔犺浇
-            LoadAllDataByXaml();
-            LoadLang();
+            try
+            {
+                /// 鎸塉son鍔犺浇
+                //LoadAllDataByJson();
+                /// 涓嬮潰鏄寜xaml鍔犺浇
+                LoadAllDataByXaml();
+                LoadLang();
+            }
+            finally
+            {
+
+            }
         }
 
         public static string Get(string key)
         {
-            var lang = SystemSetting.Instance.CurrentLanguage;
+            var lang = GetLang();
             if (!JsonMap.ContainsKey(lang)) return key;
             if (!JsonMap[lang].ContainsKey(key)) return key;
             return JsonMap[lang][key].ToString();
@@ -98,7 +113,7 @@
                         }
                     }
                 }
-                catch (Exception ex)
+                catch
                 {
                 }
             }
@@ -146,7 +161,7 @@
                         }
                     }
                 }
-                catch (Exception ex)
+                catch
                 {
                 }
             }
@@ -171,7 +186,7 @@
 
     public static class LangReader
     {
-        public static string lang(this DependencyObject dp, string key, params object[] datas)
+        public static string lang(this object dp, string key, params object[] datas)
         {
             return string.Format(LangUtil.Get(key), datas);
         }

--
Gitblit v1.9.1