dev392 .net framework: building applications with globalization in mind

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

Upload: halla-gordon

Post on 01-Jan-2016

25 views

Category:

Documents


0 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: DEV392  .NET Framework: Building Applications With Globalization In Mind

DEV392 .NET Framework:Building ApplicationsWith Globalization In Mind

DEV392 .NET Framework:Building ApplicationsWith Globalization In Mind

Michele Leroux BustamanteMichele Leroux BustamantePrincipal Software ArchitectPrincipal Software ArchitectIDesign Inc.IDesign Inc.

Page 2: DEV392  .NET Framework: Building Applications With Globalization In Mind

Speaker BIOSpeaker BIO

Principal Software Architect, IDesign, Principal Software Architect, IDesign, www.idesign.netwww.idesign.net

Microsoft Regional Director, Microsoft Regional Director, www.microsoft.com/rdwww.microsoft.com/rd

Microsoft MVP – XML Web ServicesMicrosoft MVP – XML Web Services

INETA Speaker’s BureauINETA Speaker’s Bureau

BEA Technical DirectorBEA Technical Director

Web Services Program Advisor, UCSD Web Services Program Advisor, UCSD

Blog: Blog: www.dasblonde.netwww.dasblonde.net

Page 3: DEV392  .NET Framework: Building Applications With Globalization In Mind

AgendaAgenda

What is Globalization?What is Globalization?

Localization and Application ArchitectureLocalization and Application Architecture

.NET Resources .NET Resources

Runtime Culture SelectionRuntime Culture Selection

Windows Forms ArchitectureWindows Forms Architecture

ASP.NET ArchitectureASP.NET Architecture

Page 4: DEV392  .NET Framework: Building Applications With Globalization In Mind

What Is Globalization?What Is Globalization?

Designing applications to be adapted to the Designing applications to be adapted to the global marketplaceglobal marketplace

Affects display, input, formats & conventions Affects display, input, formats & conventions

LocalizabilityLocalizabilitySeparate culture dependencies from code Separate culture dependencies from code

LocalizationLocalizationAdapting applications for a particular marketAdapting applications for a particular market

Content translation, feature customizationContent translation, feature customization

Changes independent of compiled sourceChanges independent of compiled source

Page 5: DEV392  .NET Framework: Building Applications With Globalization In Mind

Locale/CultureLocale/Culture

Language and cultural environmentLanguage and cultural environment

International Standards Organization International Standards Organization (ISO) Conventions(ISO) Conventions

Language Code - ISO 639-1 Language Code - ISO 639-1 I.e., en, fr, de, esI.e., en, fr, de, es

Country Code - ISO 3166 Country Code - ISO 3166 I.e., CA, US, EC, ESI.e., CA, US, EC, ES

Together, they identify cultureTogether, they identify cultureI.e., en-CA, en-US, es-EC, es-ESI.e., en-CA, en-US, es-EC, es-ES

See RFC 3066 – Tags for identifying languagesSee RFC 3066 – Tags for identifying languages

Page 6: DEV392  .NET Framework: Building Applications With Globalization In Mind

AgendaAgenda

What is Globalization?What is Globalization?

Localization and Application Localization and Application ArchitectureArchitecture

.NET Resources .NET Resources

Runtime Culture SelectionRuntime Culture Selection

Windows Forms ArchitectureWindows Forms Architecture

ASP.NET ArchitectureASP.NET Architecture

Page 7: DEV392  .NET Framework: Building Applications With Globalization In Mind

What To Localize?What To Localize?

Static Application ContentStatic Application ContentUsually “hard-coded” for presentationUsually “hard-coded” for presentation

For exampleFor exampleMenu captionsMenu captions

Control captions Control captions Labels, buttons, selection options, list optionsLabels, buttons, selection options, list options

Web page content Web page content *.aspx, *.ascx, *.html, *.xml*.aspx, *.ascx, *.html, *.xml

Page 8: DEV392  .NET Framework: Building Applications With Globalization In Mind

What To Localize?What To Localize?

Dynamic Application ContentDynamic Application ContentContent populated at runtime from XML Content populated at runtime from XML files, databases, and other data sourcesfiles, databases, and other data sources

Need location of content to be organized Need location of content to be organized by cultureby culture

Need filenames, connection strings and Need filenames, connection strings and queries to be configurable by culturequeries to be configurable by culture

