How can I import a string resource file into a form's resource file?

大城市里の小女人 提交于 2021-01-29 21:44:16

问题


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.

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?


回答1:


Convert a Resources.Resx file to a satellite Assembly

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

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.

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

Satellite assembly for new language having Resx file without rebuilding the application

To so so, follow these steps:

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

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

  3. 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
    
  4. 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
    
  5. 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.

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

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

For more information:

  • Creating Satellite Assemblies for Desktop Apps
  • https://docs.microsoft.com/en-us/dotnet/framework/resources/working-with-resx-files-programmatically#convert-resx-files-to-binary-resources-files
  • Resgen.exe (Resource File Generator)
  • Al.exe (Assembly Linker)


来源:https://stackoverflow.com/questions/51025415/how-can-i-import-a-string-resource-file-into-a-forms-resource-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!