1 / 37

WEB307: How To Make your Silverlight 4 Application World Ready

WEB307: How To Make your Silverlight 4 Application World Ready. Guy Smith-Ferrier Technical Architect Email: guy@guysmithferrier.com Twitter: @ GuySmithFerrier Blog: http://www.guysmithferrier.com. Agenda. Localizing Silverlight U sing . resx F iles

chi
Download Presentation

WEB307: How To Make your Silverlight 4 Application World Ready

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WEB307: How To Make your Silverlight 4 Application World Ready Guy Smith-Ferrier Technical Architect Email: guy@guysmithferrier.com Twitter: @GuySmithFerrier Blog: http://www.guysmithferrier.com

  2. Agenda • Localizing Silverlight Using .resxFiles • Downloading Localized Resources On Demand • Silverlight Installation User Experience • Silverlight UI Localization • Silverlight Fonts and Font Management • Silverlight Globalization

  3. Localizing Silverlight Using .resx Files SilverlightApplication1.sln SilverlightApplication1.xap SilverlightApplication1.csproj AppManifest.xaml MainPage.xaml SilverlightApplication1.dll MainPageResources.resx fr-FR/SilverlightApplication1. resources.dll MainPageResources.fr-FR.resx

  4. Localizing Silverlight Using .resx Files demo

  5. Solutions To The Internal Constructor • 1. Use a different Strongly Typed Resource Class code generator • PublicResourceCodeGenerator • http://www.dotneti18n.com/Downloads/ResourceProviderCodeGenerators.zip • ResXFileCodeGeneratorEx • http://dmytro.kryvko.googlepages.com • Visual Studio 2005 & 2008 only (Source code available)

  6. Solutions To The Internal Constructor (continued) • 2. Write a wrapper for the Strongly Typed Resource Class and bind to the wrapper public class PublicMainPageResources { private static MainPageResources resources = new MainPageResources(); public MainPageResourcesMainPageResources { get { return resources; } } } <UserControl.Resources> <Resources:PublicMainPageResources x:Name="MainPageResources"/> </UserControl.Resources> <Button Content="{Binding MainPageResources.Button_1, Source={StaticResourceMainPageResources}}"/>

  7. Download On Demand SilverlightApplication1.sln SilverlightApplication1.xap SilverlightApplication1.csproj AppManifest.xaml MainPage.xaml SilverlightApplication1.dll MainPageResources.resx SilverlightApplication1.fr-FR.xap AppManifest.xaml MainPageResources.fr-FR.resx fr-FR/SilverlightApplication1. resources.dll

  8. Download On DemandCreating The Resource XAP File Manually • Copy bin\debug\AppManifest.xaml to bin\debug\fr-FR • Ensure that the only AssemblyPart is:- • Create a ZIP file, SilverlightApplication1.fr-FR.zip, containing:- • AppManifest.xaml with no path information • SilverlightApplication1.resources.dll with fr-FR path • Rename SilverlightApplication1.fr-FR.zip to SilverlightApplication1.fr-FR.xap • Copy SilverlightApplication1.fr-FR.xap to SilverlightApplication1.Web\ClientBin <AssemblyPart Source= "fr-FR/SilverlightApplication1.resources.dll" />

  9. Download On DemandCreating The Resource Xap File Automatically • Download http://www.guysmithferrier.com/ Downloads/Silverlight.Build.Tasks.zip • Add the following lines to the bottom of SilverlightApplication1.csproj:- • In SilverlightApplication1.csproj add the following line beneath </SupportedCultures>:- <Import Project="$(ProgramFiles)\ MSBuild\I18N\Silverlight\v4.0\Silverlight.Build.Tasks.targets" /> <Target Name="AfterBuild" DependsOnTargets="XapResourcePackager"> </Target> <PackageCultures>fr-FR</PackageCultures>

  10. Download On DemandChanging The Silverlight Application • Empty the SupportedCultures in the .csproj file • Add the following reference to the Silverlight application:- • System.ComponentModel.Composition • System.ComponentModel.Composition.Initialization <SupportedCultures></SupportedCultures>

  11. Download On DemandChanging The Silverlight Application • Change the Application_Startup event to:- private void Application_Startup(object sender, StartupEventArgs e) { string xapResourceFilename = String.Format("{0}.{1}.xap", "SilverlightApplication1", Thread.CurrentThread.CurrentUICulture.Name); DeploymentCatalogcatalog = new DeploymentCatalog( new Uri(xapResourceFilename, UriKind.Relative)); CompositionHost.Initialize(catalog); catalog.DownloadCompleted += (s, args) => { this.RootVisual = new MainPage(); }; catalog.DownloadAsync(); }

  12. Download On Demand demo

  13. Silverlight Installation User Experience • The Silverlight install image is retrieved from http://go.microsoft.com/fwlink/?LinkId=161376 • This reads the browser's HTTP accept language setting and returns an image for that culture

  14. Silverlight Installation User Experience (continued) • The Silverlight add-in is installed using a Windows application • The Windows application uses the operating system's culture (e.g. en-US) to determine the localized resources to display • If you set your browser's language to a different language to your operating you will see a schizophrenic installation experience

  15. Silverlight Runtime Culture Support • Silverlight is a single runtime that includes all 40 supported languages:-

  16. Silverlight Configuration Dialog • The Config dialog's UI is dictated by the operating system (only) • Defaults to English

  17. Silverlight Message & File Dialogs(MessageBox, OpenFileDialog, SaveFileDialog) • These dialogs' UIs are dictated by the operating system (only)

  18. Silverlight Globalized Controls • The DatePicker and Calendar controls respect the Thread.CurrentCulture setting en-GB fr-FR nb-NO ja-JP

  19. Localization And Globalization Sources Summary

  20. Silverlight 'Web Safe' Fonts • Silverlight supports 10 'web-safe' fonts on all platforms • (assuming the fonts have not been uninstalled)

  21. Font Linking and Font Fallback • Silverlight has no 'built-in' fonts • All fonts are supplied by the operating system • The OS uses Font Linking and Font Fallback to find the best match for unknown glyphs • Lucida Sans Unicode on Windows Vista Ultimate • Lucida Sans Unicode on Windows XP SP2 (East Asian support not installed)

  22. Silverlight Default Font • Silverlight uses the "Portable User Interface" font by default • The "Portable User Interface" font is an alias for Lucida Grande

  23. Using Embedded Fonts demo

  24. Using Streamed Fonts demo

  25. Font Subsetting • Open a Silverlight project in Blend • Add a font • Tools | Font Manager • Select Mongolian Baiti (349K) • Check the "Auto fill" checkbox • Add a TextBlock, set the Font Family to the new font and set the Content to "Hello World" • Build the project

  26. Font Subsetting (continued) • Open the subsetted font (obj\Debug\Fonts\monbaiti0.subset.ttf, 101K)

  27. Font SubsettingMSBuild Tasks • When you add a Font to your project Blend adds the following line to the .csproj file:- • This .targets file includes the font subsetting task:- <Import Project="$(MSBuildExtensionsPath)\Microsoft\Expression\Blend\Silverlight\v4.0\Microsoft.Expression.Blend.Silverlight.targets" /> <UsingTaskAssemblyFile="SubsetFontTask.dll" TaskName="Microsoft.Expression.SubsetFontTask.SubsetFontsSilverlight" />

  28. Silverlight Globalization Namespace • Comparison between the .NET Framework and the Silverlight Framework:- • http://www.guysmithferrier.com/downloads/SilverlightGlobalizationClassComparison.pdf • No support for locale IDs (LCIDs) • No lunisolar calendars • No Windows-specific features • CultureInfo.ThreeLetterWindowsLanguageName • RegionInfo.GeoId • No code page support (Unicode only)

  29. Custom Cultures • The CultureAndRegionInfoBuilder class is not supported in Silverlight • Silverlightdoes read custom cultures if they are present on the client's operating system

  30. TextInfo.IsRightToLeft • There is no TextInfo.IsRightToLeft in Silverlight 4 namespace System.Globalization { static class TextInfoExtensions { public static bool IsRightToLeft(this TextInfotextInfo) { CultureInfocultureInfo = new CultureInfo(textInfo.CultureName); while (! (cultureInfo.IsNeutralCulture || cultureInfo.Parent == null)) { cultureInfo = cultureInfo.Parent; } return ( cultureInfo.Name == "ar" || // "Arabic" cultureInfo.Name == "dv" || // "Divehi" cultureInfo.Name == "fa" || // "Persian" cultureInfo.Name == "he" || // "Hebrew" cultureInfo.Name == "prs" || // "Dari" cultureInfo.Name == "ps" || // "Pashto" cultureInfo.Name == "syr" || // "Syriac" cultureInfo.Name == "ug" || // "Uyghur" cultureInfo.Name == "ur" // "Urdu" ); } } }

  31. Right To Left Support • Right to left behaviour is supported through the FrameworkElement.FlowDirection property • Values can be LeftToRight or RightToLeft • Elements inherit their FlowDirection from their container • Images never inherit their FlowDirection • To set the FlowDirection programmatically:- public MainPage() { InitializeComponent(); if ( Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft()) { this.FlowDirection = FlowDirection.RightToLeft; } }

  32. Other WPF I18N Features Not Available In Silverlight • Static markup extension is not supported • Silverlight'sMarkupExtension is not public • See "Differences Between WPF and Silverlight" • http://wpfslguidance.codeplex.com

  33. Silverlight On Windows vs. Silverlight On Mac OS X • Culture data varies across operating systems • Sort, casing and comparison results vary across operating systems

  34. Summary • Localization is possible through .resx files • Bind to the strongly typed resource classes • If you have more than one culture you should consider "download on demand" • Avoiding a schizophrenic user interface can be a challenge • Font support is dependent upon the operating system • Globalization support is dependent upon the operating system

  35. Session Evaluations Tell us what you think, and you could win! All evaluations submitted are automatically entered into a daily prize draw*  Sign-in to the Schedule Builder at http://europe.msteched.com/topic/list/ * Details of prize draw rules can be obtained from the Information Desk.

  36. © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

More Related