Page 9: DEV392  .NET Framework: Building Applications With Globalization In Mind

Storing Localized ContentStoring Localized Content

Deployment architecture is affected by Deployment architecture is affected by location of localized application contentlocation of localized application content

Resources, file system, database,Resources, file system, database,external applicationsexternal applications

Choices influenced by application typeChoices influenced by application typeWindows versus Web Windows versus Web

And by business requirementsAnd by business requirementsFrequency of culture translationsFrequency of culture translations

Ease of translation processEase of translation process

Frequency of application maintenanceFrequency of application maintenance

Page 10: DEV392  .NET Framework: Building Applications With Globalization In Mind

Satellite AssembliesSatellite AssembliesCulture-Specific SubdirectoriesCulture-Specific Subdirectories

GlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dll

GlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dll

GlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dll

GlobalApp.exeGlobalApp.exeGlobalApp.exeGlobalApp.exe

ResourcesResources

Windows Forms ResourcesWindows Forms Resources

\en-CA\en-CA

\es\es

\es-EC\es-EC

Main AssemblyMain AssemblyApplication DirectoryApplication Directory

CodeCode

TypesTypes

Form1Form1 CommonCommon

Form1Form1

Form1Form1

Form1Form1

InternalInternal

CommonCommon

CommonCommon

CommonCommon

InternalInternal

InternalInternal

InternalInternal

Page 11: DEV392  .NET Framework: Building Applications With Globalization In Mind

Satellite AssembliesSatellite AssembliesCulture-Specific SubdirectoriesCulture-Specific Subdirectories

Windows Forms Resources and dataWindows Forms Resources and data

GlobalApp.exeGlobalApp.exeGlobalApp.exeGlobalApp.exe

GlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dll

GlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dll

GlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dll

\en-CA\en-CA

\es\es

\es-EC\es-EC

ProductsProducts

Products_en-CAProducts_en-CA

Products_esProducts_es

Main AssemblyMain AssemblyApplication DirectoryApplication Directory

resourcesresources

resourcesresources

resourcesresources

resourcesresources

Database ContentDatabase Content

Page 12: DEV392  .NET Framework: Building Applications With Globalization In Mind

ASP.NET Duplicate ContentASP.NET Duplicate Content

GlobalWeb.dllGlobalWeb.dllGlobalWeb.dllGlobalWeb.dll

ProductsProducts

GlobalWebGlobalWeb \bin\bin

Global.asaxGlobal.asax

Web.configWeb.config

logo.giflogo.gif

Web Application ResourcesWeb Application Resources

page page and user and user control control contentcontent

Database ContentDatabase Content

Page 13: DEV392  .NET Framework: Building Applications With Globalization In Mind

ASP.NET Duplicate ContentASP.NET Duplicate Content

GlobalWeb.dllGlobalWeb.dllGlobalWeb.dllGlobalWeb.dll

ProductsProducts

Products_en-CAProducts_en-CA

Products_esProducts_es

GlobalWebGlobalWeb

\en-CA\en-CA

\bin\bin

\es\es

Global.asaxGlobal.asax

Web.configWeb.config

logo.giflogo.gif

logo.en-CA.giflogo.en-CA.gif

logo.es.giflogo.es.gif

Web Application ResourcesWeb Application Resources

page page and user and user control control contentcontent

translated translated page and user page and user control control contentcontent

Database ContentDatabase Content

Page 14: DEV392  .NET Framework: Building Applications With Globalization In Mind

ASP.NET Single Content BaseASP.NET Single Content Base

GlobalWeb.dllGlobalWeb.dllGlobalWeb.dllGlobalWeb.dll

ProductsProducts

Products_en-CAProducts_en-CA

Products_esProducts_es

GlobalWebGlobalWeb \bin\bin

Global.asaxGlobal.asax

Web.configWeb.config

logo.giflogo.gif

logo.en-CA.giflogo.en-CA.gif

logo.es.giflogo.es.gif

Satellite AssembliesSatellite Assemblies

\en\en

\en-CA\en-CA

\es\es

GlobalWeb.en.dllGlobalWeb.en.dllGlobalWeb.en.dllGlobalWeb.en.dll

GlobalWeb.en-CA.dllGlobalWeb.en-CA.dllGlobalWeb.en-CA.dllGlobalWeb.en-CA.dll

GlobalWeb.es.dllGlobalWeb.es.dllGlobalWeb.es.dllGlobalWeb.es.dll

