Building Localized XAP Resource Files For Silverlight 4

The steps for localizing Silverlight applications using standard .resx files are relatively straight forwards. You can follow these steps on my "Internationalizing Silverlight" slides and see a completed demo in the downloadable source code for the same presentation (see the Localization101 folder). The main problem to resolve in this scenario is that the strongly typed resource class must be public and must have a public constructor. The solution to this problem lies in a previous blog post. This blog post discusses the next stage.

Silverlight faces the same deployment problem that ClickOnce applications face: if you follow the regular localization route then your deployment solution includes all languages for all users. Purely for performance reasons this is not desirable. The optimum solution is to provide the user with only the resources for the one required language. There is no built-in solution in Visual Studio 2010 that covers this scenario - that is what this blog post is about.

The solution is to build one XAP file with the Silverlight application and fallback resources (e.g. SilverlightApplication1.xap) and a separate XAP containing language-specific satellite resource assemblies for each deployed culture (e.g. SilverlightApplication1.fr-FR.xap, SilverlightApplication.es-ES.xap). At runtime the Silverlight application dynamically loads the required XAP resource file. In earlier versions of Silverlight this was possible using WebClient to download the XAP file and AssemblyPart.Load to load the satellite resource assembly into the Silverlight application's domain. This is still possible but MEF (Managed Extensibility Framework) provides a much neater solution (MEF, however, performs almost exactly the same steps as the original solution). To load and use the XAP resource file change the App.Application_Startup event in App.xaml.cs to:-

private void Application_Startup(object sender, StartupEventArgs e)
{
    string xapResourceFilename = String.Format("{0}.{1}.xap",
        "SilverlightApplication1",
        Thread.CurrentThread.CurrentUICulture.Name);

    DeploymentCatalog catalog = new DeploymentCatalog(
        new Uri(xapResourceFilename, UriKind.Relative));

    CompositionHost.Initialize(catalog);

    catalog.DownloadCompleted += (s, args) =>
    {
        this.RootVisual = new MainPage();
    };

    catalog.DownloadAsync();
}

This code uses MEF's DeploymentCatalog to load the XAP resource file (e.g. SilverlightApplication1.fr-FR.xap) containing the application's satellite resource assembly (e.g. SilverlightApplication1.resources.dll). The new MainPage is only created once the download is complete (or has failed). At this point the satellite resource assembly has been loaded into the Silverlight application's app domain and the regular ResourceManager (or whatever resource manager class you use) can get to work resolving the resources. You can see a completed demo in the downloadable source code (see the DownloadOnDemand folder).

The hardest part to solve in this process is the creation of the XAP resource files (e.g. SilverlightApplication1.fr-FR.dll). There is no support for this scenario in Visual Studio 2010 so you have to build this bit yourself. Or rather, you have to download the MSBuild tasks that I have created to solve this problem. Silverlight.Build.Tasks.zip contains the source code to build a library of MSBuild tasks (Silverlight.Build.Tasks.dll) and an MSBuild targets file (Silverlight.Build.Tasks.targets) that you add to your Silverlight application's .csproj file. Full details are in the solution's ReadMe.txt but in essence you add the following lines to the bottom of your .csproj file:-

<Import Project="$(ProgramFiles)\MSBuild\I18N\Silverlight\v4.0\Silverlight.Build.Tasks.targets" />

<Target Name="AfterBuild" DependsOnTargets="XapResourcePackager">
</Target>

Then you add the following line immediately below your .csproj's </SupportedCultures> line:-

<PackageCultures>fr-FR</PackageCultures>

(where <PackageCultures> contains a comma delimited list of cultures to create XAP resource files for).

The result is that when you build your Silverlight application the necessary XAP resource files are also built. If your Silverlight application has a corresponding website that hosts the Silverlight application then those XAP files are copied to the website's ClientBin folder just like the Silverlight application's XAP. You can see a completed demo in the downloadable source code (see the DownloadOnDemandAutomatedBuild folder).

Of course this only covers one Silverlight deployment scenario but it is common enough that it demands a solution.

Enjoy.

Currently rated 3.4 by 13 people

  • Currently 3.384615/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: GuySmithFerrier
Posted on: Sunday, October 10, 2010 at 10:25 PM
Categories: Internationalization | Silverlight
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (4) | Post RSSRSS comment feed

TechEd Europe: How To Make Your Silverlight 4 Application World Ready

