2008-10-21 90 views
4

我要寻找一个解决方案或建议,我有一个问题。我有一堆ASPX页面将被本地化,并且有一些需要6种语言支持的文本。转换CSV文件或Excel电子表格文件RESX

的人做翻译将无法获得Visual Studio和最简单的可能的工具是Excel中。如果我们使用Excel甚至导出到CSV,我们需要能够导入到.resx文件。那么,对此最好的方法是什么?

我知道这个问题的,Convert a Visual Studio resource file to a text file?已经和使用RESX编辑器,但一个简单的解决方案将是首选。

回答

2

我不知道你的答案如何全面的寻找,但如果你真的只是使用[字符串,字符串]对你的定位和你只是寻找一个快速的方式来加载资源(.resx)文件与翻译结果进行比较,那么以下内容将作为一种相当快速,低技术含量的解决方案。

要记住的一点是,.resx文件只是XML文档,所以它应该可以手动将数据从外部的代码加载到资源。下面的例子在VS2005为我工作和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); 
     } 
    } 
} 

显然,上述方法不会产生隐藏代码为您的资源,但是打开Visual Studio中的资源文件,并切换无障碍修改为资源将(重新)为您生成静态属性。

如果您正在寻找一个完全基于XML的解决方案(与CSV或Excel互操作),您还可以指示您的翻译人员将其翻译的内容存储在Excel中,保存为XML,然后使用XPath检索您的本地化信息。唯一需要注意的是文件大小往往变得非常臃肿。

祝你好运。

+0

这个工作对resw了。 – b15 2016-06-05 13:51:18

1

我遇到了类似的问题,并意识到从excel文件创建.resx文件的最简单方法是使用excel的连接函数来生成“<”数据“>”..“<”/ data“>”节点为.resx文件,然后手动将生成的行复制到任何文本编辑器中的.resx文件。因此可以说,你在excel文档的A列中有“Name”,在Excel文档的B列中有“value”。在列C中使用以下公式

=CONCATENATE("<data name=","""",A14,""" xml:space=""preserve"">","<value>", B14, "</value>", "</data>") 

您将获得资源的数据节点。然后,您可以将此公式复制到所有行,然后将.C列中的内容复制到.resx文件中。

0

如果它在csv中,这里有一个快速的Ruby脚本来生成数据元素。

require 'csv' 
require 'builder' 

file = ARGV[0] 

builder = Builder::XmlMarkup.new(:indent => 2) 

CSV.foreach(file) do |row| 
    builder.data(:name => row[0], "xml:space" => :preserve) {|d| d.value(row[1]) } 
end 

File.open(file + ".xml", 'w') { |f| f.write(builder.target!) } 
相关问题