0
votes

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
You cannot reuse/import CAPSStrings.resx as resource file for your forms. But if you want to provide a solution to add support for different languages without rebuilding the application, I've shared a post showing how to add new language to your application.Reza Aghaei
@ROBERT: Note: I'm the author of a commercial localization tool (add-in) for VS developers (in the interest of full disclosure). It's unclear what you're trying to do. First, what is "CAPSStrings.resx". Is it the default language ".resx" file for one of your forms (each form has its own), or some other (non-form-based) ".resx" file you've created. It appears so and it seems you might be trying to use that single ".resx" file to populate all forms in your app. That's not natively supported by VS and therefore something I wouldn't recommended but you need to clarify your question.Larry
Yes, CAPSString.resx is independent of all forms in my application. It is designed for use in multiple applications. I am now planning not to try to merge it with form resource files, but instead use it separately and use the form resource files for control positioning and other things they were designed for.ROBERT RICHARDSON
@ROBERT: Ok, understood. VS isn't designed to handle form-based strings this way, so youl'd be causing yourself more headaches by trying (IMHO). Like yourself though, I'd prefer a single file system (one file to handle all strings). Unfortunately, VS doesn't natively support it (for forms anyway), and localization in VS isn't very good in any case. This is what motivated me to write a commercial localization tool, which does bundle all strings into a single file (for external translation) and eliminates all the drudgery. If it wasn't so much work I'd have given it away for free.Larry

1 Answers

0
votes

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: