Load all localization resources at startup

I found several similar topics, but I did not get the answer I'm looking for.

I'm just trying to internationalize before I start the “more serious” (WinForms) project. So, currently, in my small test application, I decided to localize using satellite assemblies (dll language files), and I fill in the text fields of the ResourceManager controls, and the language change is allowed by Thread.CurrentThread.CurrentCulture and Thread.CurrentThread. Methods CurrentUICulture.

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 resources at the initial start of the program, and not only in the main form, but all of them (also on those forms that have not yet been created)! How could I implement this? Is this procedure possible at all?

I have a tip that I should simplify the whole localization process by setting the "localizable" property to true and making the translation complete. And most manuals follow this path.

Does anyone have any idea which method should I use?

Thanks in advance!

I am very confused by localization ...

+6
source share
1 answer

use the second method you mentioned.

I have a tip that I should simplify the whole localization process by setting the "localizable" property to true and making the translation complete. And most manuals follow this path.

Because this is the intended way, as Microsoft believes that localization should be done in the winforms application. http://msdn.microsoft.com/en-us/library/y99d1cd3%28v=vs.90%29.aspx

One problem with your first solution: How do you say that text in another language will display correctly? Microsoft is one of the problems Microsoft has encountered. Using the small tool found in the SDK called: WINRES.exe, you can view the created forms and write a translation for them. http://msdn.microsoft.com/en-us/library/8bxdx003%28v=vs.90%29.aspx

If you want to change the language at run time and update all forms, this article may be a tip to you: http://msdn.microsoft.com/en-us/magazine/cc163609.aspx#S9
The following lines explain how to update the 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 constructor file.
Thus, you can specify the interface for the update method that each form must implement, implement the interface and, after changing the language, iterate over all the forms and call this method.

Hope this helps you ...

+2
source

Source: https://habr.com/ru/post/905491/


All Articles