×
Namespaces

Variants
Actions
(Difference between revisions)

Localized XAML content using ResourceDictionary - Wp7 to Wp8 Migration

From Nokia Developer Wiki
Jump to: navigation, search
Aady (Talk | contribs)
(Aady -)
Vaishali Rawat (Talk | contribs)
(Vaishali Rawat -)
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
[[Category:Windows Phone 8]][[Category:Windows Phone 7.5]][[Category:Windows Phone]]
 
[[Category:Windows Phone 8]][[Category:Windows Phone 7.5]][[Category:Windows Phone]]
{{Abstract|This article explains how to use ResourceDictionary for text localization and then we will see how to convert the code to WP8. }}  
+
{{Abstract|This article explains how to use [http://msdn.microsoft.com/en-us/library/system.windows.resourcedictionary.aspx ResourceDictionary] for text localization and then we will see how to convert the code to WP8. }}  
 
{{ArticleMetaData <!-- v1.2 -->
 
{{ArticleMetaData <!-- v1.2 -->
 
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
Line 8: Line 8:
 
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->  
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
+
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|translated-by= <!-- [[User:XXXX]] -->
 
|translated-by= <!-- [[User:XXXX]] -->
|translated-from-title= <!-- Title only -->  
+
|translated-from-title= <!-- Title only -->
 
|translated-from-id= <!-- Id of translated revision -->
 
|translated-from-id= <!-- Id of translated revision -->
|review-by=<!-- After re-review: [[User:username]] -->
+
|review-by= <!-- After re-review: [[User:username]] -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
|creationdate= <!-- Format YYYYMMDD -->
+
|creationdate= 20130122
|author= [[User:aady]]  
+
|author= [[User:aady]]
 
}}
 
}}
  
 
== Introduction ==
 
== Introduction ==
Localization is the customization of applications for a given culture or locale. ResourceDictionary is a hash table / dictionary implementation that contains objects (resources) which can be used in XAML or codebehind. <BR/><BR/>
+
Localization is the customization of applications for a given culture or locale. ResourceDictionary is a hash table/dictionary implementation that contains objects (resources) which can be used in XAML or codebehind. <BR/><BR/>
You might want to make the app localized compatible and for which you can define the string text values as resources and load the required one instead of hardcoding the text to control. Example: for a textblock control you might want to load the localized string as text and this can be done dynamically using ResourceDictionary.<BR/><BR/>
+
You might want to make your app localized and for which you can define the string text values as resources and load the required one instead of hardcoding the text to control. Example: for a textblock control you might want to load the localized string as text and this can be done dynamically using ResourceDictionary.<BR/><BR/>
In this article we will see how to use ResourceDictionary for text localization and then we will see how to convert the code to WP8.
+
In this article we will see how to use ResourceDictionary for text localization and then we will see how to convert the code to WP8.
  
 
==Implementing ResourceDictionary in WP7==
 
==Implementing ResourceDictionary in WP7==
Line 43: Line 43:
  
 
<Style x:Key="tbStyle" TargetType="TextBlock">
 
<Style x:Key="tbStyle" TargetType="TextBlock">
     <Setter Property="FontSize" Value="30"/>
+
     <Setter Property="FontSize" Value="30"/>
 
</Style>
 
</Style>
 
<sys:String x:Key="demoApp">Localized App</sys:String>
 
<sys:String x:Key="demoApp">Localized App</sys:String>
Line 83: Line 83:
  
 
==Summary==
 
==Summary==
Thus we see how easy is to make and app localized using ResourceDictionary and even more easy to make it WP8 compatible.
+
Thus we saw how easy it is to make an app localized using ResourceDictionary and even more easy to make it WP8 compatible.
 
<br/><br/>
 
<br/><br/>
 
For additional info, please refer:<br/>
 
For additional info, please refer:<br/>
 
[http://msdn.microsoft.com/en-us/library/dd882554%28v=vs.95%29.aspx How to: Make XAML Content Localizable]
 
[http://msdn.microsoft.com/en-us/library/dd882554%28v=vs.95%29.aspx How to: Make XAML Content Localizable]

Revision as of 07:54, 20 March 2013

This article explains how to use ResourceDictionary for text localization and then we will see how to convert the code to WP8.

SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
CompatibilityArticle
Created: Aady (22 Jan 2013)
Last edited: Vaishali Rawat (20 Mar 2013)

Contents

Introduction

Localization is the customization of applications for a given culture or locale. ResourceDictionary is a hash table/dictionary implementation that contains objects (resources) which can be used in XAML or codebehind.

You might want to make your app localized and for which you can define the string text values as resources and load the required one instead of hardcoding the text to control. Example: for a textblock control you might want to load the localized string as text and this can be done dynamically using ResourceDictionary.

In this article we will see how to use ResourceDictionary for text localization and then we will see how to convert the code to WP8.

Implementing ResourceDictionary in WP7

To implement a ResourceDictionary in WP7, follow the below steps: Create a .cs file Change the file extension to .xaml (example: resourceDictionary.xaml for further reference) Add reference to it in App.xaml Ready to use in application. Add the below code:

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 
<Style x:Key="tbStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="30"/>
</Style>
<sys:String x:Key="demoApp">Localized App</sys:String>
 
</ResourceDictionary>
<!--Application Resources-->
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="resourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
<TextBlock x:Name="ApplicationTitle" Style="{StaticResource tbStyle}" 
Text=”{ StaticResource demoApp }”/>

Conversion to WP8

It’s very simple, WP8 has an additional element called myNamespace:LocalizedStrings. Just add the line: <myNamespace:LocalizedStrings x:Key="LocalizedStrings"/> , after ResourceDictionary.MergedDictionaries element.

<!--Application Resources-->
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="resourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
<myNamespace:LocalizedStrings x:Key="LocalizedStrings"/>
</ResourceDictionary>
</Application.Resources>

Summary

Thus we saw how easy it is to make an app localized using ResourceDictionary and even more easy to make it WP8 compatible.

For additional info, please refer:
How to: Make XAML Content Localizable

164 page views in the last 30 days.
×