2 Internationalizing WPF And Silverlight Applications Guy Smith-Ferrier Technical Architect, Capella Software Ltd.

Slides:



Advertisements
Similar presentations
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Advertisements

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Identity Management - Login © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Feature: Reprint Outstanding Transactions Report © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Feature: Purchase Requisitions - Requester © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Feature: Payroll and HR Enhancements © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Interactivity Navigating a data model Working with large quantities of data Entry Editing and adding data User feedback and validation Presentation.
Co- location Mass Market Managed Hosting ISV Hosting.
Windows 7 Training Microsoft Confidential. Windows ® 7 Compatibility Version Checking.
Feature: Purchase Order Prepayments II © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: OLE Notes Migration Utility
Feature: Web Client Keyboard Shortcuts © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: SmartList Usability Enhancements © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Session 1.
travel Suru Windows 7 Release NET 4.0 / Surface 2.0 Release Multi-Touch Controls Multi-Touch API Surface Multi-Touch Controls & API Surface.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
 Rico Mariani Architect Microsoft Corporation.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Assign an Item to Multiple Sites © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Print Remaining Documents © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
NEXT: Overview – Sharing skills & code.
demo Receive Inventory Export Parse and Normalize.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Document Attachment –Replace OLE Notes © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Feature: Suggested Item Enhancements – Sales Script and Additional Information © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: Employee Self Service Timecard Entry © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.

customer.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
demo Demo.
Feature: Void Historical/Open Transaction Updates © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
Feature: Suggested Item Enhancements – Analysis and Assignment © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and.
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
The CLR CoreCLRCoreCLR © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.

demo User Signs Up Temporary Account is Created with Verification Link Sent User Clicks Link Account is Activated Login.Register(userName,
Building world-ready Metro style apps with XAML
Services Course 9/9/2018 3:37 PM Services Course Windows Live SkyDrive Participant Guide © 2008 Microsoft Corporation. All rights reserved.
9/11/ :22 PM What’s New for Silverlight and Windows Presentation Foundation (WPF) Developers in Microsoft Visual Studio 2010 Mark A Wilson-Thomas.
Возможности Excel 2010, о которых следует знать
Introduction to mobile app development Module 3 – Improving your App Studio app Lance McCarthy.
Title of Presentation 11/22/2018 3:34 PM
Integrating Security Roles into Microsoft Silverlight Applications
Title of Presentation 12/2/2018 3:48 PM
Brian Keller Sr. Technical Evangelist Microsoft Session Code: DEV310
Brian Keller Sr. Technical Evangelist Microsoft Session Code: DEV310
Visual Studio 2010 SharePoint Development Tools Overview
Create rich, data-driven Web apps with ASP.NET 4.5 Web Forms
Silverlight Debugging
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
PENSACOLA ENERGY WORK PLAN OCTOBER 10, 2016
Title of Presentation 5/12/ :53 PM
Шитманов Дархан Қаражанұлы Тарих пәнінің
Title of Presentation 5/24/2019 1:26 PM
日本初公開!? Vista の新機能を実演 とっちゃん わんくま同盟 7/23/2019 9:09 AM
Title of Presentation 7/24/2019 8:53 PM
Presentation transcript:

2 Internationalizing WPF And Silverlight Applications Guy Smith-Ferrier Technical Architect, Capella Software Ltd.

3 About… Author of.NET Internationalization – Visit to download the complete source code The.NET Developer Network – – Free user group for.NET developers, architects and IT Pros based in Bristol

4 Agenda Localizing WPF using.resx files Localizing WPF using LocBaml Localizing WPF using LocBaml and a ResourceDictionary Localizing Silverlight using.resx files

5 Localizing WPF Using.resx Files

6 Using Visual Studio 2008 create a new WPF application Add a button Add a Resources File (In Solution Explorer, right click WpfApplication1, select Add | New Item, select Resources File) and call it Window1Resources.resx – Add a new resource entry called "Button_1" with a value of "Hello World" – Set the Access Modifier to Public (using the combo box)

7 In Window1.xaml add a "Resources" namespace and change the button's Content to use a static resource <Window x:Class="WpfApplication1.Window1" xmlns=" xmlns=" xmlns:x=" xmlns:x=" xmlns:Resources="clr-namespace:WpfApplication1" xmlns:Resources="clr-namespace:WpfApplication1" Title="Window1" Height="300" Width="300"> Title="Window1" Height="300" Width="300"> </Window> Localizing WPF Using.resx Files (continued)

8 In Visual Studio copy Window1Resources.resx to Window1Resources.fr-FR.resx – Change the "Button_1" resource value to "Bonjour Le Monde" In App.xaml.cs add a constructor to set the CurrentUICulture public App() { Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture;} Localizing WPF Using.resx Files (continued)

9 Pros:- – Good tool support for.resx files – Resource granularity is at the resource entry level Cons:- – Binding to properties requires XAML to be changed – Binding can only be applied to dependency properties (in XAML) Localizing WPF Using.resx Files Pros And Cons

10 LocBaml LocBaml is a sample tool for localizing BAML – “The LocBaml tool is not a production-ready application. It is presented as a sample that uses some of the localization APIs and illustrates how you might write a localization tool.” Download from us/library/ms aspxhttp://msdn.microsoft.com/en- us/library/ms aspx – Unzip the download to a folder – Open Visual Studio and build the project LocBaml is a wrapper around the BamlLocalizer class

11 Localizing WPF Using LocBaml

12 Localizing WPF Using LocBaml Using Visual Studio 2008 create a new WPF application Add a button Open WpfApplication1.csproj using NotePad and add a UICulture element to the first PropertyGroup <UICulture>en-GB</UICulture>

13 Open AssemblyInfo.cs, uncomment the Neutral ResourcesLanguage attribute and set the culture In App.xaml.cs add a constructor to set the CurrentUICulture [assembly: NeutralResourcesLanguage("en-GB", UltimateResourceFallbackLocation.Satellite)] UltimateResourceFallbackLocation.Satellite)] Localizing WPF Using LocBaml (continued) public App() { Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture;}

