programming4us
programming4us
WEBSITE

Application Patterns and Tips : Localize a Silverlight Application

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
8/21/2012 4:11:45 PM
Localized resources in Silverlight are very similar to the resource file methods just given.

1.
After you create your Silverlight project, add a new resource file called, for example, Resources.resx. This is the default resource file. Visual Studio will also create a class to access these resources.

2.
Add a resource file for each culture you will need, including the appropriate culture code in the filename, e.g., Resources.it.resx or Resources.fr-CA.resx.

3.
In the project properties, go to the Sliverlight tab, and click the Assembly Information... button. Select the neutral language for your project (in my example, this is English, with no country).

4.
Now edit the project file manually by right-clicking it in the Solution Explorer and selecting Unload Project. Right-click the project again and select Edit project.csproj.

5.
Edit the <SupportedCultures /> tag to include the non-default cultures you want. For example:

<SupportedCultures>it;fr-CA</SupportedCultures>

6.
Save and close the file.

7.
Reload the project by right-clicking the project in Solution Explorer and selecting Reload Project.

8.
Modify each resource file appropriately with translated versions of each resource. Make sure each resource file’s access modifier is public.

9.
Wrap the Visual Studio-generated wrapper class in another class:

//for Silverlight to be able to bind to resources, we need to wrap
//them in another class
public class LocResources
{
    public LocResources()
    {    }
    private static LocSilverlight.Resources resource = new Resources();
    public LocSilverlight.Resources Resource
    { get { return resource; }  }
}

10.
Add a reference to the wrapper class to the Application.Resources section of App.xaml:

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/
                     presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:LocSilverlight"
             x:Class="LocSilverlight.App">
    <Application.Resources>
        <local:LocResources x:Key="LocResources"/>
    </Application.Resources>
</Application>

11.
Bind UI elements to the resources:

<UserControl x:Class="LocSilverlight.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"
    mc:Ignorable="d"
    d:DesignHeight="220" d:DesignWidth="243" >
    <Grid x:Name="LayoutRoot" Background="White"
          Height="181" Width="183">
        <dataInput:Label Name="labelMessage"
                         Height="50"
                         Width="100"
                         Margin="12,12,0,0"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Top"
                         Content="{Binding Path=Resource.Message,
								Source={StaticResource
								LocResources}}"/>
        <Button Name="button1"
                Height="23"
                Width="75"
                Margin="37,76,0,0"
                HorizontalAlignment="Left"
                VerticalAlignment="Top"
                Content="{Binding Path=Resource.buttonExit,
								Source={StaticResource
								LocResources}}"/>
    </Grid>
</UserControl>

					  

12.
Test the application in different languages by editing the HTML or ASPX file in the accompanying web project with the following lines in the <object> tag:

<object ...>
  ...
  <param name="culture" value="it-it" />
  <param name="uiculture" value="it-it" />
  ...
</object>

Note

Make sure you run the web project, not the Silverlight project, so you can use your edited HTML/ASPX file. Otherwise, Visual Studio will generate one for you, and it won’t have the culture tags.

Other  
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Video Sports
programming4us programming4us
programming4us
 
 
programming4us