Localization in Windows Phone 8 Application

In this article, we will learn how to make an application that provides support to multiple languages or for a specific culture. In previous articles, we saw:
Localization

From the Wikipedia:

"Localization is a process of translating a product into multiple 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.

 

The Windows Phone 8 application contains a folder named Resources that contains a resource file (that is a XML file) with a special .resx extension.

The Windows Phone 8 application template also contains a LocalizedStrings class that provides access to resources. An instance of this class is created in the app.xaml file with the key LocalizedStrings.

 

Open the AppResources.resx file and add some name/value string pairs.

 

Now open the properties of the project.

Under the Application tab, go to the Supported culture section and tick the languages you want your application to support.  I am selecting Hindi and U. S. English (selected by default).

 

When you select the new language(I selected Hindi), Visual Studio automatically adds a new AppResources file named AppResources.hi-IN.resx (depending on the selected culture/language). Double-click on the AppResources.hi-IN.resx file to open it.

 

Now replace the value (the translated text) depending on the language/culture. I have translated the value of the key PageName, DemoText according to the 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
  1. <Grid x:Name="LayoutRoot" Background="Transparent">  
  2.         <Grid.RowDefinitions>  
  3.             <RowDefinition Height="Auto"/>  
  4.             <RowDefinition Height="*"/>  
  5.         </Grid.RowDefinitions>  
  6.         <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">  
  7.             <TextBlock Text="Demo APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>  
  8.             <TextBlock Text="{Binding Source={StaticResource LocalizedStrings},Path=LocalizedResources.PageName}"   
  9.   
  10. Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Padding="0 10"/>  
  11.         </StackPanel>  
  12.         <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">  
  13.             <StackPanel>  
  14.                 <TextBlock Text="{Binding Source={StaticResource LocalizedStrings},Path=LocalizedResources.DemoText}"   
  15.   
  16. FontSize="32"></TextBlock>  
  17.             </StackPanel>  
  18.         </Grid>  
  19. </Grid>  
Build and Run the application.

Preview
 
Now let's change the language of our device to Hindi. Go to Settings -> Langauge + region. 
 
Change the Phone Language to Hindi.
 
Click on restart phone. After your phone restarts, open your application and you will see that our application now supports the Hindi language/culture.
 
I hope you like this. Thanks. 


Similar Articles