Web Application ResourcesWeb Application Resources

list.en-CA.xmllist.en-CA.xml

list.es.xmllist.es.xml

resourcesresources

resourcesresources

resourcesresources

resourcesresources

Database ContentDatabase Content

translated translated file file contentcontent

Page 15: DEV392  .NET Framework: Building Applications With Globalization In Mind

AgendaAgenda

What is Globalization?What is Globalization?

Localization and Application Localization and Application ArchitectureArchitecture

.NET Resources .NET Resources

Runtime Culture SelectionRuntime Culture Selection

Windows Forms ArchitectureWindows Forms Architecture

ASP.NET ArchitectureASP.NET Architecture

Page 16: DEV392  .NET Framework: Building Applications With Globalization In Mind

What Are .NET Resources?What Are .NET Resources?

XML Resources (*.resx)XML Resources (*.resx)Automatically generated by VS.NET for Automatically generated by VS.NET for each Windows Form and Web Formeach Windows Form and Web Form

By default, compiled and embedded in By default, compiled and embedded in project assemblyproject assembly

Can add custom resources toCan add custom resources tothe projectthe project

Can build assemblies that contain Can build assemblies that contain shared resourcesshared resources

Page 17: DEV392  .NET Framework: Building Applications With Globalization In Mind
Page 18: DEV392  .NET Framework: Building Applications With Globalization In Mind
Page 19: DEV392  .NET Framework: Building Applications With Globalization In Mind

What Are .NET Resources? ILDASM ViewWhat Are .NET Resources? ILDASM View

Page 20: DEV392  .NET Framework: Building Applications With Globalization In Mind

How Are Resources Created?How Are Resources Created?

Localizable = falseLocalizable = false

this.button1.Location =

new System.Drawing.Point(88, 112);

this.button1.Name = "button1";

this.button1.TabIndex = 0;

this.button1.Text = "button1";

Page 21: DEV392  .NET Framework: Building Applications With Globalization In Mind

How Are Resources Created?How Are Resources Created?

Localizable = trueLocalizable = 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")));

Page 22: DEV392  .NET Framework: Building Applications With Globalization In Mind

How Are Resources Created?How Are Resources Created?

(Default) Culture (Default) Culture Main assemblyMain assembly

Neutral CultureNeutral CultureSpanish (es)Spanish (es)

Specific Culture Specific Culture Spanish (Ecuador) (es-EC)Spanish (Ecuador) (es-EC)

Spanish (Mexico) (es-MX)Spanish (Mexico) (es-MX)

Triggers satelliteTriggers satelliteassemblyassembly generationgeneration

Page 23: DEV392  .NET Framework: Building Applications With Globalization In Mind

Localizing A Localizing A Windows FormWindows Form

Page 24: DEV392  .NET Framework: Building Applications With Globalization In Mind

Satellite AssembliesSatellite Assemblies

Defined for each language and cultureDefined for each language and cultureHub and spoke modelHub and spoke model

Contain only resources - No code!Contain only resources - No code!

Individual version updates Individual version updates No impact to main executableNo impact to main executable

Directory structure andDirectory structure andnaming conventionsnaming conventions

Runtime follows a resource fallback Runtime follows a resource fallback process to find closest matchprocess to find closest match

Page 25: DEV392  .NET Framework: Building Applications With Globalization In Mind

Satellite AssembliesILDASM ViewSatellite AssembliesILDASM View

Page 26: DEV392  .NET Framework: Building Applications With Globalization In Mind

Satellite AssembliesResource DeploymentSatellite AssembliesResource Deployment

Satellite AssembliesSatellite AssembliesCulture-Specific SubdirectoriesCulture-Specific Subdirectories

GlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dll

GlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dll

GlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dll

GlobalApp.exeGlobalApp.exeGlobalApp.exeGlobalApp.exe

ResourcesResources

\en-CA\en-CA

\es\es

\es-EC\es-EC

Main AssemblyMain AssemblyApplication DirectoryApplication Directory

CodeCode

TypesTypes

Form1Form1 CommonCommon

Form1Form1

Form1Form1

Form1Form1

InternalInternal

CommonCommon

CommonCommon

CommonCommon

InternalInternal

InternalInternal

InternalInternal

Page 27: DEV392  .NET Framework: Building Applications With Globalization In Mind

Compiling ResourcesCompiling Resources

