supporting localization
-
what's the easiest way to enable the localization support to your form so that u can select the language u want from the menu and all the buttons texts and numerics change to the specidied language. do u have do create seperate forms for each of the language u support? samitha
-
what's the easiest way to enable the localization support to your form so that u can select the language u want from the menu and all the buttons texts and numerics change to the specidied language. do u have do create seperate forms for each of the language u support? samitha
The first thing to do would be to read Developing World-ready Applications[^] in the .NET Framework SDK. Creating different forms for different cultures is not only inefficient but incredibly inflexible. Doing things the right way, you need only add localization code (documented in the topic above) and for each language you want to support, override the strings, sizes, locations, etc. (as necessary - not all always need to be changed) in a satellite assembly. VS.NET can help you do this using the form designer (though it's important to understand what's happening, otherwise you're not actually developing anything) but it won't help you switch languages on the fly. To do that, you have to break the designer. Change
InitializeComponent
so that it doesn't instantiate the controls (move instantiation in the top of that method to the constructor) and only makes calls toResourceManager.GetObject
(or, from the designer in VS 2005,ComponentResourceManager.ApplyResources
). When you switch languages, setThread.CurrentUICulture
to theCultureInfo
you want (likenew CultureInfo("de-DE")
for the German language in the country of Germany) and call the methodInitializeComponent
again to reset the localized resources. Do this after changing the form'sLocalized
property totrue
, which will add the necessary code. When localizing, localize all properties attributed withLocalizableAttribute(true)
. The neutral language (the language in which the primary assembly was written, which should contain the neutral language resources) must contain all the localized resources (which is another reason for placing these in the primary assembly); the satellite assemblies can be added later and used automatically by .NET without changing a single line of code. Fusion, the assembly binder, looks for satellite assemblies for theThread.CurrentUICulture
when binding an assembly. If no assembly is found, the neutral language resources in the primary assembly (the assembly that contains code - not just resources). In order to expediate this behavior, use theNeutralResourcesLanguageAttribute
at the assembly level (prefixed with[assembl