From b544d5cccd76735e034c8055918a50927b437474 Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期二, 10 十一月 2026 08:29:04 +0800
Subject: [PATCH] fix: 维护模式重复进入失败与按钮灰死 + Broker 并发验证用例
---
HMI.Core/Util/LangUtil.cs | 90 ++++++++++++++++++++++-----------------------
1 files changed, 44 insertions(+), 46 deletions(-)
diff --git a/HMI.Core/Util/LangUtil.cs b/HMI.Core/Util/LangUtil.cs
index 6a97afc..bed038e 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;
@@ -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")
};
@@ -28,9 +29,17 @@
{
}
- public static void LoadLang()
+
+ private static string GetLang()
{
var lang = SystemSetting.Instance.CurrentLanguage;
+ if (string.IsNullOrEmpty(lang)) lang = "zh-CN";
+ return lang;
+ }
+
+ public static void LoadLang()
+ {
+ var lang = GetLang();
if (!ResourceMap.ContainsKey(lang)) return;
var newLang = ResourceMap[lang];
if (currentResource == newLang)
@@ -47,16 +56,20 @@
public static void Load()
{
- /// 鎸塉son鍔犺浇
- //LoadAllDataByJson();
- /// 涓嬮潰鏄寜xaml鍔犺浇
- LoadAllDataByXaml();
- LoadLang();
+ try
+ {
+ LoadAllData();
+ 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 +111,7 @@
}
}
}
- catch (Exception ex)
+ catch
{
}
}
@@ -117,61 +130,46 @@
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 (Exception ex)
- {
- }
+ 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
{
- 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