visual-studio 将 Visual Studio 资源文件转换为文本文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/198772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 09:45:49  来源:igfitidea点击:

Convert a Visual Studio resource file to a text file?

visual-studiolocalizationresource-file

提问by nportelli

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?

我知道有一些工具可以将文本文件转换为 Visual Studio 的资源文件。但我想将我的资源文件中的文本转换为文本文件,以便它们可以被翻译。或者有没有更好的方法来做到这一点?

采纳答案by Matías

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

您可以使用Simple Resx Editor,它具有一些有趣的功能,可以帮助您进入翻译过程。

回答by splattne

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

您可以使用Resx Editor,这是一个面向翻译的小型文件编辑器。

  • Target audience: translators.
  • Supported file format: Microsoft RESX 2.0
  • 目标受众:翻译人员。
  • 支持的文件格式:Microsoft RESX 2.0

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

这是 Joannès Vermoel(免费工具的作者)关于它的博客条目的链接

回答by fireydude

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.

将此代码添加到包含 your.resx 文件的项目(我的位于单独的“语言”项目中),然后使用以下代码将结果保存到 .csv 中,以便可以使用电子表格编辑器加载它。

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.

这不允许您将文件从 .csv 导入回您的 .resx 文件,以便它们可以被编译。有一个可以做到这一点的实用程序会很好。

回答by ajbeaven

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.

如果您正在为 Web 项目执行此操作,则进行国际化(包括翻译)的更好方法是使用i18n nuget 包。不仅可以更好地使用模板,而且它还有其他不错的功能,例如本地化的 URL。

Here's an example from the github repo:

这是 github 存储库中的一个示例:

<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.

运行构建后任务会生成一个 PO 数据库,该数据库可以提供给使用 PO 编辑工具(如POEdit)以提供特定于区域设置的文本的翻译人员。

回答by Ralph

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.

您可能想看看Excel 资源转移。它是 Microsoft Excel 的插件,用于从资源文件导入和导出文本。有试用版。完整版售价 25 欧元。

回答by Serge Wautier

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

尽管它违反直觉,但翻译 exe 而不是资源文件是一个更好的主意。在这里阅读原因:

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

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

回答by Millhouse

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.

您可以使用 Microsoft 的 winres.exe,它可以让您本地化 Windows 窗体而无需使用 Visual Studio。它不会将资源保存到文本文件中,但其想法是每种文化的本地化专家可以使用该工具生成应用程序的本地化版本。

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

这是一个更好的解释:http: //msdn.microsoft.com/en-us/library/8bxdx003(VS.80).aspx