1 / 58

WEB326 ASP.NET 2.0: Going Global Gets Easier! New Localization Features in ASP.NET 2.0

WEB326 ASP.NET 2.0: Going Global Gets Easier! New Localization Features in ASP.NET 2.0 . Michele Leroux Bustamante Architect, IDesign Microsoft Regional Director. Michele Leroux Bustamante. IDesign Inc., www.idesign.net Microsoft Regional Director Microsoft MVP – XML Web Services

panthea
Download Presentation

WEB326 ASP.NET 2.0: Going Global Gets Easier! New Localization Features in ASP.NET 2.0

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. WEB326ASP.NET 2.0: Going Global Gets Easier! New Localization Features in ASP.NET 2.0 Michele Leroux Bustamante Architect, IDesign Microsoft Regional Director

  2. Michele Leroux Bustamante • IDesign Inc., www.idesign.net • Microsoft Regional Director • Microsoft MVP – XML Web Services • Published in MSDN, CoDe, more… • International Speaker, INETA • BEA Technical Director • Events Director, IASA • Program Advisor, UCSD • Web Services Track Chair, SD Expo • Blogs: www.dasblonde.net, www.interopwarriors.com

  3. Agenda • Localization and the Web • New Localization Features in 2.0 • Generating Local Resources • Localization Expressions • Global Resources and Type Safety • Runtime Culture Selection • ASP.NET Architecture

  4. What Is Globalization? • Designing applications to be adapted to the global marketplace • Display, input, formats & conventions • Localizability • Separate culture dependencies from code • Localization • Adapting applications for specific markets • Content translation, feature customization • Changes independent of compiled source

  5. Locale/Culture • Language and cultural environment • International Standards Organization (ISO) Conventions • Language Code: ISO 639-1 (i.e., en, fr, es) • Country Code: ISO 3166 (i.e., CA, EC) • Together, they identify culture (i.e., es-EC) • See RFC 3066 – Tags for identifying languages • Custom cultures are sometimes necessary

  6. What To Localize? • Static (hard-coded) application content • Menu/control captions, Web content, XML • Dynamic application content • Database, XML, other • Graphical content • Filenames, connection strings, queries

  7. Storing Localized Content • Deployment architecture is affected by location of localized application content • Resources, file system, database,external applications • Choices influenced by application type • Microsoft Windows versus Web • And by business requirements • Frequency of culture translations • Ease of translation process • Frequency of application maintenance

  8. Duplicate Site Content Web Application Resources GlobalWeb \bin GlobalWeb.dll Global.asax Web.config page and user control content Database Content logo.gif Products

  9. Duplicate Site Content Web Application Resources GlobalWeb \bin GlobalWeb.dll Global.asax Web.config translated page and user control content page and user control content \en-CA Database Content logo.gif logo.en-CA.gif \es logo.es.gif Products Products_en-CA Products_es

  10. Single Content Base Web Application Resources Satellite Assemblies GlobalWeb \bin \en GlobalWeb.en.dll GlobalWeb.dll Global.asax resources Web.config \en-CA resources GlobalWeb.en-CA.dll resources \es GlobalWeb.es.dll resources logo.gif Database Content logo.en-CA.gif logo.es.gif translated file content list.en-CA.xml Products list.es.xml Products_en-CA Products_es

  11. Agenda • Localization and the Web • New Localization Features in 2.0 • Generating Local Resources • Localization Expressions • Global Resources and Type Safety • Runtime Culture Selection • ASP.NET Architecture

  12. Localization Features in 2.0 • Web Forms resource generator • Localization expressions • Strongly-typed resources • Improved Resource Editor • ResourceManager lifetime management • Automatic culture selection • New Microsoft ASP.NET deployment options • New resource provider model

  13. Agenda • Localization and the Web • New Localization Features in 2.0 • Generating Local Resources • Localization Expressions • Global Resources and Type Safety • Runtime Culture Selection • ASP.NET Architecture

  14. ASP.NET 2.0 and Resources • XML Resources (*.resx) • Generated for master pages, content pages, and user controls • Accessible through page or control properties, declarative expressions, or other APIs • Type-safe global resources • Set multiple localized control properties in a single command

  15. ASP.NET 2.0 and Resources (cont’d) • App_LocalResources • Generated automatically or by hand • Per page, control • App_GlobalResources • Manual generation • Shared, strongly-typed • Pre-compile or deploy source files and let the resource build provider handle the rest

  16. ASP.NET 2.0 and Resources (cont’d) • ResourceManager lifecycle is handled automatically • Resource providers are cached along with specific resource manager instances per local or global resource • Default resource and satellite assemblies are loaded into application domain, like providers, and readily accessible • ResourceManager is still thread-safe

  17. Generating Resources • From Design View, select Generate Local Resource from the Tools menu • Localizable properties for server controls are stuffed into resources • Non-localizable properties can be manually inserted • Localization expressions are generated for each server control • Page parser turns expressions into code to set properties from resources

  18. Localizing Static Content • The <asp:Localize> control can isolate blocks of static text for localization • Participates in resource generation • Based on the <asp:Literal> control, but can directly edit text in Design View <asp:Localize id=”welcomeContent” runat="server">Welcome!</asp:Localize>

  19. Generating Local Resources Michele Leroux Bustamante Architect, IDesign Microsoft Regional Director

  20. Agenda • Localization and the Web • New Localization Features in 2.0 • Generating Local Resources • Localization Expressions • Global Resources and Type Safety • Runtime Culture Selection • ASP.NET Architecture

  21. Localization Expressions • ASP.NET supports new declarative binding expressions for connection strings, application settings and resources • Extensible for custom bindings • Automatically applied when resources are generated for a page • Can hand-edit to control where resources are drawn from

  22. Implicit Expressions • After generating resources, meta:resourcekey indicates the resource prefix for this control • Resources are generated with this prefix for all localizable properties <asp:LinkButton id=lnkSelectCulture PostBackUrl="selectculture.aspx" runat="server" meta:resourcekey="LinkButtonResource1">Change Culture Settings</asp:LinkButton>’

  23. Explicit Expressions • Set a specific property to a specific resource entry • Can come from local page resources: • Or, from a global resource: <asp:ImageButton id="btnIDesign" Runat="server" ImageUrl="~/Images/idesignlogo.jpg" AlternateText='<%$ Resources: MissionStatement %>‘ PostBackUrl="http://www.idesign.net" meta:resourcekey="ImageButtonResource1" /> <asp:ImageButton id="btnIDesign" Runat="server" ImageUrl="~/Images/idesignlogo.jpg" AlternateText='<%$ Resources: Glossary, MissionStatement %>‘ PostBackUrl="http://www.idesign.net" meta:resourcekey="ImageButtonResource1" />

  24. Binding Expression Editor • Bindings can be set through the Properties window via Expressions editor dialog • ClassKey specifies a global resource if applicable, omit for local resources • ResourceKey specifies the resource entry to apply to the control property

  25. Binding Expression Editor

  26. Agenda • Localization and the Web • New Localization Features in 2.0 • Generating Local Resources • Localization Expressions • Global Resources and Type Safety • Runtime Culture Selection • ASP.NET Architecture

  27. Creating Global Resources • Add a Resources file to the application • Will be placed in a special App_GlobalResources directory

  28. Creating Global Resources • Add resources through the integrated Resource Editor • Apply them to server controls using explicit expressions • Or, write custom code to retrieve them at runtime <asp:ImageButton id="btnIDesign" Runat="server" ImageUrl="~/Images/idesignlogo.jpg" AlternateText='<%$ Resources: Glossary, MissionStatement %>‘ PostBackUrl="http://www.idesign.net" meta:resourcekey="ImageButtonResource1" />

  29. Improved Resource Editor • Integrated with Visual Studio • Visually categorize resources by their data type • More friendly interface • Create new images/icons in place

  30. Strongly-Typed Resources • Global resources generate a type-safe class accessible via global Properties object

  31. class Resources { private static System.Resources.ResourceManager _resMgr; private static System.Globalization.CultureInfo _resCulture; /*FamANDAssem*/ internal Resources() {} [System.ComponentModel.EditorBrowsableAttribute(…)] public static System.Resources.ResourceManager ResourceManager {…} [System.ComponentModel.EditorBrowsableAttribute(…)] public static System.Globalization.CultureInfo Culture {…} public static System.Drawing.Bitmap flag { get { return ((System.Drawing.Bitmap)(ResourceManager.GetObject("flag", _resCulture))); } } }

  32. Global Resources, Expressions and Runtime Behavior Michele Leroux Bustamante Architect, IDesign Microsoft Regional Director

  33. Agenda • Localization and the Web • New Localization Features in 2.0 • Generating Local Resources • Localization Expressions • Global Resources and Type Safety • Runtime Culture Selection • ASP.NET Architecture

  34. Runtime Culture Selection • System.Threading.Thread.CurrentThread • CurrentUICulture • Affects resource selection • Defaults to system UI language, or: • CurrentCulture • Affects formatting and conventions • Defaults to user locale, can be changed: Thread.CurrentThread.CurrentUICulture = new CultureInfo("es"); Thread.CurrentThread.CurrentCulture = new CultureInfo("es"); DateTime dt = DateTime.Now; String s = dt.ToLongDateString();

  35. CultureInfo • System.Globalization.CultureInfo • Encapsulates language and region

  36. Resources and Assemblies • Satellite assemblies • Generated from localized resources • Hub and spoke model • Pre-compiled or JIT-compiled for ASP.NET • Resource build provider • ResourceManager handles resource fallback to retrieve culture-specific entries at runtime

  37. (default) en en-CA en-US Resource Fallback • Best match is current thread’sUI culture • I.e., en-CA, en-US • Neutral parent culture is next best fit • I.e., en • Last resort is default frommain assembly • (default)

  38. (default) en en-CA en-US Resource Fallback • Identify the default resource culture [assembly: NeutralResourcesLanguageAttribute("en")] • Default resources will be used instead of searching for satellite assembly

  39. Culture-Specific Formatting • System.Globalization • Utility classes support formatting, sorting and conversion by culture • Formatting Classes • Sorting: SortKey, CompareInfo • String comparison: CompareInfo • Date and time: DateTimeFormatInfo • Numbers: NumberFormatInfo • Calendar data: Calendar

  40. Automatic Culture Selection • Based on browser language settings • Application or page scope • Can specify default culture • I.e., “auto:en-US” <globalizationrequestEncoding=“utf-8" responseEncoding=“utf-8" fileEncoding=“utf-8" culture=“auto:en-US" uiCulture=“auto" /> <%@ Page UICulture="auto" Culture="auto">

  41. Automatic Culture Selection Michele Leroux Bustamante Architect, IDesign Microsoft Regional Director

  42. Agenda • Localization and the Web • New Localization Features in 2.0 • Generating Local Resources • Localization Expressions • Global Resources and Type Safety • Runtime Culture Selection • ASP.NET Architecture

  43. ASP.NET Architecture • Single code/page base is easy with 2.0 • No duplicate Web content per culture • Generated page resources • Make consuming resources per page easy • Type-safe shared resources • Make consuming common resources easy • ResourceManager lifecycle • Less code required, runtime handles it

  44. Single Code/Page Base • Low impact translations • Improved productivity • Fewer errors • Less overall development effort • Issues • Managing iterations with translators • Giving translators access to data sources • Working with Web designers

  45. Deployment Options • Deploy application source • Resources (.resx) are dynamically compiled into satellite assemblies • Updates are not version controlled • Source is not protected • Deploy pre-compiled application • Assemblies pre-generated, including a local and global resource assembly and its associated satellite assemblies • Better version control and IP protection

  46. Managing User Preferences • Automatic culture selection is inadequate for enterprise applications • Culture selection options: • Auto (for default only) • UI selection • User registration • Preferences should be persisted: • Transient solutions include cookies or user session • Persistent solutions should leverage profiles or data storage

  47. Caching and Localization • Caching is critical to site performance • Caching localized pages requires custom caching per page • @OutputCache, VaryByCustom <%@ OutputCache Duration=86400 VaryByParam=None VaryByCustom="uiCulture" %>

  48. Caching and Localization • GetVaryByCustomString must have access to the user’s preferred culture • Initialize the thread earlier in page cycle • Note: Session and Profile not available public override string GetVaryByCustomString(HttpContext context, string custom) { if (string.Compare(custom, "uiCulture", true, System.Globalization.CultureInfo.InvariantCulture) == 0 && System.Threading.Thread.CurrentThread.CurrentUICulture != null) { return System.Threading.Thread.CurrentThread.CurrentUICulture.Name; } else return base.GetVaryByCustomString(context, custom); }

More Related