I created a folder and put .NET .resx files in it. The default language was called Lan.resx; the localized one was called Lan.nl-BE.resx.
Then I added a class called Culture, containing a function called GetCulture() that returns a new Resources.Lan(), and a function called Set(CultureInfo culture) that sets the culture of the current thread by doing Thread.CurrentThread.Current(UI)Culture = culture.
In the App.xaml I added an application resource as follows:
<ObjectDataProvider x:Key="Lan" ObjectType="{x:Type this:Culture}" MethodName="GetCulture" />
To change the culture I can then do:
Culture.Set(culture); ((ObjectDataProvider)App.Current.FindResource("Lan")).Refresh();
Finally, controls are localized using statements like this:
{Binding Path=Options, Source={StaticResource Lan}}
No comments:
Post a Comment