Change CurrentUICulture, controls doesn't refresh

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear all,

My application allows users to switch languages at run time. I use the
following code to change the UI Culture but all controls are remaining
unchanged.

Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

Why? Anything that I need to do in order to refresh the controls?

Thanks for any help!

Tedmond
 
Tedmond said:
Dear all,

My application allows users to switch languages at run time. I use the
following code to change the UI Culture but all controls are remaining
unchanged.

Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

Why? Anything that I need to do in order to refresh the controls?

Thanks for any help!

Tedmond

Change "CurrentUICulture" will not automatically take effect in all UI
control.

Change "CurrentUICulture" just affect some APIs which are releated to
localization.
For example, "System.Resources.ResourceManager.GetString(...)", then it
will use the current "CurrentUICulture" to load suitable string resources.

For Windows.Form UI control, you need to reload all the resource strings
after change the "CurrentUICulture".
 
Hi Jacky,

I tried to call InitializeComponent() again after changing the
CurrentUICulture. I found it reload all the resource strings and all the
values are updated, however the display remains unchanged. Why? For
example, when I debug the program I found a button .Text property is updated
after changing the CurrentUICulture but the screen still showing the original
language.

Any more idea?

Thanks.
 
Tedmont,

The culture settings are affected to the culture setting as decimal point
and datetime representation, not direct to the used language. Because these
cultures can be depended from the language used in those countries is the
complete culture setting needed. (Think by instance to Canada, which uses
the culture from French and from England (not from the USA)).

Cor
 
Tedmond said:
Hi Jacky,

I tried to call InitializeComponent() again after changing the
CurrentUICulture. I found it reload all the resource strings and all the
values are updated, however the display remains unchanged. Why? For
example, when I debug the program I found a button .Text property is updated
after changing the CurrentUICulture but the screen still showing the original
language.



Hi Tedmond:

I do not sure what is your problem.
In my own app, it works.

Moreover, you should not call "InitializeComponent()" directly. The VS
generated "InitializeComponent()" not only loads string resource but
also creates all the child controls.
I believe it will raise exception when you call it again.
You should copy the code in "InitializeComponent()" which are related to
the localization resource in another function.



/// It is my example i na Form "FormMain"
.....
System.Threading.Thread.CurrentThread.CurrentUICulture = new
System.Globalization.CultureInfo(lang); //my selected lang from menu

ReloadControlString();

///
private void ReloadControlString()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(FormMain));

this.menuApp.Text = resources.GetString("menuApp.Text");
.........
}
///


Make sure you have made the correct localization resource for your
control. You can use debugger to check what string is loaded.
 
Back
Top