Search code examples
.netwinformsreflectionlocalizationresourcemanager

Why aren't the localized resource files created automatically when changing the culture in the designer?


I am currently working on localizing a Form. However I am somewhat confused as to how one correctly does this.

I thought it would be possible to export control properties to a resource file automatically, but it seems this is a manual task.

My current approach is to add all the Control Properties which are of type String and are writable to the resource file. This by recursively enumerating all the controls and child controls on the form and Reflecting the properties.

But this seems somewhat complicated, and I wonder how other people do this.

So my question: What is the best-practice in terms of using a resource file for Control Text Localization?

Edit: I see what I am doing wrong. I thought the Displaytext would automatically be copied into each resource file. However it seems only the fields that have changed are copied.

So basically, I set the language to a certain setting, change the DisplayText for all the controls, and when I change the language back to (default), the changed are saved.

Thanks for any/all comments.


Solution

  • Well, actually localizing a form is not that hard. You set the "Localizable" property to "true". This causes all localizable properties of controls on the form to be migrated into a resource file. The current resource file is the locale-independent one. You can then select another language in the Form's properties and replace all control captions and texts with their translated variants. This causes the appropriate locale-dependent resource file to be created and used.

    You can select the language in which the interface is displayed by setting the CurrentCulture and CurrentUICulture properties on Thread.CurrentThread:

    Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-GB");
    Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-GB");
    

    The interface wil adapt accordingly.