14 Open a command prompt in the WpfApplication1 folder and execute this line:- In Visual Studio answer "Yes To All" to reload the changed files Compile the application msbuild /t:updateuid WpfApplication1.csproj Localizing WPF Using LocBaml (continued)

15 In the command prompt change to the bin\Debug folder Copy LocBaml.exe from the LocBaml folder to the current folder and execute this line:- In Windows Explorer double click on the new fr-FR.csv file to load Excel locbaml /parse en-GB/WpfApplication1.resources.dll /out:fr-FR.csv Localizing WPF Using LocBaml (continued)

16 Change "Hello World" to "Bonjour Le Monde" File | Save As, set "Save as type" to "CSV (Comma delimited)" Make a directory beneath bin\Debug called "fr-FR" In the command prompt execute this line:- LocBaml.exe /generate en-GB/WpfLocBaml1.resources.dll /trans:fr-FR.csv /out:fr-FR /culture:fr-FR Localizing WPF Using LocBaml (continued)

17 LocBaml CSV Columns ColumnDescription BAML NameThe name of the BAML resource stream Resource KeyThe resource entry identifier Localization CategoryThe category ReadableShould the resource be visible to the localizer ModifiableShould the resource be modifiable by the localizer Localization CommentsComments from the developer to the localizer ValueThe value of the resource entry

18 Localization Comments Localization comments are added to the XAML <Button x:Uid="Button_1" Content="Hello World" Content="Hello World" ToolTip="Click to see the world" ToolTip="Click to see the world" Localization.Comments="$Content (The text shown in the button) Localization.Comments="$Content (The text shown in the button) $ToolTip (The text shown over the button)"/> $ToolTip (The text shown over the button)"/>

19 Localization comments can be extracted/included by adding a LocalizationDirectivesToLocFile to the.csproj Comments can be extracted to a separate file <LocalizationDirectivesToLocFile>All</LocalizationDirectivesToLocFile> Localization Comments (continued) <LocalizableAssembly> </LocalizableFile></LocalizableAssembly>

20 LocBaml Equivalents For ASP.NET Developers ASP.NETLocBaml Generate tags in source codeTools | Generate Local Resources msbuild /t:updateuid locbaml /parse Tag Identifiermeta:resourcekeyx:Uid Source Of Localized Resources.resx file.csv file Build Satellite AssembliesBuild (in Visual Studio)locbaml /generate 'Prevent' Localizationmeta:localizeLocalization.Attributes

21 Pros:- – Localization can be performed without the original source – Localization does not need to be part of the development process – Binding to properties requires no change to the XAML – Bind to any property Cons:- – Poor tool support – Resource granularity is at the BAML resource level – No effective resource fallback – LocBaml overwrites existing CSV files – LocBaml does not sign generated assemblies – LocBaml fails to generate correct CSV files when resources contain commas Localizing WPF Using LocBaml Pros And Cons

22 In Visual Studio select Tools | External Tools…, click Add – Set Title to "msbuild /t:updateuid" – Set Command to"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe" – Set Arguments to "/t:updateuid $(ProjectFileName)" – Set Initial directory to "$(ProjectDir)" – Check "Use Output window" – Click OK Integrating LocBaml With Visual Studio Integrating "msbuild /t:updateuid"

