Click here to Skip to main content
12,813,906 members (31,823 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# WPF
Hi guys,
In our wpf project, we want to provide support for different languages.
How can it be accomplished in wpf

Thanks you!
Posted 22-Sep-12 2:00am
Wes Aday 22-Sep-12 7:04am
You use Globalization and Localization.
sreenivas.gupta 22-Sep-12 7:12am
Actually i read the article in msdn abt Globalization and localization, but i could not get it.
i exactly want to know how it can be achevied. Pls provide any sample project if you have any.
Wes Aday 22-Sep-12 7:18am
If you cannot understand the articles, how is it that you would understand a project?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:


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 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)
            System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("nl-NL");

I hope this gives you an idea how to use multiple languages in your application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 22 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100