WEB326 ASP.NET 2.0: Going Global Gets Easier! New Localization Features in ASP.NET 2.0 Michele Leroux Bustamante Architect, IDesign Microsoft Regional.

Post on 28-Dec-2015

221 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

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

Michele Leroux BustamanteMichele Leroux BustamanteArchitect, IDesignArchitect, IDesignMicrosoft Regional DirectorMicrosoft Regional Director

Michele Leroux BustamanteMichele Leroux Bustamante

AgendaAgenda

Localization and the WebLocalization and the Web

New Localization Features in 2.0New Localization Features in 2.0

Generating Local ResourcesGenerating Local Resources

Localization ExpressionsLocalization Expressions

Global Resources and Type SafetyGlobal Resources and Type Safety

Runtime Culture SelectionRuntime Culture Selection

ASP.NET ArchitectureASP.NET Architecture

What Is Globalization?What Is Globalization?

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

Display, input, formats & conventions Display, input, formats & conventions

LocalizabilityLocalizabilitySeparate culture dependencies from code Separate culture dependencies from code

LocalizationLocalizationAdapting applications for specific marketsAdapting applications for specific markets

Content translation, feature customizationContent translation, feature customization

Changes independent of compiled sourceChanges independent of compiled source

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 (i.e., en, fr, es)Language Code: ISO 639-1 (i.e., en, fr, es)

Country Code: ISO 3166 (i.e., CA, EC)Country Code: ISO 3166 (i.e., CA, EC)

Together, they identify culture (i.e., es-EC)Together, they identify culture (i.e., es-EC)

See See RFC 3066 – Tags for identifying RFC 3066 – Tags for identifying languageslanguages

Custom cultures are sometimes Custom cultures are sometimes necessarynecessary

What To Localize?What To Localize?

Static (hard-coded) application contentStatic (hard-coded) application contentMenu/control captions, Web content, XMLMenu/control captions, Web content, XML

Dynamic application contentDynamic application contentDatabase, XML, otherDatabase, XML, other

Graphical contentGraphical content

Filenames, connection strings, queriesFilenames, connection strings, queries

Storing Localized ContentStoring Localized Content

Deployment architecture is affected by Deployment architecture is affected by location of localized application location of localized application contentcontent

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

Choices influenced by application typeChoices influenced by application typeMicrosoft Windows versus Web Microsoft 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

Database ContentDatabase Content

Duplicate Site ContentDuplicate Site Content

GlobalWeb.dllGlobalWeb.dllGlobalWeb.dllGlobalWeb.dll

ProductsProducts

GlobalWebGlobalWeb \bin\bin

Global.asaxGlobal.asax

Web.configWeb.config

logo.giflogo.gif

page page and user and user control control contentcontent

Database ContentDatabase Content

Duplicate Site ContentDuplicate Site 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

page page and user and user control control contentcontent

translated translated page and user page and user control control contentcontent

Database ContentDatabase Content

Single Content BaseSingle Content Base

GlobalWeb.dllGlobalWeb.dllGlobalWeb.dllGlobalWeb.dll

ProductsProductsProducts_en-CAProducts_en-CAProducts_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

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

list.es.xmllist.es.xml

resourcesresourcesresourcesresources

resourcesresources

resourcesresources

translated translated file file contentcontent

AgendaAgenda

Localization and the WebLocalization and the Web

New Localization Features in 2.0New Localization Features in 2.0

Generating Local ResourcesGenerating Local Resources

Localization ExpressionsLocalization Expressions

Global Resources and Type SafetyGlobal Resources and Type Safety

Runtime Culture SelectionRuntime Culture Selection

ASP.NET ArchitectureASP.NET Architecture

Localization Features in 2.0Localization Features in 2.0

Web Forms resource generatorWeb Forms resource generator

Localization expressions Localization expressions

Strongly-typed resourcesStrongly-typed resources

Improved Resource EditorImproved Resource Editor

ResourceManager lifetime managementResourceManager lifetime management

Automatic culture selectionAutomatic culture selection

New Microsoft ASP.NET deployment New Microsoft ASP.NET deployment optionsoptions

New resource provider modelNew resource provider model

AgendaAgenda