23 In Visual Studio select Tools | External Tools…, click Add – Set Title to "locbaml /parse" – Set Command to"c:\CS35Tests\WpfApplication1\bin\debug\locbaml.exe" – Set Arguments to "/parse en-GB/$(TargetName).resources.dll /out:fr-FR.csv" – Set Initial directory to "$(BinDir)" – Check "Use Output window" – Click OK Integrating LocBaml With Visual Studio Integrating "locbaml /parse"

24 In Visual Studio select Tools | External Tools…, click Add – Set Title to "locbaml /generate" – Set Command to"c:\CS35Tests\WpfApplication1\bin\debug\locbaml.exe" – Set Arguments to " /generate en- GB/$(TargetName).resources.dll /trans:fr-FR.csv /culture:fr-FR /out:fr-FR " – Set Initial directory to "$(BinDir)" – Check "Use Output window" – Click OK Integrating LocBaml With Visual Studio Integrating "locbaml /generate"

25 Localizing WPF Using LocBaml And Resource Dictionaries

26 Localizing Using LocBaml And Dictionaries Add a resource dictionary called Window1Resources Add the dictionary to Window1.xaml:- <ResourceDictionary xmlns=" xmlns=" xmlns:x=" xmlns:x=" xmlns:system="clr-namespace:System;assembly=mscorlib"> xmlns:system="clr-namespace:System;assembly=mscorlib"> Hello Hello </ResourceDictionary> <Window.Resources> </Window.Resources>

27 Add a click event to the button to show the resource Follow the previous steps to add uids, parse out the resources, modify the CSV and rebuild the assembly MessageBox.Show(this.FindResource("Button_1Message").ToString()); Localizing Using LocBaml And Dictionaries (continued)

28 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 Window1() { InitializeComponent(); InitializeComponent(); if (Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft) if (Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft) { Window.SetFlowDirection(this, FlowDirection.RightToLeft); Window.SetFlowDirection(this, FlowDirection.RightToLeft); }}

29 Localizing Silverlight Using.resx Files

30 Localizing Silverlight Using.resx Files Using Visual Studio 2008 create a new Silverlight app Add a button Add a Resources File (In Solution Explorer, right click WpfApplication1, select Add | New Item, select Resources File) and call it PageResources.resx – Add a new resource entry called "Button_1" with a value of "Hello World" – Set the Access Modifier to Public (using the combo box) – Change the constructor to public in PageResources.Designer.cs

31 In Page.xaml add a "Resources" namespace, a static resource and change the button to use a static resource <UserControl x:Class="SilverlightApplication1.Page" xmlns=" xmlns=" xmlns:x=" xmlns:x=" xmlns:Resources="clr-namespace:SilverlightApplication1" xmlns:Resources="clr-namespace:SilverlightApplication1" Width="400" Height="300"> Width="400" Height="300"> </UserControl> Localizing Silverlight Using.resx Files (continued)

32 In Visual Studio copy PageResources.resx to PageResources.fr-FR.resx – Change the "Button_1" resource value to "Bonjour Le Monde" Open SilverlightApplication1.csproj using NotePad, locate the SupportedCultures element and set it to fr-FR <SupportedCultures>fr-FR</SupportedCultures> Localizing Silverlight Using.resx Files (continued)

33 Open SilverlightApplication1TestPage.aspx and add InitParameters to the Silverlight control Localizing Silverlight Using.resx Files (continued)

34 In App.xaml.cs change the Application_Startup method Run the application Localizing Silverlight Using.resx Files (continued) private void Application_Startup(object sender, StartupEventArgs e) { string cultureName = e.InitParams["UICulture"].ToString(); string cultureName = e.InitParams["UICulture"].ToString(); if (! String.IsNullOrEmpty(cultureName)) if (! String.IsNullOrEmpty(cultureName)) Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName); Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName); this.RootVisual = new Page(); this.RootVisual = new Page();}

35 WPF I18N Features Not Available In Silverlight Static markup extension is not supported FrameworkElement.FlowDirection is not supported Custom cultures and Windows-only cultures are supported – The cultures must exist on the client (not the server) – CultureAndRegionInfoBuilder not supported Numerous properties and methods missing from System.Globalization classes (CultureInfo, RegionInfo, TextInfo etc.)

36 Summary There is no 'one true path' for localizing WPF/Silverlight The choices are:- –.resx files – XAML (LocBaml) – custom solution Tool support for post-build localization (i.e. LocBaml) will improve There is no resource provider model in WPF/Silverlight Globalization support in WPF is excellent

37

38 Resources Tech·TalksTech·Ed Bloggers Live SimulcastsVirtual Labs ??? Developer’s Kit, Licenses, and MORE!

Breakout Sessions (session codes and titles) Interactive Theater Sessions (session codes and titles) Hands-on Labs (session codes and titles) Related Content

Track Resources Resource 1 Resource 2 Resource 3 Resource 4

41 © 2008 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.