WEB326 WEB326 ASP.NET 2.0: Going Global ASP.NET 2.0: Going Global Gets Easier! New Gets Easier! New Localization Features in Localization Features in ASP.NET 2.0 ASP.NET 2.0 Michele Leroux Bustamante Michele Leroux Bustamante Architect, IDesign Architect, IDesign Microsoft Regional Director Microsoft Regional Director
58
Embed
WEB326 ASP.NET 2.0: Going Global Gets Easier! New Localization Features in ASP.NET 2.0 Michele Leroux Bustamante Architect, IDesign Microsoft Regional.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
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
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
Deployment architecture is affected by Deployment architecture is affected by location of localized application location of localized application contentcontent
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
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
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.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
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
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;
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
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
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
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
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
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
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