ColorPicker.Resources.dllColorPicker.Resources.dllColorPicker.Resources.dllColorPicker.Resources.dllColorPicker.exeColorPicker.exeColorPicker.exeColorPicker.exe

ResourcesResources

\en\en

\en-CA\en-CA

\es\es

CodeCode

TypesTypes

Form1Form1

StringsStrings

Form1Form1 StringsStrings

ColorPicker.Resources.dllColorPicker.Resources.dllColorPicker.Resources.dllColorPicker.Resources.dll

Form1Form1 StringsStrings

CommonRes.Resources.dllCommonRes.Resources.dllCommonRes.Resources.dllCommonRes.Resources.dll

ErrorsErrors

CommonRes.Resources.dllCommonRes.Resources.dllCommonRes.Resources.dllCommonRes.Resources.dll

ErrorsErrors

CommonRes.Resources.dllCommonRes.Resources.dllCommonRes.Resources.dllCommonRes.Resources.dll

ErrorsErrors

Page 28: DEV392  .NET Framework: Building Applications With Globalization In Mind

Resource Source Resource Source

Resource source filesResource source filesText (*.txt) – string resourcesText (*.txt) – string resources

XML (*.resx) – string or binary resourcesXML (*.resx) – string or binary resources

Default XML resources provided for Default XML resources provided for Windows and Web FormsWindows and Web Forms

Can manually add custom resources Can manually add custom resources

VS.NET automatically compiles VS.NET automatically compiles satellite assembliessatellite assemblies

[ResourceType].[Culture].resx[ResourceType].[Culture].resx

Page 29: DEV392  .NET Framework: Building Applications With Globalization In Mind

Locating ResourcesLocating Resources

Resource files share the same nameResource files share the same name[assemblyname][assemblyname].resources.dll.resources.dll

Manifest specifies cultureManifest specifies culture[assemblyname][assemblyname].[resourcetype].[culture].resources.[resourcetype].[culture].resources

Deployed to culture-specific Deployed to culture-specific subdirectoriessubdirectories

\\[culture][culture] for Windows Forms deployments for Windows Forms deployments

\bin\\bin\[culture][culture] for ASP.NET deployments for ASP.NET deployments

Page 30: DEV392  .NET Framework: Building Applications With Globalization In Mind

Locating ResourcesLocating Resources

Best match is current thread’sBest match is current thread’sUI cultureUI culture

en-CA, en-USen-CA, en-US

Neutral parent culture is next best fitNeutral parent culture is next best fitenen

Last resort is default fromLast resort is default frommain assemblymain assembly

(default)(default)

en-CAen-CA

en-USen-US

enen

(default)(default)

Page 31: DEV392  .NET Framework: Building Applications With Globalization In Mind

Locating ResourcesLocating Resources

Identify the default resource culture Identify the default resource culture [assembly: NeutralResourcesLanguageAttribute("en")][assembly: NeutralResourcesLanguageAttribute("en")]

Default resources will be used instead Default resources will be used instead of searching for matching satellite of searching for matching satellite assemblyassembly

en-CA

en-US

en

(default) en

Page 32: DEV392  .NET Framework: Building Applications With Globalization In Mind

ResourceManagerResourceManager

System.Resources.ResourceManagerSystem.Resources.ResourceManager

Access specific resource type:Access specific resource type:Form1, Form2, Strings, Errors, CommonForm1, Form2, Strings, Errors, Common

Request resource entries by key nameRequest resource entries by key namebutton1.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));

Page 33: DEV392  .NET Framework: Building Applications With Globalization In Mind

ResourceManagerResourceManager

Use helper methods to retrieve Use helper methods to retrieve resourcesresources

GetObject(), GetString()GetObject(), GetString()Access specific resources by nameAccess specific resources by name

GetResourceSet()GetResourceSet()Access resources for a particular cultureAccess resources for a particular culture

No resource fallbackNo resource fallback

ReleaseAllResources()ReleaseAllResources()Free resources from memoryFree resources from memory

Page 34: DEV392  .NET Framework: Building Applications With Globalization In Mind

ResourceManagerResourceManager

Direct access to satellite assembliesDirect access to satellite assemblies

Returns resources for the current Returns resources for the current thread’s UI culture setting:thread’s UI culture setting:

To customize set To customize set Thread.CurrentThread.CurrentUICultureThread.CurrentThread.CurrentUICulture

