Read this blog on
Using Resources.resx in WPF application[
^]. If you follow the steps (don't forget to change the access modifier to public or it will not work), you are prepared to use the Resource.resx in WPF.
The items you add to Resource.resx are your default language. You can add different languages. First you will need to know the
language codes[
^]. For instance the code of your language would be hi-IN (hindi, India). Some language are slightly different in other countries. Americans speak en-US (english United States) and Brits speak en-GB (english Great Britain). Languages spoken in more than one country also have a general version. General english has the code 'en' (without a country code).
To add a resource file for a specific language, you need to add a New Item of the
Resource file template (search the templates for 'Resource' or browse the available templates). The name has to follow a strict pattern like
Resources.[languagecode].resx. For instance:
Resources.en.resx
Resources.en-US.resx
Resources.en-GB.resx
Resources.hi-IN.resx
After creating the file, you need to drag-and-drop it to the Properties folder in the Solution explorer (the folder where the (default) Resources.resx resides). Otherwise it won't work.
Next you'll need to add the resources. The default Resources.resx needs to contain all the resources. For instance the following (1st value is the resource name, 2nd value is the value)
HelloWorld - Hello World!
ClickMe - Click Me
ExitApplication - Exit application
Let's say that you want to add a dutch resources file (if my Hindi was well enough I would have added a Hindi resource file :)) In the Resources.nl-NL.resx you add the following
HelloWorld - Hallo Wereld!
ClickMe - Klik mij
(ExitAppication omitted on purpose for the examples sake)
Lets say you have two buttons in your application and made the content like discribed in the
Using Resources.resx in WPF application blog[
^]
<button content="{x:Static p:Resources.ClickMe}" />
<button content="{x:Static p:Resources.ExitApplication}" />
Based on the System.Threading.Thread.CurrentThread.CurrentUICulture you're application will load resources from the different resources files according to the following principle.
* Current UICulture is hi-IN. Is there a hi-IN resource file? Yes → use it.
* No → Is there support for general hi language (without the Country code India)? Yes → use it
* No → Use the default Resources.resx (the resources.resx contains the default language)
This principle is used for each resource you search. In my english/dutch example I had not supplied a dutch value for ExitApplication. The application will search for a dutch value for ExitApplication. Because I didn't supply it, if will fallback to the defautl value of 'Exit application'(Searching for ClickMe won't fail and the dutch version of Click Me will be shown on the button).
To change the CurrentUI language you could use the following code.
using System.Globalization;
namespace LocalizationTest
{
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("nl-NL");
}
}
}
I hope this gives you an idea how to use multiple languages in your application.