生成中文语言包

This commit is contained in:
ehkang
2022-03-19 12:46:23 +08:00
parent e9367f6b29
commit 55588c0e6e
19 changed files with 5505 additions and 9276 deletions

View File

@@ -9,7 +9,7 @@
<add key="GlobalPaletteMode" value="Professionaloffice2003"/>
<add key="LanguageCode" value="zh-CN"/>
<!--<add key="LanguageCode" value="English"/>-->
<!--<add key="LanguageCode" value="en-US"/>-->
<add key="sqlmapConfigPath" value="Config/sqlmap.config"/>
<!--MySql数据库连接字符串-->
<add key="LeadMySql" value="Data Source = localhost; Port=3306;Initial Catalog = testasrs; Persist Security Info=True;User ID = root; Password=sa1234567;"/>

View File

@@ -59,7 +59,7 @@ namespace CleanMachineHMI.FrmUserControl
dataGridView.Columns.Clear();
dataGridView.DataSource = dt;
dataGridView.SetDataViewColumnText(this.Name, GlobalHelper.LanguageCode);
dataGridView.SetDataViewColumnText(this.Name);
}
private void txt_GotFocus(object sender, EventArgs e)

View File

@@ -52,7 +52,7 @@ namespace CleanMachineHMI.FrmUserControl
dataGridView.Columns.Clear();
dataGridView.DataSource = dt;
dataGridView.SetDataViewColumnText(this.Name, GlobalHelper.LanguageCode);
dataGridView.SetDataViewColumnText(this.Name);
}
private void txt_GotFocus(object sender, EventArgs e)

View File

@@ -62,7 +62,7 @@ namespace CleanMachineHMI.FrmUserControl
dataGridView.Columns.Clear();
dataGridView.DataSource = dt;
dataGridView.SetDataViewColumnText(this.Name, GlobalHelper.LanguageCode);
dataGridView.SetDataViewColumnText(this.Name);
}
private void txt_GotFocus(object sender, EventArgs e)

View File

@@ -54,7 +54,7 @@ namespace CleanMachineHMI.FrmUserControl
dataGridView.Columns.Clear();
dataGridView.DataSource = dt;
dataGridView.SetDataViewColumnText(this.Name, GlobalHelper.LanguageCode);
dataGridView.SetDataViewColumnText(this.Name);
}
private void txt_GotFocus(object sender, EventArgs e)

View File

@@ -58,7 +58,7 @@ namespace CleanMachineHMI.FrmUserControl
dataGridView.Columns.Clear();
dataGridView.DataSource = dt;
dataGridView.SetDataViewColumnText(this.Name, GlobalHelper.LanguageCode);
dataGridView.SetDataViewColumnText(this.Name);
}
private void txt_GotFocus(object sender, EventArgs e)
{

View File

@@ -52,7 +52,7 @@ namespace CleanMachineHMI.FrmUserControl
dataGridView.Columns.Clear();
dataGridView.DataSource = dt;
dataGridView.SetDataViewColumnText(this.Name, GlobalHelper.LanguageCode);
dataGridView.SetDataViewColumnText(this.Name);
}
private void txt_GotFocus(object sender, EventArgs e)

View File

@@ -49,7 +49,7 @@ namespace CleanMachineHMI.FrmUserControl
dataGridView.Columns.Clear();
dataGridView.DataSource = dt;
dataGridView.SetDataViewColumnText(this.Name, GlobalHelper.LanguageCode);
dataGridView.SetDataViewColumnText(this.Name);
}

View File

@@ -55,7 +55,7 @@ namespace CleanMachineHMI.FrmUserControl
kryptonTextBox1.Text = currPalletMsg;
kryptonTextBox2.Text = currIrMsg;
kryptonDataGridView1.SetDataViewColumnText(this.Name, GlobalHelper.LanguageCode);
kryptonDataGridView1.SetDataViewColumnText(this.Name);
}
else
{

View File

@@ -52,7 +52,7 @@ namespace CleanMachineHMI.FrmUserControl
kryptonDataGridView1.Columns.Clear();
kryptonDataGridView1.DataSource = dt;
kryptonDataGridView1.SetDataViewColumnText(this.Name, GlobalHelper.LanguageCode);
kryptonDataGridView1.SetDataViewColumnText(this.Name);
}

