using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml; namespace LanguageExtractTool { public partial class F_AddNewLanguage : Form { public F_AddNewLanguage() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (ofd.ShowDialog() == DialogResult.OK) { txt_src.Text = ofd.FileName; } } private void btn_addnewlang_Click(object sender, EventArgs e) { string newlang = txt_langcode.Text; if (string.IsNullOrWhiteSpace(newlang)) { MessageBox.Show("请选择语言代号"); return; } if (string.IsNullOrWhiteSpace(txt_src.Text)) { MessageBox.Show("请选择源文件"); return; } XmlDocument doc = new XmlDocument(); doc.Load(txt_src.Text); foreach (XmlNode node in doc.DocumentElement.ChildNodes) { if (string.Equals(node.Name, "Category", StringComparison.OrdinalIgnoreCase)) { foreach (XmlNode pcode in node.ChildNodes) { MergeLanuageItem li = new MergeLanuageItem(); li.PageID = new NodeValueItem() { Name = pcode.Name, Text = pcode.InnerText }; foreach (XmlNode lancode in pcode.ChildNodes) { if (string.IsNullOrWhiteSpace(lancode.InnerText)) { continue; } string lgid = lancode.Name; string lgvalue = lancode.InnerText; if (string.Compare(lgid, "en", true) == 0) { XmlElement pt_el = doc.CreateElement(newlang); pt_el.InnerText = lgvalue; pcode.AppendChild(pt_el); break; } } } } } doc.Save(txt_src.Text); MessageBox.Show("添加完成。"); } } }