1 / 66

DEV392 .NET Framework: Building Applications With Globalization In Mind

DEV392 .NET Framework: Building Applications With Globalization In Mind. Michele Leroux Bustamante Principal Software Architect IDesign Inc. Speaker BIO. Principal Software Architect, IDesign, www.idesign.net Microsoft Regional Director, www.microsoft.com/rd

Download Presentation

DEV392 .NET Framework: Building Applications With Globalization In Mind

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. DEV392 .NET Framework:Building ApplicationsWith Globalization In Mind Michele Leroux Bustamante Principal Software Architect IDesign Inc.

  2. Speaker BIO • Principal Software Architect, IDesign, www.idesign.net • Microsoft Regional Director, www.microsoft.com/rd • Microsoft MVP – XML Web Services • INETA Speaker’s Bureau • BEA Technical Director • Web Services Program Advisor, UCSD • Blog: www.dasblonde.net

  3. Agenda • What is Globalization? • Localization and Application Architecture • .NET Resources • Runtime Culture Selection • Windows Forms Architecture • ASP.NET Architecture

  4. What Is Globalization? • Designing applications to be adapted to the global marketplace • Affects display, input, formats & conventions • Localizability • Separate culture dependencies from code • Localization • Adapting applications for a particular market • 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, de, es • Country Code - ISO 3166 • I.e., CA, US, EC, ES • Together, they identify culture • I.e., en-CA, en-US, es-EC, es-ES • See RFC 3066 – Tags for identifying languages

  6. Agenda • What is Globalization? • Localization and Application Architecture • .NET Resources • Runtime Culture Selection • Windows Forms Architecture • ASP.NET Architecture

  7. What To Localize? • Static Application Content • Usually “hard-coded” for presentation • For example • Menu captions • Control captions • Labels, buttons, selection options, list options • Web page content • *.aspx, *.ascx, *.html, *.xml

  8. What To Localize? • Dynamic Application Content • Content populated at runtime from XML files, databases, and other data sources • Need location of content to be organized by culture • Need filenames, connection strings and queries to be configurable by culture

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

  10. Windows Forms Resources Main Assembly Application Directory Satellite Assemblies Culture-Specific Subdirectories GlobalApp.Resources.dll \en-CA GlobalApp.exe Form1 Common Internal Resources Code Form1 Common GlobalApp.Resources.dll Internal Types \es Internal Form1 Common GlobalApp.Resources.dll \es-EC Form1 Common Internal

  11. Windows Forms Resources and data Main Assembly Application Directory Satellite Assemblies Culture-Specific Subdirectories \en-CA GlobalApp.Resources.dll resources GlobalApp.exe \es GlobalApp.Resources.dll resources resources \es-EC GlobalApp.Resources.dll resources Database Content Products Products_en-CA Products_es

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

  13. ASP.NET Duplicate 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

  14. ASP.NET Single Content Base Web Application Resources Satellite Assemblies GlobalWeb \bin \en GlobalWeb.en.dll Global.asax GlobalWeb.dll 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

  15. Agenda • What is Globalization? • Localization and Application Architecture • .NET Resources • Runtime Culture Selection • Windows Forms Architecture • ASP.NET Architecture

  16. What Are .NET Resources? • XML Resources (*.resx) • Automatically generated by VS.NET for each Windows Form and Web Form • By default, compiled and embedded in project assembly • Can add custom resources tothe project • Can build assemblies that contain shared resources

  17. What Are .NET Resources? ILDASM View

  18. How Are Resources Created? • Localizable = false this.button1.Location = new System.Drawing.Point(88, 112); this.button1.Name = "button1"; this.button1.TabIndex = 0; this.button1.Text = "button1";

  19. How Are Resources Created? • Localizable = true this.button1.Location = ((System.Drawing.Point) (resources.GetObject("button1.Location"))); this.button1.Name = "button1"; this.button1.Size = ((System.Drawing.Size) (resources.GetObject("button1.Size"))); this.button1.TabIndex = ((int)(resources.GetObject("button1.TabIndex"))); this.button1.Text = resources.GetString("button1.Text"); this.button1.TextAlign = ((System.Drawing.ContentAlignment) (resources.GetObject("button1.TextAlign"))); this.button1.Visible = ((bool)(resources.GetObject("button1.Visible")));

  20. How Are Resources Created? • (Default) Culture • Main assembly • Neutral Culture • Spanish (es) • Specific Culture • Spanish (Ecuador) (es-EC) • Spanish (Mexico) (es-MX) • Triggers satelliteassemblygeneration

  21. Localizing A Windows Form

  22. Satellite Assemblies • Defined for each language and culture • Hub and spoke model • Contain only resources - No code! • Individual version updates • No impact to main executable • Directory structure andnaming conventions • Runtime follows a resource fallback process to find closest match

  23. Satellite AssembliesILDASM View

  24. Satellite AssembliesResource Deployment Main Assembly Application Directory Satellite Assemblies Culture-Specific Subdirectories GlobalApp.Resources.dll \en-CA GlobalApp.exe Form1 Common Internal Resources Code Form1 Common GlobalApp.Resources.dll Internal Types \es Internal Form1 Common GlobalApp.Resources.dll \es-EC Form1 Common Internal

  25. Compiling Resources ColorPicker.exe ColorPicker.Resources.dll \en Resources Code Form1 Form1 Strings Strings Types CommonRes.Resources.dll \en-CA CommonRes.Resources.dll Errors Errors ColorPicker.Resources.dll Form1 Strings \es CommonRes.Resources.dll Errors

  26. Resource Source • Resource source files • Text (*.txt) – string resources • XML (*.resx) – string or binary resources • Default XML resources provided for Windows and Web Forms • Can manually add custom resources • VS.NET automatically compiles satellite assemblies • [ResourceType].[Culture].resx

  27. Locating Resources • Resource files share the same name [assemblyname].resources.dll • Manifest specifies culture [assemblyname].[resourcetype].[culture].resources • Deployed to culture-specific subdirectories • \[culture] for Windows Forms deployments • \bin\[culture] for ASP.NET deployments

  28. Locating Resources • Best match is current thread’sUI culture • en-CA, en-US • Neutral parent culture is next best fit • en • Last resort is default frommain assembly • (default) (default) en en-CA en-US

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

  30. ResourceManager • System.Resources.ResourceManager • Access specific resource type: • Form1, Form2, Strings, Errors, Common • Request resource entries by key name System.Resources.ResourceManager rm = new System.Resources.ResourceManager(typeof(Form1)); button1.Text = rm.GetString(“button1.Text”); int n = (int)rm.GetObject(“count”); string s = rm.GetString(“message”);

  31. ResourceManager • Use helper methods to retrieve resources • GetObject(), GetString() • Access specific resources by name • GetResourceSet() • Access resources for a particular culture • No resource fallback • ReleaseAllResources() • Free resources from memory

  32. ResourceManager • Direct access to satellite assemblies • Returns resources for the current thread’s UI culture setting: • To customize set Thread.CurrentThread.CurrentUICulture • If resource entry not found in satellite assembly for the current culture, ResourceManager performs resource fallback to find a valid entry

  33. Agenda • What is Globalization? • Localization and Application Architecture • .NET Resources • Runtime Culture Selection • Windows Forms Architecture • ASP.NET Architecture

  34. Runtime Culture Selection • The current thread’s culture settings dictate resource selection • CurrentUICulture Property • Controls resource selection • CurrentCulture Property • Controls culture-aware data formatting

  35. Runtime Culture Selection • System.Globalization.CultureInfo • Encapsulates language and region

  36. CurrentUICulture • System.Threading • Thread.CurrentThread.CurrentUICulture • Defaults to system UI language, or: • Or, request specific ResourceSet • But, you may lose resource fallback feature Thread.CurrentThread.CurrentUICulture = new CultureInfo("es"); ResourceManager rm = new ResourceManager(typeof(Form1)); ResourceSet rset = rm.GetResourceSet(new CultureInfo("es"), true, true);

  37. Accessing Resources

  38. CurrentCulture • System.Threading • Thread.CurrentThread.CurrentCulture • Defaults to user locale, can be changed Thread.CurrentThread.CurrentCulture = new CultureInfo("es"); DateTime dt = DateTime.Now; String s = dt.ToLongDateString(); // formatted for the current culture

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

  40. Agenda • What is Globalization? • Localization and Application Architecture • .NET Resources • Runtime Culture Selection • Windows Forms Architecture • ASP.NET Architecture

  41. Windows Forms Resource Allocation • Control properties automatically stored in embedded resources • Allows translators to edit individual form layout without touching your code • Other content stored inshared resources • Shared between forms, separate resource • Shared between application or assemblies, separate resource assembly

  42. Windows Forms GlobalApp.Resources.dll Main Assembly Application Directory Form1.en-CA.resources \en-CA Strings.en-CA.resources Common.Resources.dll Common.Resources.dll Common.en-CA.resources Common.en-CA.resources GlobalApp.exe Form1.en-CA.resources GlobalApp.Resources.dll Strings.en-CA.resources \es Form1.es.resources Strings.es.resources Common.Resources.dll Common.es.resources GlobalApp.Resources.dll \es-EC Strings.en-CA.resources Products Products_en-CA Products_es

  43. Windows Forms Architecture

  44. Agenda • What is Globalization? • Localization and Application Architecture • .NET Resources • Runtime Culture Selection • Windows Forms Architecture • ASP.NET Architecture

  45. ASP.NET Duplicate Content • Goals • Facilitate rapid 1.0 release • Deal with translation later • Translate content for each culture • I.e., ASPX, ASCX, HTML, XML • Other source files selected by culture • I.e., GIF, JPG • Can redirect to localized set of pages • Translators edit content source • Error prone

  46. ASP.NET Duplicate 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

  47. Culture-Specific Directories • Subdirectories named by culture • Filenames and navigation are untouched • Content duplicated per sub-directory • Filenames include culture • Useful for shared directories • I.e., \Images\logo.gif, \Images\logo.es-EC.gif • Use resources to store filename!

  48. Culture-Specific Directories /Articles subdirectory is relative to application path Once redirected to culture-specific directory, navigation shouldbe relative /default.aspx represents default page forneutral culture CurrentUICulture=“es”

More Related