自动添加新控件的翻译

This commit is contained in:
dev
2022-05-24 09:58:10 +08:00
parent 80b9aab619
commit ab6f8874c5
3 changed files with 22 additions and 23 deletions

View File

@@ -27,9 +27,6 @@ namespace CleanMachineHMI
Application.EnableVisualStyles(); Application.EnableVisualStyles();
//frmUtil.DB2Json();//语言字典从数据库转json //frmUtil.DB2Json();//语言字典从数据库转json
Global.LoadTheme(); Global.LoadTheme();
#if DEBUG
Global.LoadzhCN();
#endif
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Global.LoadAllFormData(); Global.LoadAllFormData();
Application.Run(Global.LoginForm); Application.Run(Global.LoginForm);

View File

@@ -335,20 +335,20 @@ namespace CleanMachineHMI
} }
} }
public static void LoadzhCN() //public static void LoadzhCN()
{ //{
if (Utils.frmUtil.znCNLang == null || Utils.frmUtil.znCNLang.Count == 0) // if (Utils.frmUtil.znCNLang == null || Utils.frmUtil.znCNLang.Count == 0)
{ // {
var appPath = System.Windows.Forms.Application.StartupPath.Split(new string[] { @"bin\Debug" }, StringSplitOptions.RemoveEmptyEntries)[0]; // var appPath = System.Windows.Forms.Application.StartupPath.Split(new string[] { @"bin\Debug" }, StringSplitOptions.RemoveEmptyEntries)[0];
var filePath = appPath + $"Lang\\zh-CN.json"; // var filePath = appPath + $"Lang\\zh-CN.json";
if (!File.Exists(filePath)) // if (!File.Exists(filePath))
{ // {
return; // return;
} // }
var str = File.ReadAllText(filePath); // var str = File.ReadAllText(filePath);
Utils.frmUtil.znCNLang = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ThemeLanguage>>(str); // Utils.frmUtil.znCNLang = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ThemeLanguage>>(str);
} // }
} //}
} }
} }

View File

@@ -21,7 +21,10 @@ namespace CleanMachineHMI.Utils
/// </summary> /// </summary>
public static class frmUtil public static class frmUtil
{ {
public static List<ThemeLanguage> znCNLang = new List<ThemeLanguage>(); /// <summary>
/// 新增的翻译
/// </summary>
public static List<ThemeLanguage> _newlyLang = new List<ThemeLanguage>();
/// <summary> /// <summary>
/// 给一个字符串进行MD5加密 /// 给一个字符串进行MD5加密
@@ -351,20 +354,19 @@ namespace CleanMachineHMI.Utils
return; return;
} }
var codes = key.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); var codes = key.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
if (Global.ThemeLanguage.ContainsKey(key))
if (znCNLang.Any(x => x.formCode == codes[0] && x.controlCode == codes[1]))
{ {
return; return;
} }
znCNLang.Add(new ThemeLanguage _newlyLang.Add(new ThemeLanguage
{ {
formCode = codes[0], formCode = codes[0],
controlCode = codes[1], controlCode = codes[1],
controlName = string.IsNullOrEmpty(options) ? name : null, controlName = string.IsNullOrEmpty(options) ? name : null,
options = string.IsNullOrEmpty(options) ? null : options.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList(), options = string.IsNullOrEmpty(options) ? null : options.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList(),
}); });
var str1 = Newtonsoft.Json.JsonConvert.SerializeObject(znCNLang); var str1 = Newtonsoft.Json.JsonConvert.SerializeObject(_newlyLang);
WriteLangFile("zh-CN.json", str1); WriteLangFile("newly.json", str1);
} }
} }