如何将字符串资源文件导入到表单的资源文件中? [英] How can I import a string resource file into a form's resource file?

查看:56
本文介绍了如何将字符串资源文件导入到表单的资源文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将创建一个字符串资源文件,该文件将用于本地化我公司的所有未来产品.让我们称该文件为CAPSStrings.resx,因为它将是它的名称.在C#下的WinForms中,将Localizable属性设置为True的表单具有自己的资源文件.除了字符串资源,这些文件还包含表单中控件的所有非默认设置.

I will be creating a string resource file that will be used for localization of all future products for my company. Let's call that file CAPSStrings.resx, since that will be its name. In WinForms under C#, forms with the Localizable property set to True have their own resource files. In addition to string resources, those files contain all non-default settings for controls in the form.

我希望能够将CAPSStrings.resx中的字符串导入到表单资源文件中,以便在使用Microsoft Visual Studio提供的单独的翻译工具开发或翻译表单时,可以使用CAPSStrings.resx的翻译..不必在运行时甚至在设计时都执行此操作.运行一个单独的独立程序就足够了,该程序可以知道源文件和目标文件的位置.

I would like to be able to import the strings from CAPSStrings.resx into the form resource files so that the translations from CAPSStrings.resx are available as the form is being developed or translated using the separate translation tool Microsoft provides with Visual Studio. This does not have to be done at run time, or even at design time. It would be sufficient to run a separate stand-alone program that would know the locations of the source and destination files.

做到这一点的最佳方法是什么?

What would be the best way to do this?

推荐答案

将Resources.Resx文件转换为附属程序集

具有 Resx 文件,您可以为您的应用程序创建附属程序集.

Convert a Resources.Resx file to a satellite Assembly

Having Resx file, you can create satellite assembly for your application.

在这篇文章中,我想您已经创建了一个名为 ResGenExample 的项目,其中包含一个 Form1 ,并且您已为设置了 Localizable 属性>从Form1 更改为 true ,您就有一个 Form1.resx .

In this post, I suppose you have created a project named ResGenExample containing a Form1 and you have set Localizable property of your Form1 to true and you have a Form1.resx.

这篇文章介绍了如何在不重建应用程序的情况下为具有Resx文件的新语言创建附属程序集.

This post describes how to create satellite assembly for new languages having Resx file without rebuilding the application.

具有Resx文件的新语言的卫星程序集,而无需重建应用程序

要这样,请按照以下步骤操作:

To so so, follow these steps:

  1. 比方说,您已经基于现有的 Form1.resx 创建了 Form1.fa-IR.resx ,其中包含波斯语的本地化值.

  1. Let's say you have created Form1.fa-IR.resx containing localized values for Persian language based on the existing Form1.resx.

打开Visual Studio的开发人员命令提示符,然后使用 CD 命令移至包含 Form1.fa-IR.resx 的文件夹以运行某些命令.

Open Developer Command Prompt for Visual Studio and use CD command to move to the folder which contains Form1.fa-IR.resx to run some commands.

使用

Use resgen.exe to convert Form1.fa-IR.resx file to a Form1.fa-IR.resources using the following command:

 Form1.fa-IR.resx ResGenExample.Form1.fa-IR.resources

  • 使用 al.exe 生成包含您在上一步中创建的 .resources 文件的附属程序集.

  • Use al.exe to generate the satellite assembly containing the .resources file which you created at the previous step:

     al /embed:ResGenExample.Form1.fa-IR.resources /out:ResGenExample.resources.dll /c:fa-IR
    

  • 在应用程序的可执行文件附近创建一个 fa-IR 文件夹(例如,在Debug文件夹中),然后将生成的附属程序集复制到该文件夹​​中.

  • Create a fa-IR folder near the executable file of your application, (for example in the Debug folder) and copy the generated satellite assembly to this folder.

    然后在显示 Form1 之前设置 UICulture 就足够了:

    Then it's enough to set the UICulture before showing Form1:

    System.Threading.Thread.CurrentThread.CurrentUICulture = 
        System.Globalization.CultureInfo.GetCultureInfo("fa-IR");
    

    有关更多信息:

  • 登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