Thursday, August 28, 2014

Provide Mutiple Language Support For Windows Store App and Windows Phoone App

Windows 8.x supports a host of languages from Afrikaans to Yoruba including Chinese, Japanese and Vietnamese.  Click the link for the list of languages supported
And Windows app stores are in business in more than a dozen countries.

The market in windows store app is big, if you make your apps support multiple languages, your app’s revenue could be multiplied.
Well, Microsoft did some good job in making your app supporting multiple language easy and painless.

This tutorial will show you how easy to make your app supports multiple languages.
First of all, you want your apps be popular, so you want to support the languages in which they generate the most downloads. Without challenges, English is your first choice. The question is what is after English. If you search “Most Influential Languages in the World” or “List of languages by number of native speakers” you will get different list.  Let’s say you have made your decision on which languages to support beyond English and let’s get into on how to implement it in your app.
Click this link for the language codes used in Microsoft Windows system. Take a few examples here:

en-US:  English United Statesen-GB : English United Kingdom
es-MX: Spanish Mexico
es           : Spanish
fr             : French
fr-CA     : French Canada

From here you can tell it consist 2 parts, language and region. The priority on how the resource is used is in the following order:
1.       The resource associated with the specific language and specific region
2.       The resource associated with the specific language
3.       The resource associated with the default language, in most of cases, English United States.

In Windows Store app and Windows Phone app, there are 2 ways to reference language specific resource. One is in XAML, the other is in .Net programming languages like C# or VB.Net. Let me get to them one by one.
1.       How to reference resource with Multilanguage support in XAML

In your windows store app project or windows Phone project, add folders naming after the language code.  For example, en-US for English United Standard, and zh-Hans for Chinese China.

Then add a resource file named Resources.resw in each of them. (In my experience, I like to work on English resource first and then make a copy of the resource file and paste it to the other language folder and change the content of each resource. In this way, I do not need to type the resource key multiple times. I find this way would save time and reduce human errors. )

For the resource to be referred in XAML, the resource key should be named in the pattern of <Element Uid>.<Property Name>. Take an example, you want a resource to be used on Content property of a button with the Uid as ButtonDownload, the key should be ButtonDownload.Content. Then you provide the text value in the respective language accordingly.  When this is done, the resource is ready to be used in XAML. All it takes is adding x:Uid attribute to your XAML element . The following is an example:

<Button x:Uid="ButtonDownload" Grid.Row="3"…./>

Once you have completely externalized all your language specific resource from XAML into the resource file and changed your XAML to include x:Uid  attribute. You are more than 50% done no matter how many languages you plan to support.
The next step is to create folders following the language code and copy your English version of the resource file into these folders, and change the resource values accordingly.

How to reference resource with Multilanguage support in Code

The first step is to add a folder named Strings and add a folder named “en-US” for English United States. And add a resource file named Resources.resw. then you start to add resource into the resource file based on key value pair.

We will look at how in code these resource is referred.

protected  ResourceLoader MessagesResource = new ResourceLoader();

this line establishes the resource loader, if your resource file is named different from “Resources”, you could provide the name of the resource file to the constructor.

MessagesResource.GetString(“resource key”) will get you the resource value based your current language setting of the OS.

Similarly, after you externalized all your resource form your .Net code, into the resource file, all you need to do is create folders under Strings folder and copy the English version of the resource file to these folders and change the value of the resource to is specific language content.

1 comment:

  1. Quantum Binary Signals

    Get professional trading signals sent to your cell phone every day.

    Start following our trades NOW & gain up to 270% a day.

    ReplyDelete