If resource entry not found in satellite If resource entry not found in satellite assembly for the current culture, assembly for the current culture, ResourceManager performs resource ResourceManager performs resource fallback to find a valid entryfallback to find a valid entry

Page 35: DEV392  .NET Framework: Building Applications With Globalization In Mind

AgendaAgenda

What is Globalization?What is Globalization?

Localization and Application Localization and Application ArchitectureArchitecture

.NET Resources .NET Resources

Runtime Culture SelectionRuntime Culture Selection

Windows Forms ArchitectureWindows Forms Architecture

ASP.NET ArchitectureASP.NET Architecture

Page 36: DEV392  .NET Framework: Building Applications With Globalization In Mind

Runtime Culture SelectionRuntime Culture Selection

The current thread’s culture settings The current thread’s culture settings dictate resource selection dictate resource selection

CurrentUICulture PropertyCurrentUICulture PropertyControls resource selectionControls resource selection

CurrentCulture PropertyCurrentCulture PropertyControls culture-aware data formattingControls culture-aware data formatting

Page 37: DEV392  .NET Framework: Building Applications With Globalization In Mind

Runtime Culture SelectionRuntime Culture Selection

System.Globalization.CultureInfoSystem.Globalization.CultureInfoEncapsulates language and regionEncapsulates language and region

Page 38: DEV392  .NET Framework: Building Applications With Globalization In Mind

CurrentUICultureCurrentUICulture

System.ThreadingSystem.Threading

Thread.CurrentThread.CurrentUICultureThread.CurrentThread.CurrentUICultureDefaults to system UI language, or:Defaults to system UI language, or:

Or, request specific ResourceSetOr, request specific ResourceSet

But, you But, you may may lose resource fallback featurelose resource fallback feature

Thread.CurrentThread.CurrentUICulture = new CultureInfo("es");

ResourceManager rm = new ResourceManager(typeof(Form1));

ResourceSet rset = rm.GetResourceSet(new CultureInfo("es"), true, true);

Page 39: DEV392  .NET Framework: Building Applications With Globalization In Mind

Accessing Accessing ResourcesResources

Page 40: DEV392  .NET Framework: Building Applications With Globalization In Mind

CurrentCultureCurrentCulture

System.ThreadingSystem.Threading

Thread.CurrentThread.CurrentCultureThread.CurrentThread.CurrentCultureDefaults to user locale, can be changedDefaults 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

Page 41: DEV392  .NET Framework: Building Applications With Globalization In Mind

Culture-Specific FormattingCulture-Specific Formatting

System.GlobalizationSystem.Globalization

Utility classes support formatting and Utility classes support formatting and conversion based on cultureconversion based on culture

Formatting ClassesFormatting ClassesSorting: Sorting: SortKey, CompareInfoSortKey, CompareInfo

String comparison: String comparison: CompareInfoCompareInfo

Date and time: Date and time: DateTimeFormatInfoDateTimeFormatInfo

Numbers: Numbers: NumberFormatInfoNumberFormatInfo

Calendar data: Calendar data: CalendarCalendar

Page 42: DEV392  .NET Framework: Building Applications With Globalization In Mind

AgendaAgenda

What is Globalization?What is Globalization?

Localization and Application Localization and Application ArchitectureArchitecture

.NET Resources .NET Resources

Runtime Culture SelectionRuntime Culture Selection

Windows Forms ArchitectureWindows Forms Architecture

ASP.NET ArchitectureASP.NET Architecture

Page 43: DEV392  .NET Framework: Building Applications With Globalization In Mind

Windows Forms Resource AllocationWindows Forms Resource Allocation

Control properties automatically stored Control properties automatically stored in embedded resourcesin embedded resources

Allows translators to edit individual form Allows translators to edit individual form layout without touching your codelayout without touching your code

Other content stored inOther content stored inshared resourcesshared resources

Shared between forms, separate resourceShared between forms, separate resource

Shared between application or Shared between application or assemblies, separate resource assemblyassemblies, separate resource assembly

Page 44: DEV392  .NET Framework: Building Applications With Globalization In Mind

Main AssemblyMain AssemblyApplication DirectoryApplication Directory

Windows FormsWindows Forms

GlobalApp.exeGlobalApp.exeGlobalApp.exeGlobalApp.exe

GlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dll

\en-CA\en-CA

\es\es

\es-EC\es-ECProductsProducts

