domenica 28 ottobre 2012

Windows Phone - Localization

When you publish a Windows Phone application in the Marketplace, you have more visibility if you support the region language.

An easy way to build a localized app is to use resources file (.resx).

First of all remember to set the default "neutral" language in the project properties! This is an important step because the "AppResources.resx" file is used from all not specified languages.

Add new file, and name it "AppResources.resx" for default language. For a new language, just add a new resource named with the CultureInfo ISO letters:
  • for italian language.
  • AppResources.cs-CZ.resx for czech language.
  • for french language.
  • etc..
Remember to set all resource files to the public access modifier.

Now unload your project and edit the csproj file to add your supported language:

Create a class to get your resources.

public class LocalizedStrings
        private static AppResources localizedResources = new AppResources();

        public AppResources Strings
                return localizedResources;

In your xaml you need to declare your class as resource:
     <local:LocalizedStrings x:Key="LocalizedStrings"/>

Now you can use your localized string like this:
Text="{Binding Strings.Loading, Source={StaticResource LocalizedStrings}}"
Or from code behind:
txtLoading.Text = AppResources.Loading;

To test your app you can insert this code in application launching event:
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("it-IT");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("it-IT");

All CultureInfo codes here.

4 commenti:

  1. Questo commento è stato eliminato da un amministratore del blog.

  2. You can easily localize the strings of any Windows phone app by using this online software localization tool

  3. Hello everyone! If you need to explore the market of localization tools, so you can subscribe to a service, I highly recommend reading this article , because you'll find insights about pricing and useful information.

  4. Nice blog,thanks for sharing blog with us and you have done a incredible work in this blog to collect the information and i bookmark this blog for the future use.

    Windows Application Development Services