In this article we are going to see how to Localize the Windows Phone application, in our previous article we have seen how to Globalize the application to accept the Culture code and react based on the culture selected. With Localization we can design the application in such a way it adapts the changes that are required for a specific local market which basically includes the strings(texts) that changes based on the market or also the application bar that is required to change along with the menu items in the context. One important thing to notice is with Localize option we can change the Application title based on the market which plays a major impact to the application usage. But to Localize the application title we need to create a resource specific dll’s along with the separate Multilingual UI files for each of the language we are going to target to change it based on the market. [more]
Let us see the steps on how to achieve this task in our Windows Phone application development. Open Visual Studio 2012 IDE and create a new Windows Phone project with a valid project name as shown in the screen below.
Clicking on OK will create the project and the solution with the list of default files and folders that are required to run the application. It will take some time to create these files based on your system configuration, so once everything is ready we can see the Visual Studio IDE with the project as shown in the screen below.
Now let us add some controls that are used to examine the Localization technique that we will be using in the Windows Phone application development as shown in the code below. So what are we going to Localize here, we need to first locate the items which are needed to be localized. Once we identified we need to separate the code from the localized resources, basically the UI text strings that can be copied to each resource file strings. In the project solution we can see a file AppResources.resx in the resources folder by default when the project is created.
XAML Code:
[code:c#]<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Style="{StaticResource PhoneTextNormalStyle}" />
<TextBlock x:Name="PageTitle" Text="Localize App" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!–ContentPanel – place additional content here–>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock Height="122" HorizontalAlignment="Left" TextWrapping="Wrap" Margin="29,108,0,0" Name="textBlock1" Text="" VerticalAlignment="Top" Width="407" />
</Grid>
If we notice by default there is a Style that is assigned to the Textblock inside the stack panel which is basically Application Title. We can hardcode the title here by simply using the X:Name property to the value with the help of Text property. But to localize we need to go the the AppResources which is inside the Resource folder which holds the default resources that are available.
In the ApplicationTitle name we can change the value to the customized value that should be localized based on the application resource. So once changed we can go back to the XAML main page and change the style to take the value from the resource file as shown in the code below.
XAML Code:
[code:c#]<TextBlock x:Name="ApplicationTitle" Style="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}" />
[/code]Similarly we can do for the different resources inside the application, basically here we can add the Page Title, textblock value etc. Replace the values with the respective to localize as shown in the screen below.
Now we are done with our configuration, just run the application by pressing F5 directly from the keyboard or we can use the Build and execute the project option from the tool bar to run the application. Once the Build is successful we can see the Windows Phone emulator with the application and the expected outputs as shown in the screens below.
No Comments
Or you can use localization tools for a fast and professional localization of your windows phone app. I recommend https://poeditor.com/, it's the best of all the tools I have tested so far, although it's quite new and unknown.