Friday, November 25, 2011

Localization in Mango

Hi everyone! In this blog post, we are going to cover how you can create localized applications on Mango!

Today, a developer creates an application wich is used globally by people speaking and understanding different languages. It is always better if your application is localized to different regions. In this post, we will learn how to create such application and test the localization on emulator.

The application we are going to create will be very simple one but you can use the concept and code shared here to create whatever you intend to do. This sample application when seen in United States region will show text as "Hello Friends!" and when seen in Spain region, will have text as "Halo Amigos!" -





Steps to create Localized application

1. On the Solution File, Create a new Folder named "Localization" and add two resx files - "Strings.resx" and "Strings.es-ES.resx".




2. In String.resx, add an entry with name of string as "Localization.HelloText" and value as "Hello Friends!" -


3. In Strings.es-ES.resx, add an entry with name of string as "Localization.HelloText" and value as "Hola Amigos!"


4. As the default resource file is named "Strings.resx", the Neutral Language should be kept as "United States (English) under Projects -> Application Tab -> Advanced Assembly Information.

5. If you want to make this application support Spanish region, then open the .csproj file in text editor, add the following -

<SupportedCultures>es-ES;</SupportedCultures>

Add any number of cultures as you want your application to support!

6. Code needed to read the localized strings from resource file is as follows -

ResourceManagerresourceManager = new ResourceManager("Localization.Localization.Strings", Assembly.GetExecutingAssembly());

textBlock1.Text = resourceManager.GetString("Localization.HelloText", CultureInfo.CurrentCulture);


Note -  CultureInfo needs "System.Globalization"  while Assembly class needs "System.Reflection" and ResourceManager needs "System.Resources".

Steps to test the application on emulator

The following are steps to test the localization on emulator -

1. Go to Settings



2. Select Region + Language under Settings
3. For "Region Format" choose Spanish - Spain (es - ES)


4. Click on link for restarting the emulator to save the changes


5. Click on "Localization" application to start the application with region as Spain


And here you go!! The application is localized. Check out this applicaiton by changing the region back to United States. The text will be shown in English.

1 comment:

  1. Great post In this blog entry they are controlling us how we can make restricted provisions on Mango.
    For more details please visit.
    windows mobile app // iPhone application development // Android application development

    ReplyDelete