Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load all localization resources on startup

I've found a few similar topics, but I didn't get the answer I'm looking for.

I'm just trying the internationalization before I commence a "more serious" (WinForms) project. So, currently in my small test application, I solved the localization using satellite assemblies (language dll files), and I fill the controls' text fields with ResourceManager, and the language change is resolved by Thread.CurrentThread.CurrentCulture & Thread.CurrentThread.CurrentUICulture methods.

CultureInfo ci = new CultureInfo(lang);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;

this.button1.Text = Resources.LocTest.String1;

I would like to load all texts from the resources on the program initial startup, not only the main form but all of them (also on those forms, that not instantiated yet)! How could I implement this? Is this procedure is feasible at all?

I got some advice that I should simplify the whole localization process, by setting the "localizable" property to true and make the translations done. And most of the tutorials follow this way.

Does anybody have any idea, which method should I use?

Thanks in advance!

I'm very confused with the localization...

like image 970
Peter Krima Avatar asked Jan 09 '12 06:01

Peter Krima


1 Answers

please use the second method you've mentioned.

I got some advice that I should simplify the whole localization process, by setting the "localizable" property to true and make the translations done. And most of the tutorials follow this way.

Because this is the intended way of how Microsoft think localization should be done in a winforms app. http://msdn.microsoft.com/en-us/library/y99d1cd3%28v=vs.90%29.aspx

One problem with your first solution: How do you maintain that a text in another language will be displayed correctly?
That's one of the occuring problems, Microsoft have been aware of. With a small tool found in the SDK called: WINRES.exe you can see the designed forms and write the translation for them. http://msdn.microsoft.com/en-us/library/8bxdx003%28v=vs.90%29.aspx

If you want to change the language on runtime and update all forms this article maybe a hint for you: http://msdn.microsoft.com/en-us/magazine/cc163609.aspx#S9
The following lines gives an explain howto update you UI:

Dim crm As ComponentResourceManager  
crm = New ComponentResourceManager(GetType(Main))   
crm.ApplyResources(cmdAddCustomer, cmdAddCustomer.Name)   
crm.ApplyResources(mnuFile, mnuFile.Name)   
crm.ApplyResources(mnuFileAddCustomer, mnuFileAddCustomer.Name)   

The last 3 lines of this code can be found in each form (localizable = true) in the designer file.
So you can specify an interface for an update method, which every form should implement, implement the interface and after language change iterate the through all forms and call these method.

Hope this might help you ...

like image 159
70sCommander Avatar answered Nov 10 '22 10:11

70sCommander