Friday, July 2, 2010

Using Resource Dictionary for multi language support

WPF Provides nice concept of resource dictionary where you can define your resources (key value pairs) used across the application. For each language you need to create separate resource dictionary & the same can be used in XAML files with no much effort.

Lets create a resource dictionary for Ducth.


Similarly lets create one more resource dictionary for English With same Keys.


Now Create two forms one to select  the language & One to see how localisation Works.


 Once you select the language from combo box Load that respective resource dictionary into application .
Something like this. I have written in my App.Xaml.cs



Call this method in your language selection form


Once this is done

Create new form something like this


The cs file will look like this,


If you see the code.. you can find all the label's content will be pointed to dynamic resource
Context={DynamicResource Key}
key is defined in all the resource dictionaries of respective languages.

Now Run the application you can see the labels content getting changed based on the selection of language.

1 comment: