Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a Visual Studio resource file to a text file?

I know there are tools to get text files to resource files for Visual Studio. But I want to get the text from my resource files to a text file so they can be translated. Or is there a better way to do this?

like image 657
nportelli Avatar asked Oct 13 '08 19:10

nportelli


People also ask

What is a resource file in Visual Studio?

Applies to: Visual Studio Visual Studio for Mac Visual Studio Code. Resource files are files that are part of an application but are not compiled, for example icon files or audio files. Since these files are not part of the compilation process, you can change them without having to recompile your binaries.

What is a .resx file?

A . resx file contains a standard set of header information that describes the format of the resource entries, and specifies the versioning information for the XML code that parses the data. These files contain all the strings, labels, captions, and titles for all text in the three IBM Cognos Office components.


2 Answers

You could use Resx Editor, a small translation-oriented file editor.

  • Target audience: translators.
  • Supported file format: Microsoft RESX 2.0

Here is a link to Joannès Vermoel's (the author of the free tool) weblog entry about it.

like image 151
splattne Avatar answered Sep 18 '22 02:09

splattne


In the end I just used a quick hack:

public class Export
{
    public string Run()
    {
        var resources = new StringBuilder();

        var assembly = Assembly.GetExecutingAssembly();
        var types = from t in assembly.GetTypes()
                    where t != typeof(Export)
                    select t;
        foreach (Type t in types)
        {
            resources.AppendLine(t.Name);
            resources.AppendLine("Key, Value");
            var props = from p in t.GetProperties()
                        where !p.CanWrite && p.Name != "ResourceManager"
                        select p;
            foreach (PropertyInfo p in props)
            {
                resources.AppendFormat("\"{0}\",\"{1}\"\n", p.Name, p.GetValue(null));
            }

            resources.AppendLine();
        }
        return resources.ToString();
    }
}

Add this code to the project which contains your.resx files (mine are in a separate "Languages" project) then use the following code to save the result into a .csv so that it can be loaded with a spreadsheet editor.

var hack = new Languages.Export();
var resourcesSummary = hack.Run();
var cultureName = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
using (TextWriter file = File.CreateText(@"C:\resources." + cultureName + ".csv"))
{
    file.Write(resourcesSummary);
}

This does not allow you to import files from the .csv back to your .resx files so that they can be compiled. It would be nice to have a utility that would do that.

like image 22
fireydude Avatar answered Sep 20 '22 02:09

fireydude