Localization and the WebLocalization and the Web

New Localization Features in 2.0New Localization Features in 2.0

Generating Local ResourcesGenerating Local Resources

Localization ExpressionsLocalization Expressions

Global Resources and Type SafetyGlobal Resources and Type Safety

Runtime Culture SelectionRuntime Culture Selection

ASP.NET ArchitectureASP.NET Architecture

ASP.NET 2.0 and ResourcesASP.NET 2.0 and Resources

XML Resources (*.resx)XML Resources (*.resx)

Generated for master pages, content Generated for master pages, content pages, and user controlspages, and user controls

Accessible through page or control Accessible through page or control properties, declarative properties, declarative expressions, expressions, or other APIsor other APIs

Type-safe global resources Type-safe global resources

Set multiple localized Set multiple localized control control properties in a properties in a single single commandcommand

ASP.NET 2.0 and Resources (cont’d)ASP.NET 2.0 and Resources (cont’d)

App_LocalResourcesApp_LocalResourcesGenerated automatically or by handGenerated automatically or by handPer page, controlPer page, control

App_GlobalResources App_GlobalResources Manual generationManual generationShared, strongly-typedShared, strongly-typed

Pre-compile or deploy Pre-compile or deploy source source files and let the files and let the resource build resource build

provider handle provider handle the rest the rest

ASP.NET 2.0 and Resources (cont’d)ASP.NET 2.0 and Resources (cont’d)

ResourceManager lifecycle is handled ResourceManager lifecycle is handled automaticallyautomatically

Resource providers are cached along Resource providers are cached along with specific resource manager with specific resource manager instances per local or global resourceinstances per local or global resource

Default resource and satellite Default resource and satellite assemblies are loaded into application assemblies are loaded into application domain, like providers, and readily domain, like providers, and readily accessibleaccessible

ResourceManager is still thread-safeResourceManager is still thread-safe

Generating ResourcesGenerating Resources

From Design View, select Generate From Design View, select Generate Local Resource from the Tools menuLocal Resource from the Tools menu

Localizable properties for server Localizable properties for server controls are stuffed into resourcescontrols are stuffed into resources

Non-localizable properties can be Non-localizable properties can be manually insertedmanually inserted

Localization expressions are generated Localization expressions are generated for each server controlfor each server control

Page parser turns expressions into code Page parser turns expressions into code to set properties from resourcesto set properties from resources

Localizing Static ContentLocalizing Static Content

The <asp:Localize> control can isolate The <asp:Localize> control can isolate blocks of static text for localizationblocks of static text for localization

Participates in resource generationParticipates in resource generation

Based on the <asp:Literal> control, but Based on the <asp:Literal> control, but can directly edit text in Design Viewcan directly edit text in Design View

<asp:Localize id=”welcomeContent” runat="server">Welcome!</asp:Localize>

Generating Local ResourcesGenerating Local Resources

Michele Leroux BustamanteMichele Leroux BustamanteArchitect, IDesignArchitect, IDesignMicrosoft Regional DirectorMicrosoft Regional Director

AgendaAgenda

Localization and the WebLocalization and the Web

New Localization Features in 2.0New Localization Features in 2.0

Generating Local ResourcesGenerating Local Resources

Localization ExpressionsLocalization Expressions

Global Resources and Type SafetyGlobal Resources and Type Safety

Runtime Culture SelectionRuntime Culture Selection

ASP.NET ArchitectureASP.NET Architecture

Localization ExpressionsLocalization Expressions

ASP.NET supports new declarative ASP.NET supports new declarative binding expressions for connection binding expressions for connection strings, application settings and strings, application settings and resourcesresources

Extensible for custom bindingsExtensible for custom bindings

Automatically applied when resources Automatically applied when resources are generated for a pageare generated for a page

Can hand-edit to control where resources Can hand-edit to control where resources are drawn fromare drawn from

Implicit ExpressionsImplicit Expressions

After generating resources, After generating resources, meta:resourcekey indicates the meta:resourcekey indicates the resource prefix for this controlresource prefix for this control

Resources are generated with this Resources are generated with this prefix for all localizable propertiesprefix for all localizable properties

