Presentation is loading. Please wait.

Presentation is loading. Please wait.

DEV392.NET Framework: Building Applications With Globalization In Mind Michele Leroux Bustamante Principal Software Architect IDesign Inc.

Similar presentations


Presentation on theme: "DEV392.NET Framework: Building Applications With Globalization In Mind Michele Leroux Bustamante Principal Software Architect IDesign Inc."— Presentation transcript:

1 DEV392.NET Framework: Building Applications With Globalization In Mind Michele Leroux Bustamante Principal Software Architect IDesign Inc.

2 Speaker BIO Principal Software Architect, IDesign, www.idesign.net www.idesign.net Microsoft Regional Director, www.microsoft.com/rd 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 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 Satellite Assemblies Culture-Specific Subdirectories GlobalApp.Resources.dll GlobalApp.Resources.dll GlobalApp.Resources.dll GlobalApp.exe Resources Windows Forms Resources \en-CA \es \es-EC Main Assembly Application Directory Code Types Form1Common Form1 Form1 Form1 Internal Common Common Common Internal Internal Internal

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

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

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

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

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 to the project Can build assemblies that contain shared resources

17

18

19 What Are.NET Resources? ILDASM View

20 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";

21 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")));

22 How Are Resources Created? (Default) Culture Main assembly Neutral Culture Spanish (es) Specific Culture Spanish (Ecuador) (es-EC) Spanish (Mexico) (es-MX) Triggers satellite assembly generation

23 Localizing A Windows Form

24 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 and naming conventions Runtime follows a resource fallback process to find closest match

25 Satellite Assemblies ILDASM View

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

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

28 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

29 Adding XML Resources

30 Compiling Resources Can be done from command line to automate build process Resource Generation Tool (resgen.exe) Compiled to intermediate *.resources Compiled resources are embedded in or linked to an assembly resgen strings.en-CA.txt GlobalWebApp.strings.en-CA.resources resgen common.es.resx GlobalWebApp.common.es.resources

31 Compiling Resources Assembly Linker Tool (al.exe) Must provide culture /c: setting Use /template: to inherit assembly metadata al /t:lib /out:GlobalApp.resources.dll /v:1.0.0.0 /c:en-CA /embed:GlobalApp.strings.en-CA.resources /embed:GlobalApp.common.en-CA.resources al /t:lib /out:GlobalApp.resources.dll /c:es /embed:GlobalApp.strings.es.resources /embed:GlobalApp.strings.es.resources /template:../GlobalApp.exe

32 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

33 Locating Resources Best match is current thread’s UI culture en-CA, en-US Neutral parent culture is next best fit en Last resort is default from main assembly (default) en-CA en-US en (default)

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

35 Assembly Manifest

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

37 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

38 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

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

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

41 Runtime Culture Selection System.Globalization.CultureInfo Encapsulates language and region

42 CurrentUICulture System.ThreadingThread.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);

43 Accessing Resources

44 CurrentCulture System.ThreadingThread.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

45 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

46 Culture-Specific Formatting

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

48 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 in shared resources Shared between forms, separate resource Shared between application or assemblies, separate resource assembly

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

50 Windows Forms Architecture

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

52 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

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

54 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!

55 /Articles subdirectory is relative to application path /default.aspx represents default page for neutral culture Once redirected to culture- specific directory, navigation should be relative CurrentUICulture=“es” Culture-Specific Directories

56 Culture-Specific Filenames CurrentUICulture=“es”

57 ASP.NET Configuration Machine.config Default settings for Default settings for Web.config Application-specific settings <globalization requestEncoding=“utf-8" responseEncoding=“utf-8" fileEncoding=“utf-8" culture=“en-CA" uiCulture=“en-CA" />

58 uiCulture Sets the UI culture for resource resolution ResourceManager respects this setting culture Sets culture formatting for processing requests Culture-sensitive classes respect this setting Formatting date, time and currency Calendar Sorting and list separators

59 @ Page Directive Culture settings for a particular page Overrides settings for the project or subdirectory Culture Sets culture formatting for this page UICulture Sets the UI culture for this page for resource resolution

60 Single Content Base Goals One code base Low impact future translations Alternative to direct page translation Dynamic page content XML, database or other data source Issues How do translators access data source? How do Web designers integrate?

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

62 Single Content Base And Presentation Layer CurrentUICulture=“es”

63 ASP.NET And Resources XML resources provided for global.asax and Web forms Embedded in main assembly Manually add resources for other cultures

64 ASP.NET And Resources Add new resource file to the project [resourcetype].[culture].resx Satellite resources deployed for each culture Beneath culture-named subdirectories ASP.NET shadow-copies assemblies (XCOPY deployment) Not used for significant blocks of content

65 Culture Preferences Browser Language Preferences Information is passed HTTP header GET WebForm1.aspx HTTP/1.1 Connection: Keep-Alive Accept: */* Accept-Encoding: gzip, deflate Accept-Language: en-us;q=0.8,es-ec; q=0.6,fr-ca;q=0.4,de;q=0.2; ja Host: localhost User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0;.NET CLR 1.0.3705)

66 Culture Preferences User Selection Allow users to change culture/language settings Cookies May not be supported, and may be deleted Session Storage Good for the duration of current session User Profile Persist user settings

67 ASP.NET Localization

68 Session Summary You learned about.NET support for resources and culture formatting You’ve seen some sample deployment architectures for Windows Forms and ASP.NET You should have a better idea how to employ a combination of resources, external data sources and culture- specific files You are ready to think global!

69 Call to Action Globalization planning should begin with V1.0 Otherwise, can require extensive re- architecture of existing solutions Lots of product defects waiting to happen Aggressive schedules are a given Procrastination only lengthens release cycle for V2.0

70 For More Information Microsoft Newsgroup: microsoft.public.dotnet.internationalization Localization Partner Program http://www.vsippartners.com/programs/localization More Articles and Code http://msdn.microsoft.com/asp.net/community/authors/mlb/def ault.aspx?pull=/library/en-us/dnaspp/html/aspnet- globalarchi.asp http://msdn.microsoft.com/asp.net/community/authors/mlb/def ault.aspx?pull=/library/en-us/dnaspp/html/aspnet- globalarchi.asp http://www.microsoft.com/globaldev/getwr/steps/wrguide.mspx http://www.dotnetdashboard.net/Sessions/globalization.aspx http://www.idesign.net

71 Attend a free chat or web cast http://www.microsoft.com/communities/chats/default.mspx http://www.microsoft.com/usa/webcasts/default.asp List of newsgroups http://communities2.microsoft.com/ communities/newsgroups/en-us/default.aspx MS Community Sites http://www.microsoft.com/communities/default.mspx Locate Local User Groups http://www.microsoft.com/communities/usergroups/default.mspx Community sites http://www.microsoft.com/communities/related/default.mspx

72 Q1:Overall satisfaction with the session Q2:Usefulness of the information Q3:Presenter’s knowledge of the subject Q4:Presenter’s presentation skills Q5:Effectiveness of the presentation Please fill out a session evaluation on CommNet


Download ppt "DEV392.NET Framework: Building Applications With Globalization In Mind Michele Leroux Bustamante Principal Software Architect IDesign Inc."

Similar presentations


Ads by Google