Going to TechEd Europe 2010 in Berlin ? Come and see my session (WEB307) How To Make your Silverlight 4 Application World Ready. This is the same session I'm doing at the 34th Internationalization and Unicode Conference (#IUC34, where it is called How To Achieve World-Ready Domination In Silverlight 4) and I did last night at the Silverlight UK User Group (where it was called Internationalizing Silverlight 4). Here's the abstract:-

So you've written your Silverlight application and you want it to work in another language ? Then this session is for you. World-Readiness is all of the work that a developer needs to do to globalize an application and make it localizable (i.e. capable of being localized). Whereas these concepts are well established in Windows Forms and ASP.NET, Silverlight is not only a cut-down version of the .NET Framework but also cross platform and client-side. In this session you will learn how to localize Silverlight applications using .resx files, download culture-specific resources on demand so that users only download resources for the culture they need, understand what System.Globalization types and properties Silverlight does not support and why, what globalization and font support you can expect on Windows and the Mac, what the Silverlight installation user experience is for non-English users and what language support you can expect from the Silverlight framework.

Currently rated 1.8 by 4 people

  • Currently 1.75/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Thursday, September 16, 2010 at 5:35 PM
Tags:
Categories: Internationalization | Silverlight | Events
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Internationalizing Silverlight 4 Slides and Source Code

Thanks to everyone who came to the Internationalizing Silverlight 4 presentation at the Silverlight UK User Group last night. A particularly huge thanks to Mark Mann who provided a personalised and internationalized introduction to me. Never had something like this before and I was very impressed and touched. Best introduction ever.

Excellent chat in the pub afterwards too. Really enjoyed it ? thanks everyone.

The slides for the presentation are available at http://www.guysmithferrier.com/Downloads/I18NSilverlight.zip. The source code is at http://www.guysmithferrier.com/Downloads/I18NSilverlightSource.zip.

Ian Smith took a video of the presentation which will be posted soon.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Thursday, September 16, 2010 at 10:51 AM
Tags:
Categories: Internationalization | Silverlight | Events
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

Silverlight Globalization Namespace Comparison Updated For Silverlight 4

When Silverlight 2 was released I wrote a short document comparing the classes in the Silverlight System.Globalization namespace with those of the .NET Framework's same namespace. Last year I updated it for Silverlight 3 and now I have done the same again for Silverlight 4. Before you get too excited, however, the System.Globalization classes and their methods and properties in Silverlight 4 have not changed since Silverlight 3. That is not to say that there aren't internationalization changes in Silverlight 4 (right-to-left support being a very welcome addition), just that the classes themselves have not changed (not even to include TextInfo.IsRightToLeft). You can download the document here.

Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Thursday, September 09, 2010 at 3:42 PM
Tags:
Categories: Silverlight | Internationalization
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

PublicResourceCodeGenerator now works with Visual Studio 2010

I have updated the PublicResourceCodeGenerator (and all of the other code generators) so that it installs and works with Visual Studio 2010 (as well as Visual Studio 2008). The PublicResourceCodeGenerator is used to create Strongly Typed Resource Classes with a public class and a public constructor so that resx files can be used with Silverlight (you can read all about these code generators here). You can download an MSI/EXE and/or the source code (for Visual Studio 2010, 2008 and 2005) here.

Currently rated 4.3 by 3 people

  • Currently 4.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Wednesday, September 01, 2010 at 6:30 PM
Tags:
Categories: Internationalization | .NET Internationalization Book | Silverlight
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

Internationalizing Silverlight 4

I will be presenting a Silverlight 4 version of my Internationalizing Silverlight presentation twice in the coming months. The first is at the Silverlight User Group in London on Wednesday 15th September 2010 and the second is at the 34th Internationalization and Unicode Conference (where it is entitled "How To Achieve World(-Ready) Domination In Silverlight 4") in Santa Clara, California from Monday 18th October to Wednesday 20th October 2010. Typically I present internationalization subjects to developers and the consequence is that there is sometimes some groundwork that needs to be covered for the subject to make sense. Each of these upcoming events approaches this subject from a different viewpoint: the Silverlight User Group members know Silverlight very well and therefore will be solely focused on internationalization and the Internationalization and Unicode Conference attendees know internationalization very well and will be focused solely on Silverlight. I'm looking forward to the different perspectives. Here's the abstract:-

