zoukankan      html  css  js  c++  java
  • .NET元数据XML中文翻译

    功能:主要用来翻译.NET中Dll对应XML解析文档成中文。

     

    源码:

        /// <summary>
        /// 加载xml
        /// </summary>
        /// <param name="xmlPath"></param>
        private void readyXml(object xmlPath)
        {
          XmlDocument xmlDoc = new XmlDocument();
          xmlDoc.Load((string)xmlPath);
          this.Invoke(new MethodInvoker(delegate() { xmltxt.Text = XmlToString(xmlDoc); }));
    
          int num = 0;
          XmlNodeList memberList = xmlDoc.SelectSingleNode("doc/members").ChildNodes;
          for (int i = 0; i < memberList.Count; i++)
          {
            XmlNodeList itemList = memberList[i].ChildNodes;
            for (int t = 0; t < itemList.Count; t++)
            {
              if (itemList[t].Name == "summary" || itemList[t].Name == "param" || itemList[t].Name == "returns" || itemList[t].Name == "value")
              {
                if (!itemList[t].InnerText.StartsWith("【已翻译】"))
                {
                  string itemStr = "";
                  Dictionary<string, string> itemChildDesc = new Dictionary<string, string>();
    
                  getXmlItemText(itemList[t].ChildNodes, ref itemStr, ref itemChildDesc);
    
                  string resultstr = translate(itemStr.Trim());
                  foreach (KeyValuePair<string, string> item in itemChildDesc)
                  {
                    resultstr = resultstr.Replace(item.Key, item.Value);
                  }
                  if (!String.IsNullOrEmpty(resultstr))
                    itemList[t].InnerText = "【已翻译】
    " + "" + resultstr + "" + "
    " + itemList[t].InnerText.Trim().Replace("
    ", "");
                  num++;
                }
              }
            }
    
            this.Invoke(new MethodInvoker(delegate() { this.prolab.Text = (i + 1).ToString() + "/" + memberList.Count.ToString(); }));
    
            if (num % 20 == 0)
            {
              xmlDoc.Save((string)xmlPath);
              this.Invoke(new MethodInvoker(delegate() { xmltxt.Text = XmlToString(xmlDoc); }));
            }
          }
          xmlDoc.Save((string)xmlPath);
          this.Invoke(new MethodInvoker(delegate() { filebtn.Enabled = true; xmltxt.Text = XmlToString(xmlDoc); }));
          if (thread != null)
            thread.Abort();
        }
    
        private void getXmlItemText(XmlNodeList itemChildNode, ref string text, ref  Dictionary<string, string> desc)
        {
          for (int j = 0; j < itemChildNode.Count; j++)
          {
            if (itemChildNode[j].NodeType == XmlNodeType.Text)
            {
              text += itemChildNode[j].InnerText;
            }
            else if (itemChildNode[j].NodeType == XmlNodeType.Element && itemChildNode[j].Name == "see")
            {
              string vaK = "[" + "apple" + j + "]";
              string vaV = itemChildNode[j].Attributes["cref"].Value;
              vaV = (vaV.StartsWith("T:") || vaV.StartsWith("E:")) ? vaV.Remove(0, 2) : vaV;
              desc.Add(vaK, vaV);
              text += vaK;
            }
            else if (itemChildNode[j].NodeType == XmlNodeType.Element && itemChildNode[j].Name == "c")
            {
              string vaK = "[" + "banana" + j + "]";
              string vaV = itemChildNode[j].InnerText;
              desc.Add(vaK, vaV);
              text += vaK;
            }
            else if (itemChildNode[j].NodeType == XmlNodeType.Element && itemChildNode[j].Name == "para")
            {
              if (!itemChildNode[j].InnerText.StartsWith("【已翻译】"))
              {
                string itemStr = "";
                Dictionary<string, string> itemChildDesc = new Dictionary<string, string>();
    
                getXmlItemText(itemChildNode[j].ChildNodes, ref itemStr, ref itemChildDesc);
    
                string resultstr = translate(itemStr.Trim());
                foreach (KeyValuePair<string, string> item in itemChildDesc)
                {
                  resultstr = resultstr.Replace(item.Key, item.Value);
                }
                itemChildNode[j].InnerText = "【已翻译】
    " + "" + resultstr + "" + "
    " + itemChildNode[j].InnerText.Trim().Replace("
    ", "");
              }
            }
          }
        }

    源码下载地址:XML翻译.zip

  • 相关阅读:
    Oracle+PL+SQL从入门到精通.丁士锋.清华大学出版社.2012
    《 Oracle查询优化改写 技巧与案例 》电子工业出版社
    HTML5从入门到精通(明日科技) 中文pdf扫描版
    《JavaWeb从入门到精通》(明日科技,清华大学出版社)
    JavaScript从入门到精通(附光盘1张):作者:明日科技出版社:清华大学出版社出版时间:2012年09月
    ORACLE_修改实例的内存大小
    JAVA图书管理系统汇总共27个
    IntelliJ Idea 2017 免费激活方法
    spring springMvc spring-boot spring-cloud分别是什么
    nodejs环境 + 入门 + 博客搭建
  • 原文地址:https://www.cnblogs.com/tlmbem/p/10827135.html
Copyright © 2011-2022 走看看