<asp:LinkButton id=lnkSelectCulture PostBackUrl="selectculture.aspx" runat="server" meta:resourcekey="LinkButtonResource1">Change Culture Settings</asp:LinkButton>’

Explicit ExpressionsExplicit Expressions

Set a specific property to a specific Set a specific property to a specific resource entryresource entry

Can come from local page resources:Can come from local page resources:

Or, from a global resource: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" />

Binding Expression EditorBinding Expression Editor

Bindings can be set through the Bindings can be set through the Properties window via Expressions Properties window via Expressions editor dialogeditor dialog

ClassKey specifies a global resource if ClassKey specifies a global resource if applicable, omit for local resourcesapplicable, omit for local resources

ResourceKey specifies the resource ResourceKey specifies the resource entry to apply to the control propertyentry to apply to the control property

Binding Expression EditorBinding Expression Editor

AgendaAgenda

Localization and the WebLocalization and the Web

New Localization Features in 2.0New Localization Features in 2.0

Generating Local ResourcesGenerating Local Resources

Localization ExpressionsLocalization Expressions

Global Resources and Type SafetyGlobal Resources and Type Safety

Runtime Culture SelectionRuntime Culture Selection

ASP.NET ArchitectureASP.NET Architecture

Creating Global ResourcesCreating Global Resources

Add a Resources file to the applicationAdd a Resources file to the application

Will be placed in a special Will be placed in a special App_GlobalResources directoryApp_GlobalResources directory

Creating Global ResourcesCreating Global Resources

Add resources through the integrated Add resources through the integrated Resource EditorResource Editor

Apply them to server controls using Apply them to server controls using explicit expressionsexplicit expressions

Or, write custom code to retrieve them Or, write custom code to retrieve them at runtimeat runtime

<asp:ImageButton id="btnIDesign" Runat="server" ImageUrl="~/Images/idesignlogo.jpg" AlternateText='<%$ Resources: Glossary, MissionStatement %>‘ PostBackUrl="http://www.idesign.net" meta:resourcekey="ImageButtonResource1" />

Improved Resource EditorImproved Resource Editor

Integrated with Visual StudioIntegrated with Visual Studio

Visually categorize resources by their Visually categorize resources by their data typedata type

More friendly interfaceMore friendly interface

Create new images/icons in placeCreate new images/icons in place

Strongly-Typed ResourcesStrongly-Typed Resources

Global resources generate a type-safe Global resources generate a type-safe class accessible via global Properties class accessible via global Properties objectobject

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))); } } }

Global Resources, Expressions Global Resources, Expressions and Runtime Behaviorand Runtime Behavior

Michele Leroux BustamanteMichele Leroux BustamanteArchitect, IDesignArchitect, IDesignMicrosoft Regional DirectorMicrosoft Regional Director

AgendaAgenda

Localization and the WebLocalization and the Web

New Localization Features in 2.0New Localization Features in 2.0

Generating Local ResourcesGenerating Local Resources

Localization ExpressionsLocalization Expressions

Global Resources and Type SafetyGlobal Resources and Type Safety

Runtime Culture SelectionRuntime Culture Selection

ASP.NET ArchitectureASP.NET Architecture

Runtime Culture SelectionRuntime Culture Selection

System.Threading.Thread.CurrentThreadSystem.Threading.Thread.CurrentThread

CurrentUICultureCurrentUICultureAffects resource selectionAffects resource selection

Defaults to system UI language, or:Defaults to system UI language, or:

CurrentCultureCurrentCultureAffects formatting and conventionsAffects formatting and conventions

Defaults to user locale, can be changed: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();

CultureInfoCultureInfo

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

Resources and AssembliesResources and Assemblies

Satellite assembliesSatellite assembliesGenerated from localized resourcesGenerated from localized resources

Hub and spoke modelHub and spoke model

Pre-compiled or JIT-compiled Pre-compiled or JIT-compiled for ASP.NETfor ASP.NET

Resource build providerResource build provider

ResourceManager handles resource ResourceManager handles resource fallback to retrieve culture-specific fallback to retrieve culture-specific entries at runtimeentries at runtime

Resource FallbackResource Fallback

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

I.e., en-CA, en-USI.e., en-CA, en-US