View File

@@ -223,7 +223,7 @@ namespace CleanMachineHMI.FrmUserControl
dt.DefaultView.Sort = "报警时间 DESC";
dt = dt.DefaultView.ToTable();
kryptonDataGridView1.DataSource = dt;
kryptonDataGridView1.SetDataViewColumnText(this.Name, GlobalHelper.LanguageCode);
kryptonDataGridView1.SetDataViewColumnText(this.Name);
}
else
{

View File

@@ -244,7 +244,7 @@ namespace CleanMachineHMI.FrmUserControl
}
kryptonDataGridView1.DataSource = dt;
kryptonDataGridView1.ClearSelection();
kryptonDataGridView1.SetDataViewColumnText(this.Name, GlobalHelper.LanguageCode);
kryptonDataGridView1.SetDataViewColumnText(this.Name);
}
else
{

View File

@@ -43,7 +43,7 @@ namespace CleanMachineHMI.FrmUserControl
if (dt != null && dt.Rows.Count > 0)
{
kryptonDataGridView2.DataSource = dt;
kryptonDataGridView2.SetDataViewColumnText(this.Name + "." + kryptonDataGridView2.Name, GlobalHelper.LanguageCode);
kryptonDataGridView2.SetDataViewColumnText(this.Name + "." + kryptonDataGridView2.Name);
}
else
{
@@ -99,13 +99,13 @@ namespace CleanMachineHMI.FrmUserControl
kryptonDataGridView1.Rows[index].Cells[4].Value = item["创建人"].ToString();
kryptonDataGridView1.Rows[index].Cells[5].Value = item["创建时间"].ToString();
}
kryptonDataGridView1.SetDataViewColumnText(this.Name + "." + kryptonDataGridView1.Name, GlobalHelper.LanguageCode);
kryptonDataGridView1.SetDataViewColumnText(this.Name + "." + kryptonDataGridView1.Name);
isSlectRow = true;
kryptonDataGridView1_SelectionChanged(kryptonDataGridView1, new EventArgs());
}
else
{
kryptonDataGridView1.SetDataViewColumnText(this.Name + "." + kryptonDataGridView1.Name, GlobalHelper.LanguageCode);
kryptonDataGridView1.SetDataViewColumnText(this.Name + "." + kryptonDataGridView1.Name);
kryptonDataGridView1.Rows.Clear();
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -25,7 +25,9 @@ namespace CleanMachineHMI
if (canCreateNew)
{
Application.EnableVisualStyles();
//frmUtil.DB2Json();//语言字典从数据库转json
GlobalHelper.LoadTheme();
GlobalHelper.LoadzhCN();
Application.SetCompatibleTextRenderingDefault(false);
GlobalHelper.LoadAllFormData();
Application.Run(GlobalHelper.LoginForm);

View File

@@ -191,40 +191,37 @@ namespace CleanMachineHMI
{
var appPath = System.Windows.Forms.Application.StartupPath.Split(new string[] { @"bin\Debug" }, StringSplitOptions.RemoveEmptyEntries)[0];
var filePath = appPath + $"Lang\\{GlobalHelper.LanguageCode}.json";
using (StreamReader sr = new StreamReader(filePath))
var str = File.ReadAllText(filePath);
var lstLanguage = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ThemeLanguage>>(str);
var tmpThemeLanguage = new Dictionary<string, string>();
lstLanguage.ForEach(item =>
{
var str = sr.ReadToEnd();
var lstLanguage = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ThemeLanguage>>(str);
//var tmpThemeLanguage = new List<ThemeLanguage>();
//lstLanguage.ForEach(item =>
//{
// var part = tmpThemeLanguage.FirstOrDefault(x => x.formCode == item.formCode && x.controlCode == item.controlCode);
// if (part == null)
// {
// tmpThemeLanguage.Add(item);
// }
// else
// {
// part.options.Add(item.controlName);
// }
//});
//var str1 = Newtonsoft.Json.JsonConvert.SerializeObject(tmpThemeLanguage);
//WriteFile(appPath + "\\Lang", filePath, str1);
var tmpThemeLanguage = new Dictionary<string, string>();
lstLanguage.ForEach(item =>
if (item.options != null && item.options.Count > 0)
{
if (item.options.Count > 0)
{
tmpThemeLanguage.Add(item.formCode + "|" + item.controlCode, string.Join(",", item.options));
}
else
{
tmpThemeLanguage.Add(item.formCode + "|" + item.controlCode, item.controlName);
}
});
ThemeLanguage = tmpThemeLanguage;
tmpThemeLanguage.Add(item.formCode + "|" + item.controlCode, string.Join(",", item.options));
}
else
{
tmpThemeLanguage.Add(item.formCode + "|" + item.controlCode, item.controlName);
}
});
ThemeLanguage = tmpThemeLanguage;
}
}
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

