问题
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:
Let's say you have created
Form1.fa-IR.resx
containing localized values for Persian language based on the existingForm1.resx
.Open Developer Command Prompt for Visual Studio and use
CD
command to move to the folder which containsForm1.fa-IR.resx
to run some commands.Use resgen.exe to convert
Form1.fa-IR.resx
file to aForm1.fa-IR.resources
using the following command:Form1.fa-IR.resx ResGenExample.Form1.fa-IR.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
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