There are several ways of implementing a multilingual application out of those,
- Using Resource Files
- Using a Database
- Using the Config File
- Using a File Full of Strings (Not good)
are few ways of getting the work done. Out of the above listed methods I will show how to create an application using resource files.
You can either use StaticResource or DynamicResource. StaticResource would be fine if you are not going to change the language while application is running. In this article I will be using StaticResource so let's get started.
(IDE - Visual Studio)
1. Create a new WPF project using visual studio and then design a simple UI as below. (In this app, Language menu item has 2 sub menus for 2 languages)
2. Add two new resource files named Resources.en-US.rsex and Resources.si-LK.rsex.
Note. name of the resource file must match with the format of, Resources.[name of the culture].rsex. You can find cultural information from these two links link1, link2
3. Move the two resource files inside the Properties.
4. Create item names of these resource files as following,
In default Resources.rsex file will be inside the properties and this should be modified too.
Note. Access Modifier must be set to Public
5. String values for a component can be assigned inside the .xaml file or in the code behind
Method 1 - Inside the .xaml file
You have to do two things. First one is add this namespace
Then you have to assign the relevant text to the component's text field
For Textblock1's text
For Button's text
Method 2 - In code behind
6. Add System.configuration to reference and indicate the following code set in App.xaml
Last one, you have to add following code snippet inside the configuration tag in the App.config file.
Change the Language
Following set of codes help to change the language. Since I have shown using static resources the application must be restarted to have the effects.