Localization in Windows Universal Apps – Part 1 1


The Windows Store helps you reach a large audience. It provides support for distributing your app worldwide and takes care of all the financial intricacies. You could choose to create only an English version of your app or an app in your own language, but that would reduce your potential audience. The Windows Store serves hundreds of markets and over a hundred different languages, so ignoring them greatly reduces the audience for your app. fortunately, the Windows Runtime exposes functionality that simplifies the creation of globalized apps. Making your app world-ready involves two things- Globalization and Localization.

Globalization

Globalization is the process of making sure that your app works well in multiple cultures. It is often confused with localization, which is the process of customizing your app for a specific language and culture Globalization refers to making your app act appropriately for different markets without any changes or customizations.

Localization

Localization refers making our app to adapt new market. To localize an app we have to remove all the hard coded strings and images and instead mark such elements with a unique identifier.

 

Implementing Localization

1

To share the view I have dragged one of the MainPage.xaml file to shared project and then deleted it from the other two projects. Now there is a common MainPage.xamlfile for both the projects. The view of project looks like this in Solution Explorer.

2
Now lets us create a simple UI containing a TextBlock only. The first thing we have to do is to remove all the hardcoded strings from the Xaml file and give that element an x:Uid. The x:Uid marking is completely independent from an element’s Name. The former is specifically for the localization process, and the latter is for the benefit of code-behind. Now our code looks like this

00

The next step is to create a new folder in Shared project. Name it “Strings”. In Strings folder we are going to keep all our resource file specific to each language in their specific folder. We are going to localize this app to French and our default language will be US-English. So we have to create folders for each of then. The name of folder should exactly match the language code such as fr-FR for French(France) and hi-IN for Hindi(India). We have to add as much folders as the languages we want to target and then we have to add resource file in each language specific folder which is going to contain all the translated strings. So here in our app I have created two folders Fr-FR for French and en-US for US English and added a resource file in each of them.

0

 

To add a resource file, right click on the specific folder and select Add->New Item ->Resource File(.resw).The default name is fine, you need not to change that.

 

3
Now open the first Resource file, here in our case it is en-US. Here in the Name section we have to mention the x:Uid of element with the property which we want to change, it can be string, color , height , width or any other property and in the value section we have to provide its value which we want to be shown if the app runs in that specific culture. In our demo app we are accessing the Text and color property of TextBlock whose X:uid was “message”
9

Similarly we will change other resource file which is for French. Here in the value section of message.Text property we will put the translated text which will be in French. Now if we run the app, it will run in our default language. My default language is US English, so the output view will be from en-US resource file. Also notice the foreground color of text.

4

Let us change our language to French and the run the app. To do this go to Control Panel->Clock, Language, and Region -> Language Select Add a Language and then select France. To make any selected language our default language we have to move it to top. The language here on the top of the list is automatically selected as our default language.

6

Now we have changed our default language to French. Now run the app again, we have successfully localized our app to French

7


Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “Localization in Windows Universal Apps – Part 1