Commit 173c9a22 刘韬

完成SMF服务端多语言

1 个父辈 0181f10e
...@@ -30,9 +30,7 @@ ...@@ -30,9 +30,7 @@
{ {
this.btnCancel = new System.Windows.Forms.Button(); this.btnCancel = new System.Windows.Forms.Button();
this.btnOk = new System.Windows.Forms.Button(); this.btnOk = new System.Windows.Forms.Button();
this.rbtnEnglish = new System.Windows.Forms.RadioButton(); this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.rbtnChina = new System.Windows.Forms.RadioButton();
this.rbtnJapanese = new System.Windows.Forms.RadioButton();
this.SuspendLayout(); this.SuspendLayout();
// //
// btnCancel // btnCancel
...@@ -40,10 +38,11 @@ ...@@ -40,10 +38,11 @@
this.btnCancel.Anchor = System.Windows.Forms.AnchorStyles.Top; this.btnCancel.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCancel.Font = new System.Drawing.Font("微软雅黑", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnCancel.Font = new System.Drawing.Font("微软雅黑", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnCancel.Location = new System.Drawing.Point(238, 187); this.btnCancel.Location = new System.Drawing.Point(311, 88);
this.btnCancel.Name = "btnCancel"; this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(122, 45); this.btnCancel.Size = new System.Drawing.Size(122, 45);
this.btnCancel.TabIndex = 283; this.btnCancel.TabIndex = 283;
this.btnCancel.Tag = "取消";
this.btnCancel.Text = "取消"; this.btnCancel.Text = "取消";
this.btnCancel.UseVisualStyleBackColor = false; this.btnCancel.UseVisualStyleBackColor = false;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
...@@ -53,67 +52,37 @@ ...@@ -53,67 +52,37 @@
this.btnOk.Anchor = System.Windows.Forms.AnchorStyles.Top; this.btnOk.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.btnOk.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnOk.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnOk.Font = new System.Drawing.Font("微软雅黑", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnOk.Font = new System.Drawing.Font("微软雅黑", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnOk.Location = new System.Drawing.Point(77, 187); this.btnOk.Location = new System.Drawing.Point(311, 21);
this.btnOk.Name = "btnOk"; this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(122, 45); this.btnOk.Size = new System.Drawing.Size(122, 45);
this.btnOk.TabIndex = 282; this.btnOk.TabIndex = 282;
this.btnOk.Tag = "确定";
this.btnOk.Text = "确定"; this.btnOk.Text = "确定";
this.btnOk.UseVisualStyleBackColor = false; this.btnOk.UseVisualStyleBackColor = false;
this.btnOk.Click += new System.EventHandler(this.btnOk_Click); this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
// //
// rbtnEnglish // flowLayoutPanel1
// //
this.rbtnEnglish.AutoSize = true; this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.rbtnEnglish.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.flowLayoutPanel1.Location = new System.Drawing.Point(34, 21);
this.rbtnEnglish.Location = new System.Drawing.Point(198, 84); this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.rbtnEnglish.Name = "rbtnEnglish"; this.flowLayoutPanel1.Size = new System.Drawing.Size(219, 167);
this.rbtnEnglish.Size = new System.Drawing.Size(60, 25); this.flowLayoutPanel1.TabIndex = 284;
this.rbtnEnglish.TabIndex = 281;
this.rbtnEnglish.TabStop = true;
this.rbtnEnglish.Text = "英语";
this.rbtnEnglish.UseVisualStyleBackColor = true;
//
// rbtnChina
//
this.rbtnChina.AutoSize = true;
this.rbtnChina.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.rbtnChina.Location = new System.Drawing.Point(198, 39);
this.rbtnChina.Name = "rbtnChina";
this.rbtnChina.Size = new System.Drawing.Size(60, 25);
this.rbtnChina.TabIndex = 280;
this.rbtnChina.TabStop = true;
this.rbtnChina.Text = "中文";
this.rbtnChina.UseVisualStyleBackColor = true;
//
// rbtnJapanese
//
this.rbtnJapanese.AutoSize = true;
this.rbtnJapanese.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.rbtnJapanese.Location = new System.Drawing.Point(198, 130);
this.rbtnJapanese.Name = "rbtnJapanese";
this.rbtnJapanese.Size = new System.Drawing.Size(76, 25);
this.rbtnJapanese.TabIndex = 281;
this.rbtnJapanese.TabStop = true;
this.rbtnJapanese.Text = "日本語";
this.rbtnJapanese.UseVisualStyleBackColor = true;
// //
// FrmLanguare // FrmLanguare
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(456, 274); this.ClientSize = new System.Drawing.Size(456, 221);
this.Controls.Add(this.flowLayoutPanel1);
this.Controls.Add(this.btnCancel); this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOk); this.Controls.Add(this.btnOk);
this.Controls.Add(this.rbtnJapanese);
this.Controls.Add(this.rbtnEnglish);
this.Controls.Add(this.rbtnChina);
this.MaximizeBox = false; this.MaximizeBox = false;
this.MinimizeBox = false; this.MinimizeBox = false;
this.Name = "FrmLanguare"; this.Name = "FrmLanguare";
this.Text = "语言设置"; this.Text = "语言设置";
this.Load += new System.EventHandler(this.FrmLanguare_Load); this.Load += new System.EventHandler(this.FrmLanguare_Load);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
...@@ -121,8 +90,6 @@ ...@@ -121,8 +90,6 @@
private System.Windows.Forms.Button btnCancel; private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnOk; private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.RadioButton rbtnEnglish; private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.RadioButton rbtnChina;
private System.Windows.Forms.RadioButton rbtnJapanese;
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -23,20 +23,28 @@ namespace OnlineStore.ACSingleStore ...@@ -23,20 +23,28 @@ namespace OnlineStore.ACSingleStore
{ {
LanguageProcess(); LanguageProcess();
LanguagePro(); LanguagePro();
if (ResourceCulture.CurrLanguage.Equals(ResourceCulture.English)) loadLanglist(ResourceCulture.CurrLanguage);
{ }
rbtnEnglish.Checked = true;
} void loadLanglist(string currnetlang) {
else if(ResourceCulture.CurrLanguage.Equals(ResourceCulture.Japanese)) var LangList = ResourceCulture.GetLangList();
{ flowLayoutPanel1.Controls.Clear();
rbtnJapanese.Checked = true; foreach (var l in LangList.ToArray()) {
}
else RadioButton radioButton = new RadioButton()
{ {
rbtnChina.Checked = true; AutoSize = true,
Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))),
Tag = l.Key,
Text = l.Value,
UseVisualStyleBackColor = true,
Checked= (currnetlang.ToLower() == l.Key.ToLower())
};
flowLayoutPanel1.Controls.Add(radioButton);
} }
} }
private void btnCancel_Click(object sender, EventArgs e) private void btnCancel_Click(object sender, EventArgs e)
{ {
this.Close(); this.Close();
...@@ -44,6 +52,8 @@ namespace OnlineStore.ACSingleStore ...@@ -44,6 +52,8 @@ namespace OnlineStore.ACSingleStore
private void btnOk_Click(object sender, EventArgs e) private void btnOk_Click(object sender, EventArgs e)
{ {
string str = flowLayoutPanel1.Controls.Cast<RadioButton>().Where((c) => { return c.Checked; }).First().Tag.ToString();
/*
string str = ConfigAppSettings.GetValue(Setting_Init.Default_Language); string str = ConfigAppSettings.GetValue(Setting_Init.Default_Language);
if (rbtnEnglish.Checked) if (rbtnEnglish.Checked)
{ {
...@@ -55,7 +65,7 @@ namespace OnlineStore.ACSingleStore ...@@ -55,7 +65,7 @@ namespace OnlineStore.ACSingleStore
}else }else
{ {
str = ResourceCulture.China; str = ResourceCulture.China;
} }*/
ResourceCulture.SetCurrentCulture(str); ResourceCulture.SetCurrentCulture(str);
ConfigAppSettings.SaveValue(Setting_Init.Default_Language, str); ConfigAppSettings.SaveValue(Setting_Init.Default_Language, str);
this.Close(); this.Close();
......
...@@ -9,7 +9,7 @@ using System.Runtime.InteropServices; ...@@ -9,7 +9,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SO951-HC-ACSingleStore 3f972f3f1ae8ddd17dbf3847e26af0a0b4e1f8b2")] [assembly: AssemblyProduct("SO951-HC-ACSingleStore 0181f10ea5b20d7bff31acc620be9cb216488e56")]
[assembly: AssemblyCopyright("Copyright ? 2017")] [assembly: AssemblyCopyright("Copyright ? 2017")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
......
...@@ -60,9 +60,7 @@ namespace OnlineStore ...@@ -60,9 +60,7 @@ namespace OnlineStore
{ {
Task.Delay(10 * 1000).Wait(); Task.Delay(10 * 1000).Wait();
var lngjson = JsonHelper.SerializeObject(ResourceMap); var lngjson = JsonHelper.SerializeObject(ResourceMap);
var insertindex = lngjson.IndexOf("{"); if (SMF.UploadLangJsonData(lngjson, out SmfResult smfResult))
lngjson = lngjson.Insert(insertindex + 1, "\"type\": \"siso\",");
if (SMF.UploadJsonData("/api/translation/resource", lngjson, out SmfResult smfResult))
{ {
LogUtil.info("语言资源上传成功"); LogUtil.info("语言资源上传成功");
} }
...@@ -91,9 +89,10 @@ namespace OnlineStore ...@@ -91,9 +89,10 @@ namespace OnlineStore
}); });
} }
} }
private static char spilt = '\t';
private static char spilt = '\t';
private static string rPath = Application.StartupPath + @"\resources\"; private static string rPath = Application.StartupPath + @"\resources\";
private static void LoadData(bool loadserverdir=false) private static void LoadData(bool loadserverdir = false)
{ {
string loadpath = rPath; string loadpath = rPath;
if (loadserverdir) if (loadserverdir)
...@@ -103,7 +102,8 @@ namespace OnlineStore ...@@ -103,7 +102,8 @@ namespace OnlineStore
{ {
Dictionary<string, string> lngMap; Dictionary<string, string> lngMap;
var lngname = Path.GetFileNameWithoutExtension(lngresfile); var lngname = Path.GetFileNameWithoutExtension(lngresfile);
if (!ResourceMap.ContainsKey(lngname)) { if (!ResourceMap.ContainsKey(lngname))
{
ResourceMap.Add(lngname, new Dictionary<string, string>()); ResourceMap.Add(lngname, new Dictionary<string, string>());
} }
lngMap = ResourceMap[lngname]; lngMap = ResourceMap[lngname];
...@@ -118,20 +118,16 @@ namespace OnlineStore ...@@ -118,20 +118,16 @@ namespace OnlineStore
{ {
string key = array[0].Trim(); string key = array[0].Trim();
string value = array[2]; string value = array[2];
if (lngMap.ContainsKey(key)) if (lngMap.ContainsKey(key))
lngMap[key] = value; lngMap[key] = value;
else else
lngMap.Add(key, value); lngMap.Add(key, value);
}
}
} }
} }
} }
public static Dictionary<string, string> LangName = new Dictionary<string, string>() { static Dictionary<string, string> LangName = new Dictionary<string, string>() {
{"zh-CN","简体中文" }, {"zh-CN","简体中文" },
{"zh-TW","繁體中文" }, {"zh-TW","繁體中文" },
{ "en-US", "English" }, { "en-US", "English" },
...@@ -140,6 +136,21 @@ namespace OnlineStore ...@@ -140,6 +136,21 @@ namespace OnlineStore
{ "de-DE", "Deutsche" }, { "de-DE", "Deutsche" },
}; };
public static Dictionary<string, string> GetLangList()
{
Dictionary<string, string> LangList = new Dictionary<string, string>();
foreach (var v in LangName)
{
if (ResourceMap.ContainsKey(v.Key))
{
if (!LangList.ContainsKey(v.Key))
LangList.Add(v.Key, v.Value);
}
}
return LangList;
}
public static string GetChinaString(string id, params object[] param) public static string GetChinaString(string id, params object[] param)
{ {
string strCurLanguage = gets(China, id); string strCurLanguage = gets(China, id);
......
...@@ -135,6 +135,9 @@ namespace OnlineStore.ACSingleStore.useControl ...@@ -135,6 +135,9 @@ namespace OnlineStore.ACSingleStore.useControl
if (pa[2][1].Equals('A') || pa[2][1].Equals('B')) if (pa[2][1].Equals('A') || pa[2][1].Equals('B'))
{ {
pa2 = (pa[2][1].Equals('A') ? "1" : "2") + pa[2][0]; pa2 = (pa[2][1].Equals('A') ? "1" : "2") + pa[2][0];
}else if (pa[2][1].Equals('1') || pa[2][1].Equals('2'))
{
pa2 = (pa[2][1].Equals('1') ? "1" : "2") + pa[2][0];
} }
} }
...@@ -143,6 +146,9 @@ namespace OnlineStore.ACSingleStore.useControl ...@@ -143,6 +146,9 @@ namespace OnlineStore.ACSingleStore.useControl
if ((pb[2][1].Equals('A') || pb[2][1].Equals('B'))) if ((pb[2][1].Equals('A') || pb[2][1].Equals('B')))
{ {
pb2 = (pb[2][1].Equals('A') ? "1" : "2") + pb[2][0]; pb2 = (pb[2][1].Equals('A') ? "1" : "2") + pb[2][0];
}else if ((pb[2][1].Equals('1') || pb[2][1].Equals('2')))
{
pb2 = (pb[2][1].Equals('1') ? "1" : "2") + pb[2][0];
} }
} }
......
...@@ -10,37 +10,47 @@ namespace OnlineStore.Common ...@@ -10,37 +10,47 @@ namespace OnlineStore.Common
{ {
public class SMF public class SMF
{ {
static string _server= ConfigAppSettings.GetValue(Setting_Init.http_server); public static string DeviceType = "SISO";
static string _server = ConfigAppSettings.GetValue(Setting_Init.http_server);
static string server static string server
{ {
get get
{ {
_server = "http://192.168.1.243/smf-core"; _server = "http://192.168.1.243/smf-core";
if (_server.EndsWith("/")) { if (_server.EndsWith("/"))
return _server.Remove(_server.Length-1,1); {
return _server.Remove(_server.Length - 1, 1);
} }
else else
return _server; return _server;
} }
} }
public static bool UploadJsonData(string api, string json,out SmfResult smfResult) public static bool UploadLangJsonData(string json, out SmfResult smfResult)
{ {
var insertindex = json.IndexOf("{");
json = json.Insert(insertindex + 1, "\"type\": \"" + DeviceType + "\",");
return UploadJsonData("/api/translation/resource", json, out smfResult);
}
public static bool UploadJsonData(string api, string json, out SmfResult smfResult)
{
smfResult = new SmfResult(); smfResult = new SmfResult();
try try
{ {
MyWebClient wc = new MyWebClient(10 * 1000); MyWebClient wc = new MyWebClient(10 * 1000);
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8"); wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
var resp = wc.UploadData(server+api, Encoding.UTF8.GetBytes(json)); var resp = wc.UploadData(server + api, Encoding.UTF8.GetBytes(json));
smfResult = JsonHelper.DeserializeJsonToObject<SmfResult>(Encoding.UTF8.GetString(resp)); smfResult = JsonHelper.DeserializeJsonToObject<SmfResult>(Encoding.UTF8.GetString(resp));
} }
catch (Exception e) { catch (Exception e)
LogUtil.info($"UploadJsonData:{api}"+e.ToString()); {
LogUtil.info($"UploadJsonData:{api}" + e.ToString());
} }
return smfResult.okResult; return smfResult.okResult;
} }
public static List<SmfLangData> DownloadLngData() public static List<SmfLangData> DownloadLngData()
{ {
string api = "/api/translation/resource?type=siso"; string api = "/api/translation/resource?type=" + DeviceType;
try try
{ {
MyWebClient wc = new MyWebClient(10 * 1000); MyWebClient wc = new MyWebClient(10 * 1000);
...@@ -59,15 +69,17 @@ namespace OnlineStore.Common ...@@ -59,15 +69,17 @@ namespace OnlineStore.Common
} }
//{"code":0,"data":"ok","msg":"ok","msgKey":"smfcore.ok","okResult":true} //{"code":0,"data":"ok","msg":"ok","msgKey":"smfcore.ok","okResult":true}
public class SmfResult { public class SmfResult
{
public int code; public int code;
public string data; public string data;
public string msg; public string msg;
public string msgKey; public string msgKey;
public bool okResult; public bool okResult;
} }
public class SmfLangData { public class SmfLangData
{
public string lanCode; public string lanCode;
public Dictionary<string, string> resourceMap; public Dictionary<string, string> resourceMap;
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!