@@ -2,6 +2,7 @@
using Krypton.Navigator;
using Krypton.Toolkit;
using LeadDataBaseUtility;
using Newtonsoft.Json;
using NX_LogUtility;
using System;
using System.Collections.Generic;
@@ -20,7 +21,8 @@ namespace CleanMachineHMI.Utils
/// </summary>
public static class frmUtil
{
public static List<ThemeLanguage> znCNLang = new List<ThemeLanguage>();
/// <summary>
/// 给一个字符串进行MD5加密
/// </summary>
@@ -118,44 +120,25 @@ namespace CleanMachineHMI.Utils
}
}
private static void WriteFile(string strDir, string filePath, string txt)
{
FileStream fs = null;
StreamWriter sw = null;
try
{
if (!Directory.Exists(strDir))//如果日志文件存放的文件夹不存在,就新建一个文件夹。
{
Directory.CreateDirectory(strDir);
}
if (File.Exists(filePath))//日志文件存放路径存在,向日志文件追加记录。
{
fs = new FileStream(filePath, FileMode.Append);
}
else//日志文件存放路径不存在,创建日志文件。
{
fs = new FileStream(filePath, FileMode.Create);
}
sw = new StreamWriter(fs);
//开始写入
sw.Write(txt);
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
}
catch (Exception)
/// <summary>
/// 递归获取子控件
/// </summary>
/// <param name="control"></param>
/// <returns></returns>
public static List<Control> GetAllControls(Control control)
{
var list = new List<Control>();
foreach (Control con in control.Controls)
{
list.Add(con);
if (con.Controls.Count > 0)
{
list.AddRange(GetAllControls(con));
}
}
finally
{
if (sw != null)
sw.Close();
if (fs != null)
fs.Close();
}
return list;
}
/// <summary>
@@ -167,24 +150,24 @@ namespace CleanMachineHMI.Utils
{
try
{
Control[] tmpC = form.Controls.Find("label2", true);
foreach (Control item in form.Controls)
foreach (Control item in GetAllControls(form))
{
var key = form.Name + "|" + item.Name;
if (!GlobalHelper.ThemeLanguage.ContainsKey(key))
{
continue;
}
AddzhCN(key, item.Text, "");
if (item is KryptonGroupBox)
{
((KryptonGroupBox)item).Values.Heading = GlobalHelper.ThemeLanguage[key];
continue;
}
else {
else
{
item.Text = GlobalHelper.ThemeLanguage[key];
}
}
}
catch (Exception ex)
@@ -199,7 +182,7 @@ namespace CleanMachineHMI.Utils
/// <param name="dataGrid"></param>
/// <param name="formName"></param>
/// <param name="languageCode"></param>
public static void SetDataViewColumnText(this DataGridView dataGrid, string formName, string languageCode)
public static void SetDataViewColumnText(this DataGridView dataGrid, string formName)
{
try
{
@@ -210,7 +193,8 @@ namespace CleanMachineHMI.Utils
{
continue;
}
item.HeaderText=GlobalHelper.ThemeLanguage[key];
AddzhCN(key, item.HeaderText, "");
item.HeaderText = GlobalHelper.ThemeLanguage[key];
}
}
catch (Exception ex)
@@ -237,6 +221,7 @@ namespace CleanMachineHMI.Utils
}
else
{
AddzhCN(key, defaultValue, "");
return GlobalHelper.ThemeLanguage[key];
}
}
@@ -247,17 +232,24 @@ namespace CleanMachineHMI.Utils
}
}
public static List<string> GetComBoboxItemArr(this Control form, string code, string controlType)
public static List<string> GetComBoboxItemArr(this Control form, string controlCode, string controlType)
{
try
{
var key = form.Name + "|" + code;
var key = form.Name + "|" + controlCode;
if (!GlobalHelper.ThemeLanguage.ContainsKey(key))
{
return new List<string>();
}
else
{
var control = (KryptonComboBox)form.Controls.Find(controlCode,true)[0];
var str = "";
foreach (var item in control.Items) {
str += $"{item},";
}
AddzhCN(key, "", string.IsNullOrEmpty(str) ? GlobalHelper.ThemeLanguage[key] : str.TrimEnd(new char[] { ',' }));
return GlobalHelper.ThemeLanguage[key].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
}
@@ -268,6 +260,85 @@ namespace CleanMachineHMI.Utils
return null;
}
}
public static void DB2Json()
{
var tmpThemeLanguage = new List<ThemeLanguage>();
var table = LeadDbHelperSQLite.Query("SELECT FORM_CODE,CONTROL_CODE,CONTROL_NAME FROM SYS_LANGUAGE_CONTROL WHERE FORM_CODE <> 'frmMain'").Tables[0];
foreach (DataRow row in table.Rows)
{
var part = tmpThemeLanguage.FirstOrDefault(x => x.formCode == row["FORM_CODE"].ToString() && x.controlCode == row["CONTROL_CODE"].ToString());
if (part == null)
{
tmpThemeLanguage.Add(new ThemeLanguage
{
formCode = row["FORM_CODE"].ToString(),
controlCode = row["CONTROL_CODE"].ToString(),
controlName = row["CONTROL_NAME"].ToString(),
});
}
else
{
if (part.options == null)
{
part.options = new List<string> { part.controlName, row["CONTROL_NAME"].ToString() };
part.controlName = null;
}
else
{
part.options.Add(row["CONTROL_NAME"].ToString());
}
}
}
var str1 = Newtonsoft.Json.JsonConvert.SerializeObject(tmpThemeLanguage);
WriteLangFile("en.json", str1);
}
/// <summary>
/// 写文本文件
/// </summary>
/// <param name="fileName"></param>
/// <param name="txt"></param>
private static void WriteLangFile(string fileName, string txt)
{
var fileDir = System.Windows.Forms.Application.StartupPath.Split(new string[] { @"bin\Debug" }, StringSplitOptions.RemoveEmptyEntries)[0] + "Lang\\";
try
{
if (!Directory.Exists(fileDir))//如果文件夹不存在,就新建一个文件夹。
{
Directory.CreateDirectory(fileDir);
}
File.WriteAllText(fileDir + fileName, txt);
}
catch (Exception)
{
}
}
private static void AddzhCN(string key, string name, string options)
{
if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(options)) {
Console.WriteLine(key+"空");
return;
}
var codes = key.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
if (znCNLang.Any(x => x.formCode == codes[0] && x.controlCode == codes[1]))
{
return;
}
znCNLang.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);
}
}
public class ThemeLanguage
@@ -283,8 +354,10 @@ namespace CleanMachineHMI.Utils
/// <summary>
/// 控件名称
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string controlName { get; set; }
public List<string> options { get; set; } = new List<string>();
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public List<string> options { get; set; }
}
}

View File

@@ -47,7 +47,7 @@ namespace CleanMachineHMI.frmChild
kryptonDataGridView1.Rows[index].Cells[9].Value = item["INPUT_TIME"].ToString();
}
kryptonDataGridView1.SetDataViewColumnText(this.Name, GlobalHelper.LanguageCode);
kryptonDataGridView1.SetDataViewColumnText(this.Name);
}
}
catch (Exception ex)