Convert a CSV file or Excel spreadsheet to a .resx file

I am looking for a solution or recommendation on the problem I am experiencing. I have a bunch of ASPX pages that will be localized and contain a bunch of text that should be supported in 6 languages.

Translators will not have access to Visual Studio, and Excel is the easiest tool. If we use Excel or even export to CSV, we must be able to import to go to .resx files. So what is the best way to do this?

I know about this question, Now convert the Visual Studio resource file to a text file and use the Resx editor, but a simpler solution would be preferable.

+4
source share
3 answers

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

Keep in mind that .resx files are only XML documents, so you can manually load your data into a resource from the outside of the 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 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);
        }
    }
}

Obviously, the previous method will not generate code for your resource, however opening the resource file in Visual Studio and switching the availability modifier for the resource (re) generate static properties for you.

XML ( CSV Excel interop), Excel, XML, XPath , , , , .

.

+2

, .resx excel - concatenate excel "<" data " > ".. "<" /data " > " node .resx, .resx . , "" A excel "value" B excel. C

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

node . C .resx.

+1

csv Ruby script .

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!) }
0

All Articles