自动添加新控件的翻译

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();
//frmUtil.DB2Json();//语言字典从数据库转json
Global.LoadTheme();
#if DEBUG
Global.LoadzhCN();
#endif
Application.SetCompatibleTextRenderingDefault(false);
Global.LoadAllFormData();
Application.Run(Global.LoginForm);

View File

@@ -335,20 +335,20 @@ namespace CleanMachineHMI
}
}
public static void LoadzhCN()
{
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 filePath = appPath + $"Lang\\zh-CN.json";
if (!File.Exists(filePath))
{
return;
}
var str = File.ReadAllText(filePath);
Utils.frmUtil.znCNLang = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ThemeLanguage>>(str);
//public static void LoadzhCN()
//{
// 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 filePath = appPath + $"Lang\\zh-CN.json";
// if (!File.Exists(filePath))
// {
// return;
// }
// var str = File.ReadAllText(filePath);
// Utils.frmUtil.znCNLang = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ThemeLanguage>>(str);
}
}
// }
//}
}
}

View File

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