Re: Change CurrentUICulture, controls doesn't refresh

Tech-Archive recommends: Fix windows errors by optimizing your registry



Tedmond wrote:
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.






--
Jacky Kwok
jacky@alumni_DOT_cuhk_DOT_edu_DOT_hk
jacky@compose_DOT_com_DOT_hk



Any more idea?

Thanks.

"jacky kwok" wrote:

Tedmond wrote:
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".


--
Jacky Kwok
jacky@alumni_DOT_cuhk_DOT_edu_DOT_hk
jacky@compose_DOT_com_DOT_hk

.


Quantcast