Introduction:
In this article,i am going to explain about how to localize a silverlight application.Localized resources in Silverlight are very similar to the resource file methods just
given.
Main:
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
want. For example:
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; } }
}
//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>
<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 ...>
...
<param name=”culture” value=”it-it” />
<param name=”uiculture” value=”it-it” />
...
</object>
<object ...> ... <param name=”culture” value=”it-it” /> <param name=”uiculture” value=”it-it” /> ... </object> |
Conclusion:
Hope this helps,
Happy Coding.
Whats happening, I discovered this blog by error when I was browsing Bing ,next I arrived to your web site. I need to say your site is interesting I really like your theme! Today I don’t have the free time at the current moment to fully browse your sitebut I have bookmarked it. I will be back in a day or two. Thanks for a good site.
What a great resource!
Hi – I wanted to say thank you for an cool site about a subject I have had an interest in for a long time now. I have been lurking and reading the comments avidly so just wanted to express my thanks for providing me with some very good information. I look forward to more, and taking a more proactive part in the discussions here, whilst picking up some knowledge too!!
Have found your web page. My pal mentioned it to me before, yet never got around to checking it out until now. I must express, I’m floored. I really enjoyed reading through your posts and will absolutely be back to get more.
Hi there, I found your blog via Google while searching for first aid for a heart attack and your post looks very interesting for me.
I believe you might like what I came across on this internet site today.
I have been looking for these, and now find, thank you.
Book marked the sites. Appreciate discussing. Absolutely value enough time from my tests.
you look like a million dollars.you lood outstanding.
The new Zune browser is surprisingly good, but not as good as the iPod’s. It works well, but isn’t as fast as Safari, and has a clunkier interface. If you occasionally plan on using the web browser that’s not an issue, but if you’re planning to browse the web alot from your PMP then the iPod’s larger screen and better browser may be important.