8

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?

Kris Erickson
  • 33,454
  • 26
  • 120
  • 175
nportelli
  • 3,934
  • 7
  • 37
  • 52

7 Answers7

3

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.

fireydude
  • 1,181
  • 10
  • 23
3

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.

splattne
  • 102,760
  • 52
  • 202
  • 249
  • @takrl thanks, the project was moved to this link apparently http://resx.sourceforge.net/ (I updated the answer) – splattne Apr 17 '13 at 09:11
2

You can use Simple Resx Editor, it has some interesting features that will help you into the translation process.

Tute
  • 6,943
  • 12
  • 51
  • 61
1

Even though it is counter intuitive, it's a better idea to translate the exe rather than the resource file. Read why here:

http://www.apptranslator.com/misconceptions.html

Serge Wautier
  • 21,494
  • 13
  • 69
  • 110
1

You may want to have a look at Excel Resource Transfer. It is an Add-In for Microsoft Excel to import and export texts from resource files. There is a trial version. The full version costs 25,- Euro.

Ralph
  • 5,154
  • 1
  • 21
  • 19
1

If you're doing this for a web project, a better way to do internationalization (including translation) is to use the i18n nuget package. Not only does work better with templates but it has other nice-to-haves like localized URLs.

Here's an example from the github repo:

<div id="content">
    <h2>[[[Welcome to my web app!]]]</h2>
    <h3><span>[[[Amazing slogan here]]]</span></h3>
    <p>[[[Ad copy that would make Hiten Shah fall off his chair!]]]</p>
    <span class="button" title="[[[Click to see plans and pricing]]]">
        <a href="@Url.Action("Plans", "Home", new { area = "" })">
            <strong>[[[SEE PLANS & PRICING]]]</strong>
            <span>[[[Free unicorn with all plans!]]]</span>
        </a>
    </span>
</div>

Running a post-build task generates a PO database that can be provided to translators that use PO editing tools (like POEdit) to provide locale-specific text.

ajbeaven
  • 9,265
  • 13
  • 76
  • 121
0

You could use winres.exe from Microsoft, it lets you localize windows forms without having to use Visual Studio. It doesn't save the resources to a text file, but the idea is that the localization expert for each culture could use the tool to generate a localized versions of the application.

Here's a better explanation: http://msdn.microsoft.com/en-us/library/8bxdx003(VS.80).aspx

Millhouse
  • 732
  • 1
  • 8
  • 17