Products_en-CAProducts_en-CA

Products_esProducts_es

Form1.en-CA.resourcesForm1.en-CA.resourcesStrings.en-CA.resourcesStrings.en-CA.resources

Common.Resources.dllCommon.Resources.dllCommon.Resources.dllCommon.Resources.dll

Common.en-CA.resourcesCommon.en-CA.resources

GlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dll

Form1.es.resourcesForm1.es.resourcesStrings.es.resourcesStrings.es.resources

Common.Resources.dllCommon.Resources.dllCommon.Resources.dllCommon.Resources.dll

Common.es.resourcesCommon.es.resources

GlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dllGlobalApp.Resources.dll

Strings.en-CA.resourcesStrings.en-CA.resources

Form1.en-CA.resourcesForm1.en-CA.resourcesStrings.en-CA.resourcesStrings.en-CA.resources

Common.Resources.dllCommon.Resources.dllCommon.Resources.dllCommon.Resources.dll

Common.en-CA.resourcesCommon.en-CA.resources

Page 45: DEV392  .NET Framework: Building Applications With Globalization In Mind

Windows Forms Windows Forms ArchitectureArchitecture

Page 46: DEV392  .NET Framework: Building Applications With Globalization In Mind

AgendaAgenda

What is Globalization?What is Globalization?

Localization and Application Localization and Application ArchitectureArchitecture

.NET Resources .NET Resources

Runtime Culture SelectionRuntime Culture Selection

Windows Forms ArchitectureWindows Forms Architecture

ASP.NET ArchitectureASP.NET Architecture

Page 47: DEV392  .NET Framework: Building Applications With Globalization In Mind

ASP.NET Duplicate ContentASP.NET Duplicate Content

GoalsGoalsFacilitate rapid 1.0 releaseFacilitate rapid 1.0 releaseDeal with translation laterDeal with translation later

Translate content for each cultureTranslate content for each cultureI.e., ASPX, ASCX, HTML, XMLI.e., ASPX, ASCX, HTML, XML

Other source files selected by cultureOther source files selected by cultureI.e., GIF, JPGI.e., GIF, JPG

Can redirect to localized set of pagesCan redirect to localized set of pagesTranslators edit content sourceTranslators edit content source

Error proneError prone

Page 48: DEV392  .NET Framework: Building Applications With Globalization In Mind

ASP.NET Duplicate ContentASP.NET Duplicate Content

GlobalWeb.dllGlobalWeb.dllGlobalWeb.dllGlobalWeb.dll

ProductsProducts

Products_en-CAProducts_en-CA

Products_esProducts_es

GlobalWebGlobalWeb

\en-CA\en-CA

\bin\bin

\es\es

Global.asaxGlobal.asax

Web.configWeb.config

logo.giflogo.gif

logo.en-CA.giflogo.en-CA.gif

logo.es.giflogo.es.gif

Web Application ResourcesWeb Application Resources

page page and user and user control control contentcontent

translated translated page and user page and user control control contentcontent

Database ContentDatabase Content

Page 49: DEV392  .NET Framework: Building Applications With Globalization In Mind

Culture-Specific DirectoriesCulture-Specific Directories

Subdirectories named by cultureSubdirectories named by cultureFilenames and navigation are untouchedFilenames and navigation are untouched

Content duplicated per sub-directoryContent duplicated per sub-directory

Filenames include cultureFilenames include cultureUseful for shared directories Useful for shared directories

I.e., \Images\logo.gif, \Images\logo.es-EC.gifI.e., \Images\logo.gif, \Images\logo.es-EC.gif

Use resources to store filename!Use resources to store filename!

Page 50: DEV392  .NET Framework: Building Applications With Globalization In Mind

/Articles subdirectory is /Articles subdirectory is relative to application pathrelative to application path

/default.aspx represents /default.aspx represents default page fordefault page forneutral cultureneutral culture

Once redirected to culture-Once redirected to culture-specific directory, specific directory, navigation shouldnavigation shouldbe relativebe relative

CurrentUICulture=“es”CurrentUICulture=“es”

Culture-Specific DirectoriesCulture-Specific Directories

Page 51: DEV392  .NET Framework: Building Applications With Globalization In Mind

Culture-Specific FilenamesCulture-Specific Filenames

CurrentUICulture=“es”CurrentUICulture=“es”

Page 52: DEV392  .NET Framework: Building Applications With Globalization In Mind

