John Mangam

Hi,

How can I change the localization content dynamically

I wan to give the user the choice of the langauge/localization and I want to display the content

in that language dynamically.

Could you please suggest an easy way to do it

Thanks !

Regards,

John Mangam



Re: Visual C# General Dynamic Localization

TaylorMichaelL

You can use Threading.CurrentThread.CurrentUICulture to change the locale of your UI. Is this what you wanted

Michael Taylor - 8/6/07

http://p3net.mvps.org





Re: Visual C# General Dynamic Localization

timvw

The 'problem' with changing Thread.CurrentUICulture is that it only affects forms that are created *after* this property has been changed (because the resourcemanager will typically only be used in the InitializeComponent method, which is called in a Forms constructor...)





Re: Visual C# General Dynamic Localization

TaylorMichaelL

Yes but you can force a form to "refresh" with the new locale. You will have to do some legwork because there is no direct way to get access to all the forms or controls that are visible but you could probably use some heuristics (like enumerating the controls (and subcontrols) of a form) to simplify things. Nevertheless you would create an instance of the resource manager and then use ApplyResource to force a refresh of the localized data.

ComponentResourceManager resMgr = new ComponentResourceManager(typeof(MainForm));
resMgr.ApplyResources(ctrl, ctrl.Name);

resMgr.ApplyResources(ctrl2, ctrl2.Name);

...

A couple of wrapper methods and you can probably localize an entire form (or forms) with little trouble.

Here is an article to help you out: http://msdn.microsoft.com/msdnmag/issues/06/05/BasicInstincts/default.aspx

Michael Taylor - 8/6/07

http://p3net.mvps.org





Re: Visual C# General Dynamic Localization

boban.s

If your application is very simple, with one to two forms, then applying resources on opened forms manually is not very complex job. One simple way of applying resources is by calling Initialize method of opened forms, but then comes problem with values on editable controls that will be lost, so that is another problem to solve. If your application is not simple, have tents of forms, with many controls on the form, then applying resources in runtime is killing process with no one time solution. I preffer to just give user a message that if he wants to see the changes, he must restart the application. This is common scenario with many well know application that i have used.






Re: Visual C# General Dynamic Localization

Caddre

Dynamic localization is a mirage as Broban have explained for a small application maybe all others many things can go wrong. I have seen 32 languages application you start with translated static content and then let your users insert language specific texts. Now I am not saying you cannot do it with third party tools but if you are writing everything the link below will give you some idea please read it he covered Winfom related issues at the end of the article. The point I am trying make is passing the Latin alphabet dynamically is not the same thing as passing 2000 plus alphabet languages like Chinese, Japanese and Korean. One more thing VS2005 comes with Advanced Save as option which lets you save your code with specific languages.

http://www.codeproject.com/useritems/localization.asp