Neutral parent culture is next best fitNeutral parent culture is next best fitI.e., enI.e., en

Last resort is Last resort is default fromdefault frommain assemblymain assembly

(default)(default)

en-CA

en-US

en

(default)

Resource FallbackResource Fallback

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 satellite assemblyof searching for satellite assembly

en-CA

en-US

en

(default)

Culture-Specific FormattingCulture-Specific Formatting

System.GlobalizationSystem.Globalization

Utility classes support formatting, Utility classes support formatting, sorting and conversion by culturesorting and conversion by culture

Formatting ClassesFormatting ClassesSorting: SortKey, CompareInfoSorting: SortKey, CompareInfo

String comparison: CompareInfoString comparison: CompareInfo

Date and time: DateTimeFormatInfoDate and time: DateTimeFormatInfo

Numbers: NumberFormatInfoNumbers: NumberFormatInfo

Calendar data: CalendarCalendar data: Calendar

Automatic Culture SelectionAutomatic Culture Selection

Based on browser language settingsBased on browser language settings

Application or page scopeApplication or page scope

Can specify default cultureCan specify default cultureI.e., “auto:en-US”I.e., “auto:en-US”

<globalization requestEncoding=“utf-8" responseEncoding=“utf-8" fileEncoding=“utf-8" culture=“auto:en-US" uiCulture=“auto" />

<%@ Page UICulture="auto" Culture="auto">

Automatic Culture SelectionAutomatic Culture Selection

Michele Leroux BustamanteMichele Leroux BustamanteArchitect, IDesignArchitect, IDesignMicrosoft Regional DirectorMicrosoft Regional Director

AgendaAgenda

Localization and the WebLocalization and the Web

New Localization Features in 2.0New Localization Features in 2.0

Generating Local ResourcesGenerating Local Resources

Localization ExpressionsLocalization Expressions

Global Resources and Type SafetyGlobal Resources and Type Safety

Runtime Culture SelectionRuntime Culture Selection

ASP.NET ArchitectureASP.NET Architecture

ASP.NET ArchitectureASP.NET Architecture

Single code/page base is easy with 2.0Single code/page base is easy with 2.0No duplicate Web content per cultureNo duplicate Web content per culture

Generated page resourcesGenerated page resourcesMake consuming resources per page easyMake consuming resources per page easy

Type-safe shared resourcesType-safe shared resourcesMake consuming common resources easyMake consuming common resources easy

ResourceManager lifecycle ResourceManager lifecycle Less code required, runtime handles itLess code required, runtime handles it

Single Code/Page BaseSingle Code/Page Base

Low impact translationsLow impact translations

Improved productivityImproved productivityFewer errorsFewer errors

Less overall development effortLess overall development effort

IssuesIssuesManaging iterations with translatorsManaging iterations with translators

Giving translators access to data sourcesGiving translators access to data sources

Working with Web designersWorking with Web designers

Deployment OptionsDeployment Options

Deploy application sourceDeploy application sourceResources (.resx) are dynamically Resources (.resx) are dynamically compiled into satellite assembliescompiled into satellite assemblies

Updates are not version controlledUpdates are not version controlled

Source is not protectedSource is not protected

Deploy pre-compiled applicationDeploy pre-compiled applicationAssemblies pre-generated, including a Assemblies pre-generated, including a local and global resource assembly and local and global resource assembly and its associated satellite assembliesits associated satellite assemblies

Better version control and IP protectionBetter version control and IP protection

Managing User PreferencesManaging User Preferences

Automatic culture selection is Automatic culture selection is inadequate for enterprise applicationsinadequate for enterprise applications

Culture selection options:Culture selection options:Auto (for default only)Auto (for default only)

UI selection UI selection

User registrationUser registration

Preferences should be persisted:Preferences should be persisted:Transient solutions include cookies or Transient solutions include cookies or user sessionuser session

Persistent solutions should leverage profiles or Persistent solutions should leverage profiles or data storagedata storage

Caching and LocalizationCaching and Localization

Caching is critical to site performanceCaching is critical to site performance

Caching localized pages requires Caching localized pages requires custom caching per pagecustom caching per page

@OutputCache, VaryByCustom@OutputCache, VaryByCustom