ASP.NET Configuration<globalization>ASP.NET Configuration<globalization>

Machine.configMachine.configDefault settings for <globalization>Default settings for <globalization>

Web.configWeb.configApplication-specific settingsApplication-specific settings

<globalization requestEncoding=“utf-8"

responseEncoding=“utf-8"

fileEncoding=“utf-8"

culture=“en-CA"

uiCulture=“en-CA" />

Page 53: DEV392  .NET Framework: Building Applications With Globalization In Mind

<globalization><globalization>

uiCultureuiCultureSets the UI culture for resource resolutionSets the UI culture for resource resolution

ResourceManager respects this settingResourceManager respects this setting

culturecultureSets culture formatting forSets culture formatting forprocessing requestsprocessing requests

Culture-sensitive classes respectCulture-sensitive classes respectthis settingthis setting

Formatting date, time and currencyFormatting date, time and currency

CalendarCalendar

Sorting and list separatorsSorting and list separators

Page 54: DEV392  .NET Framework: Building Applications With Globalization In Mind

@ Page Directive@ Page Directive

Culture settings for a particular pageCulture settings for a particular page

Overrides <globalization> settings for Overrides <globalization> settings for the project or subdirectorythe project or subdirectory

Culture Culture Sets culture formatting for this pageSets culture formatting for this page

UICulture UICulture Sets the UI culture for this page for Sets the UI culture for this page for resource resolutionresource resolution

Page 55: DEV392  .NET Framework: Building Applications With Globalization In Mind

Single Content BaseSingle Content Base

GoalsGoalsOne code base One code base

Low impact future translationsLow impact future translations

Alternative to direct page translationAlternative to direct page translationDynamic page contentDynamic page content

XML, database or other data sourceXML, database or other data source

IssuesIssuesHow do translators access data source?How do translators access data source?

How do Web designers integrate?How do Web designers integrate?

Page 56: DEV392  .NET Framework: Building Applications With Globalization In Mind

ASP.NET Single Content BaseASP.NET Single Content Base

GlobalWeb.dllGlobalWeb.dllGlobalWeb.dllGlobalWeb.dll

ProductsProducts

Products_en-CAProducts_en-CA

Products_esProducts_es

GlobalWebGlobalWeb \bin\bin

Global.asaxGlobal.asax

Web.configWeb.config

logo.giflogo.gif

logo.en-CA.giflogo.en-CA.gif

logo.es.giflogo.es.gif

Satellite AssembliesSatellite Assemblies

\en-CA\en-CA

\es\es

\es-EC\es-EC

GlobalWeb.en-CA.dllGlobalWeb.en-CA.dllGlobalWeb.en-CA.dllGlobalWeb.en-CA.dll

GlobalWeb.es.dllGlobalWeb.es.dllGlobalWeb.es.dllGlobalWeb.es.dll

GlobalWeb.es-EC.dllGlobalWeb.es-EC.dllGlobalWeb.es-EC.dllGlobalWeb.es-EC.dll

Web Application ResourcesWeb Application Resources

list.en-CA.xmllist.en-CA.xml

list.es.xmllist.es.xml

resourcesresources

resourcesresources

resourcesresources

resourcesresources

Database ContentDatabase Content

translated translated file file contentcontent

Page 57: DEV392  .NET Framework: Building Applications With Globalization In Mind

ASP.NET And Resources ASP.NET And Resources

XML resources provided for XML resources provided for global.asax and Web formsglobal.asax and Web forms

Embedded in main assemblyEmbedded in main assembly

Manually add resourcesManually add resourcesfor other culturesfor other cultures

Page 58: DEV392  .NET Framework: Building Applications With Globalization In Mind

ASP.NET And ResourcesASP.NET And Resources

Add new resource file to the projectAdd new resource file to the project[resourcetype].[culture].resx[resourcetype].[culture].resx

Satellite resources deployed forSatellite resources deployed foreach cultureeach culture

Beneath culture-named subdirectoriesBeneath culture-named subdirectories

ASP.NET shadow-copies assemblies ASP.NET shadow-copies assemblies (XCOPY deployment)(XCOPY deployment)

Not used for significant blocksNot used for significant blocksof contentof content

Page 59: DEV392  .NET Framework: Building Applications With Globalization In Mind

Culture PreferencesCulture Preferences

Browser Language PreferencesBrowser Language Preferences

