views:

313

answers:

3

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.

+1  A: 

It does this already.

Turn on Localizable in the Form or UserControl designer.

Now change you Language (also in designer), and the appropriate langXXX.resx is automagically created.

leppie
From everything I read, this seemed to be the way to do it, but the Text properties of my controls did not appear anywhere in the Resource file.
Yannick M.
If you build your own custom controls you have to set the Localizable attribute for the properties that need localization (such as display text, icons, etc.). To do this, just put `[Localizable(true)]` above the property declaration.
Joey
I see, but even standard controls like labels, buttons, radio buttons, groupboxes do not appear in the resourcefile. Maybe I am doing something wrong...
Yannick M.
There a basically no strings in the resource files. There are two bitmaps, and an icon, but no strings.
Yannick M.
+1  A: 

You just need to make the form localizable (in the properties panel, set Localizable to true). Then you just need to select the language for which you want to localizable. All necessary resource files are generated automatically

Thomas Levesque
+1  A: 

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.

Joey
Replacing all the control captions with the translation did the trick, thank you!
Yannick M.