<%@ OutputCache Duration=86400 VaryByParam=None VaryByCustom="uiCulture" %>

Caching and LocalizationCaching and Localization

GetVaryByCustomString must have GetVaryByCustomString must have access to the user’s preferred cultureaccess to the user’s preferred culture

Initialize the thread earlier in page cycleInitialize the thread earlier in page cycleNote:Note: Session and Profile not available 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);}

Handling 1.1 ResourcesHandling 1.1 Resources

By default, localization expressions By default, localization expressions and resource providers do not interact and resource providers do not interact with 1.1 resourceswith 1.1 resources

Can port your 1.1 solution to data binding Can port your 1.1 solution to data binding expressions and ResourceManager expressions and ResourceManager lifecycle managementlifecycle management

Custom expression builders and Custom expression builders and resource providers can helpresource providers can help

Culture Preferences, Caching & Culture Preferences, Caching & DeploymentDeployment

Michele Leroux BustamanteMichele Leroux BustamanteArchitect, IDesignArchitect, IDesignMicrosoft Regional DirectorMicrosoft Regional Director

Michele’s ResourcesMichele’s Resources

Michele’s Globalization Site: Michele’s Globalization Site: http://www.dotnetdashboard.net/sessions/globalization.aspx

Michele’s Blog: Michele’s Blog: http://www.dasblonde.net

IDesign: IDesign: http://www.idesign.net

Localization Partner Program: Localization Partner Program: http://www.vsippartners.com/programs/localization

ResourcesResources

General guidelines on internationalization:General guidelines on internationalization: http://www.microsoft.com/globaldev

General questions:General questions: drintl@microsoft.com

Developing International Software:Developing International Software: (available here at the Tech-Ed store)(available here at the Tech-Ed store)

ResourcesResourcesTech-Ed 2005 International Break-out SessionsTech-Ed 2005 International Break-out Sessions

TitleTitleCodeCode

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

WEB326WEB326

Deploying Office 2003Deploying Office 2003 in a Multilingual Environment in a Multilingual EnvironmentDSK345DSK345

Deploying Windows XPDeploying Windows XP in a Multilingual Environment in a Multilingual EnvironmentDSK350DSK350

Databases for the World:Databases for the World: Best Practices for Search in Multilingual Data Best Practices for Search in Multilingual Data Sets Using SQL Server Collation for Sorting and IndexingSets Using SQL Server Collation for Sorting and Indexing

DBA319DBA319

Microsoft Business SolutionsMicrosoft Business Solutions––Axapta:Axapta: A Truly Global Business Application A Truly Global Business ApplicationBAP347BAP347

Supporting East Asian LanguagesSupporting East Asian Languages in Global Exchange Deployments in Global Exchange DeploymentsMSG369MSG369

.NET Framework: Think Global!.NET Framework: Think Global! Custom Cultures and International Data Custom Cultures and International DataDEV323DEV323

Databases for the World:Databases for the World: Designing Multilingual Databases Using SQL Designing Multilingual Databases Using SQL Server 2005Server 2005

DAT290DAT290

Planning a Global Release:Planning a Global Release: Many countries, Many Languages, One Process Many countries, Many Languages, One ProcessARC303ARC303

ResourcesResourcesTech-Ed 2005 International Cabana TalksTech-Ed 2005 International Cabana Talks

Dr. International’s ClinicDr. International’s Clinic

Booth in the Community Cabana International Experts available all week long

TitleTitleCodeCode

Custom Cultures in Whidbey: Custom Cultures in Whidbey: An In-Depth DiscussionAn In-Depth DiscussionDEVC21DEVC21

Advanced Localization ArchitectureAdvanced Localization ArchitectureDEVC19DEVC19

Windows XP MUI:Windows XP MUI: Keeping it Localized & Secure Keeping it Localized & SecureDSKC07DSKC07

Meet the Speakers From ARC303: Meet the Speakers From ARC303: Planning a Global ReleasePlanning a Global ReleaseARCC04ARCC04

Your FeedbackYour Feedbackis Important!is Important!Please Fill Out a Survey forPlease Fill Out a Survey forThis Session on CommNetThis Session on CommNet

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

top related