WindowsPhoneGeek

WPAppInfo

Login | Join (Why?)

rss rss rss
logo

Localizing a Windows Phone app Step by Step

published on: 11/15/2011 | Views: N/A | Tags: Localization

by WindowsPhoneGeek

In this article I am going to talk about how to localize a Windows Phone application.

image image

Basically you need to separate localizable resources from the rest of the code by creating language-specific resource files. Visual Studio uses these files to create assemblies that allow your application to support many languages.

For reference take a look at the MSDN documentation.

Getting Started

Step1: Create a Windows Phone 7 application project.

Step2: Add a resource file for the default language of your application. In our case we will add a resource file named AppResources.resx

image

Step3: Open the resource file and enter the strings that you want to be localized in the resource file.

image

NOTE: It is important to consider the following requirements while editing strings in the resource editor:

  • The name must be unique. Make it as descriptive as possible.

  • The value is the string that will be displayed to the user in the application.

  • The comment is optional, but it is helpful for translators, especially in large resource files with many strings.

Step4:  Copy the resource file once for each additional language that you want your app to support. Note that each resource file must contain the correct culture/language name, as described in Culture and Language Support for Windows Phone.  In our case we will use the following name of the file  AppResources.de-DE.resx (for the culture German (Germany)). The general resource file name format is :

<name of main resource>.<culture name>.resx

image

Step5: Translate the strings in the additionally added files.

image

Step6: Edit the project file to define the additional cultures / languages the application will support. To do this first unload the project file by pressing the mouse right button on the project and then select "Unload Project":

image

After that again press the mouse right button on the project and select "Edit" from the context menu:

imageimage

Finally you will need to add the names of the additional cultures in the project file the following way:  <SupportedCultures>de-DE;</SupportedCultures>

NOTE: If you have more than one additional culture you can include them in this way (note that semicolon is used to separate the culture names): <SupportedCultures>de-DE;es-ES;</SupportedCultures>

image   image

Step7: Make sure that the Access Modifier of all resource files(including the default one) is set to Public!

image

Step8: Create a new class that will have a property exposing the resources:

public class LocalizedStrings
{
    public LocalizedStrings()
    {
    }

    private static AppResources localizedResources = new AppResources();

    public AppResources AppResources
    {
        get { return localizedResources; }
    }
}

In the example above AppResources is the name of the class generated automatically for the resource files:

image

Step9: Open the App.xaml file and add the following code:

<Application.Resources>
    <local:LocalizedStrings xmlns:local="clr-namespace:WPLocalization" x:Key="LocalizedStrings" />
</Application.Resources>

 

Step10: Whenever you want to show a localized string in your app you will have to bind to a specific property of the global resource that we have just defined. The property names correspond to the resource names in the resource files. Example:

<TextBlock x:Name="PageTitle" 
Text="{Binding Path=AppResources.Title, Source={StaticResource LocalizedStrings}}" 
Margin="9,-7,0,0" 
Style="{StaticResource PhoneTextTitle1Style}"/>

To test the localization you will have to change the Display Language of the emulator in this way:

imageimageimageimage

Here is the result:

image image

That was all about how to localize a  Windows Phone application.  You can find the full source code here:

I hope that the article was helpful.

You can also follow us on Twitter @winphonegeek

Comments

:D

posted by: Alfah on 11/15/2011 3:38:43 PM

When you said you would be doin an article on localization, din expect it this fast :)

good goin.

Well done

posted by: Casper Skovgaard on 11/25/2011 12:59:22 PM

Only thing that didn't worked for me was step 6. I don't have the option to unload project. But I just followed the step on msdn and it worked. And now I have a localized app :-)

Now a couple of questions:

  1. Would it be possible to publish an app with several names depending on the local marketplace. So in English marketplace name of app is "My local..." and on German marketplace it would be "Meine lo..."?

  2. Is it possible to overwrite Display Language from settings, for example with language selected from a setting stored in the app?

Thanks.

/Casper

RE: @Casper Skovgaard

posted by: winphonegeek on 12/6/2011 11:50:17 AM

  1. You can localize the application title that appears in the application list and also on the application tile when the user pins your app to start. More information about localizing the app title you can find here: http://msdn.microsoft.com/en-us/library/ff967550(v=vs.92).aspx

Unfortunately I cannot tell if the marketplace will show your localized app title for the different countries.

  1. I am not aware of the existence of API that will allow you to change the Display Settings of the phone.

Cool touch for the article

posted by: jinek@msn.com on 12/27/2011 5:36:51 PM

Create the class: public partial class LocalizedBinding : Binding { public LocalizedBinding() { Source = Application.Current.Resources["LocalizedStrings"]; }

    private string _lc;
    public string LC
    {
        get { return _lc; }
        set
        {
            _lc = value;
            Path = new PropertyPath(string.Format(@"AppResources.{0}", value));
        }
    }
}

and you can use it in more simple way:

posted by: Kris on 5/8/2012 12:54:05 AM

Step8: Create a new class that will have a property exposing the resources:

Where?

Add comment to 'Localizing a Windows Phone app Step by Step'

Comment

Our Top Articles & Free books

Our Top Tips & Samples