So you've written your Silverlight application and you want it to work in another language ? Then this session is for you. World-Readiness is all of the work that a developer needs to do to globalize an application and make it localizable (i.e. capable of being localized). Whereas these concepts are well established in Windows Forms and ASP.NET, Silverlight is not only a cut-down version of the .NET Framework but also cross platform and client-side. In this session you will learn how to localize Silverlight applications using .resx files, download culture-specific resources on demand so that users only download resources for the culture they need, understand what System.Globalization types and properties Silverlight does not support and why, what globalization and font support you can expect on Windows and the Mac, what the Silverlight installation user experience is for non-English users and what language support you can expect from the Silverlight framework.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Wednesday, July 28, 2010 at 10:37 AM
Tags:
Categories: Silverlight | Internationalization
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (2) | Post RSSRSS comment feed

Jesse Liberty Tour of the UK and Ireland (#techdays)

Jesse Liberty, Silverlight Geek (Microsoft US Developer Evangelist for Silverlight), is doing a tour of the UK and Ireland in April to coincide with Microsoft UK's week of TechDays (#techdays) events. Jesse is speaking at Bristol, London, Cambridge, Leeds, Newcastle, Edinburgh, Glasgow, Belfast and Dublin between Monday 12th April 2010 and Friday 23rd April 2010. You can match the dates to the venues at Jesse's post. Jesse's first stop on the tour is at The .NET Developer Network on Monday 12th April 2010 where we will also be celebrating our third birthday (with cake!). Jesse will be presenting:-

  • Silverlight 4, MVVM and TDD: A Brave New World (level 300)
    1.       MVVM and Silverlight to build test-driven programs
    2.       Understanding Refactoring and Dependency Injection
    3.       A Walk through of a non-trivial application
You can sign up for this one here. Thanks to Microsoft (US, UK, ROI) and UGSS for sponsoring this tour and making it possible

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Monday, February 15, 2010 at 10:10 PM
Tags:
Categories: Events | Silverlight | The .NET Developer Network
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

LRC XIV: Localisation in The Cloud

The 14th annual LRC (Localisation Research Centre) conference will be held on Thursday/Friday 24th and 25th September 2009 in Limerick City, Ireland. I will be there presenting a poster. This is a new kind of presentation for me; the idea is to stand in a communal area during the break for lunch next to an A0 poster that you have prepared and be prepared to chat to anyone who is interested. It seems a bit like the Ask The Experts format but with better focus. If it works I might try it at dev events in the UK. My poster is on Internationalizing Silverlight and is based on the presentation that I have started giving this year. All in all I'm very excited about LRC as it will be a rare treat for me to be at a conference that is solely on localization and everyone there is guaranteed to be interested in the subject.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Tuesday, September 08, 2009 at 9:12 AM
Tags:
Categories: Internationalization | Events | Silverlight
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

Internationalizing Silverlight Slides And Source Code

Thanks to everyone who came to the Internationalizing Silverlight (aka How To Achieve World-Ready Domination In Silverlight) talk at NxtGen Southampton on Thursday. The slides are at http://www.guysmithferrier.com/Downloads/I18NSilverlight.pptx and the source code for the completed demos are at http://www.guysmithferrier.com/Downloads/I18NSilverlightSource.zip. Note that the font I was using is not included in the download as the licence prevents redistribution but you can substitute an alternative font.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Saturday, June 20, 2009 at 11:51 AM
Tags:
Categories: Silverlight | Internationalization | Events
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

NxtGen: How To Achieve World(-Ready) Domination In Silverlight

In a long overdue first return to the Southampton chapter of The Next Generation User Group I will be giving the following presentation on internationalizing Silverlight on Thursday 18th June 2009:-

  • How To Achieve World(-Ready) Domination In Silverlight
    So you've written your Silverlight application and you want it to work in another language ? Then this session is for you. World-Readiness is all of the work that a developer needs to do to globalize an application and make it localizable (i.e. capable of being localized). Whereas these concepts are well established in Windows Forms and ASP.NET, Silverlight is not only a cut-down version of the .NET Framework but also cross platform and client-side. In this session you will learn how to localize Silverlight applications using .resx files, download culture-specific resources on demand so that users only download resources for the culture they need, understand what System.Globalization types and properties Silverlight does not support and why, what CultureInfo and RegionInfo support you can expect on different operating systems, what the Silverlight installation user experience is for non-English users and what language support you can expect from the Silverlight framework.
Full details are available here. See you there.

Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: guysmithferrier
Posted on: Wednesday, April 01, 2009 at 7:52 PM
Tags:
Categories: Silverlight | Events | Internationalization
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed