转换CSV文件或Excel US preadsheet到RESX文件 [英] Convert CSV file or Excel spreadsheet to RESX File

查看:152
本文介绍了转换CSV文件或Excel US preadsheet到RESX文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一个解决方案或建议,我有一个问题。我有一堆将本地化,有文字的一堆需要6种语言要支持ASPX页面。

I am looking for a solution or recommendation to a problem I am having. I have a bunch of ASPX pages that will be localized and have a bunch of text that needs to be supported in 6 languages.

的人做翻译将不能访问到Visual Studio,可能最简单的工具是Excel。如果我们使用Excel,甚至导出为CSV,我们需要能够导入移动到.resx文件。那么,什么是最好的方法呢?

The people doing the translation will not have access to Visual Studio and the likely easiest tool is Excel. If we use Excel or even export to CSV, we need to be able to import to move to .resx files. So, what is the best method for this?

我意识到这个问题,<一个href=\"http://stackoverflow.com/questions/198772/convert-a-visual-studio-resource-file-to-a-text-file\">Convert一个Visual Studio资源文件到一个文本文件?已和使用RESX编辑器,而是一个更容易的解决办法是preferred。

I am aware of this question, Convert a Visual Studio resource file to a text file? already and the use of Resx Editor but an easier solution would be preferred.

推荐答案

我不知道怎么COM prehensive你要找的,但如果你真的只是用[字符串,字符串]对的答案为您的本地化,而你只是在寻找一个快速的方式来加载资源(的.resx)与你的翻译结果文件,那么下面的工作作为一个相当快,科技含量低的解决方案。

I'm not sure how comprehensive an answer you're looking for, but if you're really just using [string, string] pairs for your localization, and you're just looking for a quick way to load resource (.resx) files with the results of your translations, then the following will work as a fairly quick, low-tech solution.

要记住的是,.resx文件只是XML文档,所以它应该是可以手动将数据从外部件code加载到该资源。下面的例子在VS2005的工作对我和VS2008:

The thing to remember is that .resx files are just XML documents, so it should be possible to manually load your data into the resource from an external piece of code. The following example worked for me in VS2005 and VS2008:

namespace SampleResourceImport
{
    class Program
    {
        static void Main(string[] args)
        {

            XmlDocument doc = new XmlDocument();
            string filePath = @"[file path to your resx file]";
            doc.Load(filePath);
            XmlElement root = doc.DocumentElement;

            XmlElement datum = null;
            XmlElement value = null;
            XmlAttribute datumName = null;
            XmlAttribute datumSpace = doc.CreateAttribute("xml:space");
            datumSpace.Value = "preserve";

            // The following mocks the actual retrieval of your localized text
            // from a CSV or ?? document...
            // CSV parsers are common enough that it shouldn't be too difficult
            // to find one if that's the direction you go.
            Dictionary<string, string> d = new Dictionary<string, string>();
            d.Add("Label1", "First Name");
            d.Add("Label2", "Last Name");
            d.Add("Label3", "Date of Birth");

            foreach (KeyValuePair<string, string> pair in d)
            {
                datum = doc.CreateElement("data");
                datumName = doc.CreateAttribute("name");
                datumName.Value = pair.Key;
                value = doc.CreateElement("value");
                value.InnerText = pair.Value;

                datum.Attributes.Append(datumName);
                datum.Attributes.Append(datumSpace);
                datum.AppendChild(value);
                root.AppendChild(datum);
            }

            doc.Save(filePath);
        }
    }
}

显然,preceding方法不会产生code-背后的资源,但是打开Visual Studio中的资源文件,并切换为资源将(重新)无障碍修改生成的静态属性给你的。

Obviously, the preceding method won't generate the code-behind for your resource, however opening the resource file in Visual Studio and toggling the accessibility modifier for the resource will (re)generate the static properties for you.

如果你正在寻找一个完全基于XML的解决方案(与CSV或Excel互操作),你也可以指导您的翻译存储在Excel他们翻译的内容,保存为XML,然后使用XPath检索您的本地化信息。作为文件大小唯一的条件往往成为pretty臃肿。

If you're looking for a completely XML-based solution (vs. CSV or Excel interop), you could also instruct your translators to store their translated content in Excel, saved as XML, then use XPath to retrieve your localization info. The only caveat being the file sizes tend to become pretty bloated.

好运。

这篇关于转换CSV文件或Excel US preadsheet到RESX文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