Wednesday, 5 August 2015

Localization in Windows Phone 8 Application

In this article, We will learn How to make an application which provides support multiple languages or for specific culture. In previous article, we saw:


What is Localization?
From the Wikipedia-
"Localization is a process of translating a product into different languages or adapting a product for a specific country or region."

Let's Begin:
Create a new Windows Phone application and select Windows Phone 8.0 as the target Windows Phone OS for this application and click on OK.
Create Windows Phone Project
Windows Phone 8 Application Contains a folder named as Resources which contains Resource file(which is a xml file) with a special .resx extension. Windows Phone 8 Application template also contains a LocalizedStrings class which provides access to resources. An instance of this class is created in app.xaml with the key LocalizedStrings. Open AppResources.resx file and add some Name-Value string Pairs.
LocalizedStrings
Now open the properties of the project
Under the Application tab, Go to Supported culture section and Tick the languages you want your application to support. I am Selecting Hindi and English U.S.(Selected by Default ).
When you select the new language(I selected Hindi), Visual Studio automatically adds a new AppResources file named as AppResources.hi-IN.resx accoording to selected Culture/Language. Double click on AppResources.hi-IN.resx file to open it.
Now replace the value(the translated text) according to language/culture. I have translated the value of Key PageName, DemoText according to Hindi language. Then save and build your application.
Databind the text property of TextBlock or other control to StaticResource with a key LocalizedStrings.
Source Code:
<Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="Demo APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
            <TextBlock Text="{Binding Source={StaticResource LocalizedStrings},Path=LocalizedResources.PageName}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Padding="0 10"/>
        </StackPanel>
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <StackPanel>
                <TextBlock Text="{Binding Source={StaticResource LocalizedStrings},Path=LocalizedResources.DemoText}" FontSize="32"></TextBlock>
            </StackPanel>
        </Grid>
</Grid>
Build and Run the application.
Preview:
Now let's change the Language of our device to Hindi. Go to Settings ->  Langauge + region.
Change Phone Language to Hindi.
Click on restart Phone. After your phone restarts, Open your application and you see our application is now supported for Hindi Language/culture.
I hope you like this. Thanks.
[Download Source Code via Google Drive]

1 comment:

  1. Hello Anoop and thanks for sharing this "how to" article, useful information. Another way to translate your mobile app is using a software localization tool. I recommend you https://poeditor.com/ a collaborative translation management platform where project managers, translators and other contributors can work efficiently on their projects. It has also a WordPress plugin which can be found here: https://wordpress.org/plugins/poeditor/

    ReplyDelete

Subscribe Now

Popular Posts

Contact us

Name

Email *

Message *

Subscribe us on YouTube

Like us on Facebook

Follow us on Google+