Localization and Globalization in Windows Store Apps

In this article we explain how to use Localization and Globalization in Windows Store apps.

Introduction

Today we are going to explain how to use Localization in Windows Store apps. Windows Store apps support Localization and Globalization of apps. Localization is the process of translating the application User Interface (UI) or adapting graphics for a specific culture.

In this article we are usng string resources for the application User Interface (UI). The application User Interface will be changed depending on the culture or language of the system of your application.

Step 1

Open Visual Studio 2012 and start a new Windows Store apps project or open an existing project where you want to use Localization.

Step 2

In Solution Explorer click on "Open package.appxmanifest" to open it then go to the Application UI tab, and set your default Language to "en-US".

Default-Language-Windows-Store-Apps.png

Step 3

In the Solution Explorer, right-click the project and select "Add" > "New Folder". The folder name is "strings".

Step 4

Right-click the strings folder and add two new folders. Name then "en-US" and "hi-IN".

Step 5

Now right-click on each of the "en-US" and "hi-IN" folders and select "Add" > "New Item". Select "Resources File (.resw)" for both folders.

Resorrce-File-Windows-Store-Apps.png

Step 6

In "Resource.resx" click on "Add resource". Add a string resource as in the following:

String resource for "en-US".

en-US-Windows-Store-Apps.png

String resource for "hi-IN".

hi-In-Windows-Store-Apps.png

Step 7

Now go the "MainPage.xaml" page and add a TextBlock control. Now add a resource to the UI control as in the following:

<TextBlock HorizontalAlignment="Left" Text="" TextWrapping="Wrap" FontSize="30" x:Uid="Msg" />

Step 8

Now run your program. You will see the "en-US" resource text as the default. Because the default language of the application is "en-US".

En-Out-Put-Windows-Store-Apps.png

Step 9

If you want to test the app for another language then you must change the your system language. To do that go to "Control Panel" -> "Languages". Select the language in the list and click Move up until it is at the top.

Step 10

You can also test the app for another language by changing the application language. To do that go to "Solution Explorer" and double-click on "App.xaml.cs" to open it and add the following code to "Public App". Here we are using "hi-IN" for the "Hindi" language. Replace it with another language code to check the application for the other language. Here we are using the "System.Globalization" namespace.

public App()

{

     this.InitializeComponent();

     this.Suspending += OnSuspending;

 

     var culture = new CultureInfo("hi-IN");

     Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = culture.Name;

     CultureInfo.DefaultThreadCurrentCulture = culture;

     CultureInfo.DefaultThreadCurrentUICulture = culture;

}

Step 11

Now run the program. In this example we used the two languages "en-US" and "hi-IN". You can use more than two languages to localize an app.

Hn-Output-Windows-Store-Apps.png