Information is passed HTTP headerInformation 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)

Page 60: DEV392  .NET Framework: Building Applications With Globalization In Mind

Culture PreferencesCulture Preferences

User SelectionUser SelectionAllow uAllow users to change culture/language sers to change culture/language settingssettings

CookiesCookiesMay not be supported, and mayMay not be supported, and maybe deletedbe deleted

Session StorageSession StorageGood for the duration of Good for the duration of current current sessionsession

User ProfileUser ProfilePersist user settingsPersist user settings

Page 61: DEV392  .NET Framework: Building Applications With Globalization In Mind

ASP.NET ASP.NET LocalizationLocalization

Page 62: DEV392  .NET Framework: Building Applications With Globalization In Mind

Session SummarySession Summary

You learned about .NET support for You learned about .NET support for resources and culture formattingresources and culture formatting

You’ve seen some sample deployment You’ve seen some sample deployment architectures for Windows Formsarchitectures for Windows Formsand ASP.NETand ASP.NET

You should have a better idea how to You should have a better idea how to employ a combination of resources, employ a combination of resources, external data sources and culture-external data sources and culture-specific filesspecific files

You are ready to think global!You are ready to think global!

Page 63: DEV392  .NET Framework: Building Applications With Globalization In Mind

Call to ActionCall to Action

Globalization planning should begin Globalization planning should begin with V1.0with V1.0

Otherwise, can require extensive re-Otherwise, can require extensive re-architecture of existing solutions architecture of existing solutions

Lots of product defects waiting to happenLots of product defects waiting to happen

Aggressive schedules are a givenAggressive schedules are a givenProcrastination only lengthens release Procrastination only lengthens release cycle for V2.0cycle for V2.0

Page 64: DEV392  .NET Framework: Building Applications With Globalization In Mind

For More InformationFor More Information

Microsoft Newsgroup: Microsoft Newsgroup: microsoft.public.dotnet.internationalizationmicrosoft.public.dotnet.internationalization

Localization Partner ProgramLocalization Partner Programhttp://www.vsippartners.com/programs/localizationhttp://www.vsippartners.com/programs/localization

More Articles and CodeMore Articles and Codehttp://msdn.microsoft.com/asp.net/community/authors/mlb/defhttp://msdn.microsoft.com/asp.net/community/authors/mlb/default.aspx?pull=/library/en-us/dnaspp/html/aspnet-globalarchi.aault.aspx?pull=/library/en-us/dnaspp/html/aspnet-globalarchi.aspsp

http://www.microsoft.com/globaldev/getwr/steps/wrguide.mspxhttp://www.microsoft.com/globaldev/getwr/steps/wrguide.mspx

http://www.dotnetdashboard.net/Sessions/globalization.aspxhttp://www.dotnetdashboard.net/Sessions/globalization.aspx

http://http://www.idesign.netwww.idesign.net

Page 65: DEV392  .NET Framework: Building Applications With Globalization In Mind

Attend a free chat or web castAttend a free chat or web casthttp://www.microsoft.com/communities/chats/default.mspxhttp://www.microsoft.com/communities/chats/default.mspx http://www.microsoft.com/usa/webcasts/default.asphttp://www.microsoft.com/usa/webcasts/default.asp

List of newsgroupsList of newsgroupshttp://communities2.microsoft.com/http://communities2.microsoft.com/communities/newsgroups/en-us/default.aspxcommunities/newsgroups/en-us/default.aspx

MS Community SitesMS Community Siteshttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

Locate Local User GroupsLocate Local User Groupshttp://www.microsoft.com/communities/usergroups/default.mspxhttp://www.microsoft.com/communities/usergroups/default.mspx

Community sitesCommunity siteshttp://www.microsoft.com/communities/related/default.mspxhttp://www.microsoft.com/communities/related/default.mspx

Page 66: DEV392  .NET Framework: Building Applications With Globalization In Mind

Q1:Q1: Overall satisfaction with the sessionOverall satisfaction with the session

Q2:Q2: Usefulness of the informationUsefulness of the information

Q3:Q3: Presenter’s knowledge of the subjectPresenter’s knowledge of the subject

Q4:Q4: Presenter’s presentation skillsPresenter’s presentation skills

Q5:Q5: Effectiveness of the presentationEffectiveness of the presentation

Please fill out a session evaluation on CommNetPlease fill out a session evaluation on CommNet