Asp.net 资源文件翻译助手

     最近项目需要做一个双语的网站,需要将对资源文件进行翻译,在vs里翻译感觉不够方便,参考SimpleResxEditor,自己写了个资源文件编辑助手,自己DIY的才是最好用的,呵呵,软件界面:

Asp.net 资源文件翻译助手
使用方法:

Asp.net 资源文件翻译助手
实现思路:

1.资源文件对应的实体

namespace ResxEditor
{
    public class ResourceItem
    {
        public ResourceItem()
        { }

        public ResourceItem(int id, string key, string value, string comment)
        {
            this.ID = id;
            this.Key = key;
            this.Value = value;
            this.Comment = comment;
        }
        public int ID { get; set; }
        public string Key { get; set; }
        public string Value { get; set; }
        public string Comment { get; set; }
    }
}

2.读取资源文件的方法

        /// <summary>
        /// 读取资源文件
        /// </summary>
        /// <returns></returns>
        private List<ResourceItem> GetDicList()
        {
            List<ResourceItem> itemList = new List<ResourceItem>();
            ResXResourceReader rsxResource = new ResXResourceReader(resourceFilePath);
            rsxResource.UseResXDataNodes = true;
            AssemblyName[] referencedAssemblies = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
            IDictionaryEnumerator enumerator = rsxResource.GetEnumerator();
            int i = 0;
            while (enumerator.MoveNext())
            {
                DictionaryEntry current = (DictionaryEntry)enumerator.Current;
                ResXDataNode node = (ResXDataNode)current.Value;
                string strKey = node.Name;    //资源项名  
                string strValue = node.GetValue(referencedAssemblies).ToString();//值  
                string strComment = node.Comment;   //注释  
                ResourceItem item = new ResourceItem(i, strKey, strValue, strComment);
                itemList.Add(item);
                i++;
            }
            return itemList;
        }
3.写入资源文件的方法

        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            LblResult.Text = "";
            //写入键值对
            List<ResourceItem> itemList = GetDicList();            
            ResXResourceWriter rswt = new ResXResourceWriter(resourceFilePath);
            foreach (ResourceItem item in itemList)
            {
                if (string.Compare(item.Key, TxtKey.Text, true) == 0)
                {
                    ResXDataNode node = new ResXDataNode(item.Key, TxtTranslate.Text.Trim());//将翻译写入Value
                    node.Comment = TxtValue.Text;//将value写入注释
                    rswt.AddResource(node);
                }
                else
                {
                    ResXDataNode node = new ResXDataNode(item.Key, item.Value);
                    node.Comment = item.Comment;
                    rswt.AddResource(node);
                }
            }
            rswt.Close();
            rswt.Dispose();
            LblResult.Text = "更新成功!";
            LblResult.ForeColor = Color.Green;
        }

软件下载:http://download.csdn.net/detail/a497785609/4040724

源码下载:http://download.csdn.net/detail/a497785609/4040709




上一篇:探讨基于阿里云容器技术架构(二)


下一篇:return语句在try-catch-finally中的执行顺序