Mark Frederiksen ABLE Innovations i18n (Internationalization) in ASP.NET 2.0

download Mark Frederiksen ABLE Innovations i18n (Internationalization) in ASP.NET 2.0

of 55

  • date post

  • Category


  • view

  • download


Embed Size (px)

Transcript of Mark Frederiksen ABLE Innovations i18n (Internationalization) in ASP.NET 2.0

  • Slide 1
  • Mark Frederiksen ABLE Innovations i18n (Internationalization) in ASP.NET 2.0
  • Slide 2
  • Objectives: Describe the Internationalization issues related to ASP.NET 2.0 applications Define technical approaches Suggest strategies for Internationalizing ASP.NET 2.0 applications (and WinForms, too)
  • Slide 3
  • Assumptions: Environment ASP.NET 2.0 development environment Using Visual Studio 2005 C# Microsoft SQL Server 2005 Typically, single or clustered server environment supporting multiple languages simultaneously: Unicode as default code set Likely: Using ASP.NET 2.0 Membership/Profile capabilities
  • Slide 4
  • Assumptions: Users Using browsers: Internet Explorer 6.0+(Windows and Mac??) Firefox 1.5+(Windows and Mac) Safari 1.3.2 (Mac) Languages initially supported: Unicode as default code set English (default) Western European languages Asian: Japanese, Korean, Chinese (simplified (PRC), traditional (Taiwan, other areas) Discussion will NOT include: bi-directional language Only Gregorian calendar system will be considered Most Users are not on local LAN - not dependant upon AD
  • Slide 5
  • Primary Steps: Enable International options (SQL Server) Establish the users preferred culture Respond to the users culture Resources and Formatting Resource translation Test and Maintain system
  • Slide 6
  • SQL Server Issues: Enable Unicode Establish the Collate options
  • Slide 7
  • SQL Server 2005 Default Internationalization Settings Default internationalization behavior is determined by: SQL Installation Install asks for default Character set and Collation - Affects System database Choosing Unicode would double system databases - Hard to change after SQL Server is installed Suggest using DEFAULTS: Windows Latin-1 char. Set Latin1_General collation Defining a new database Defaults to model database - which defaults to SQL Installation Char set/Collation unless model database has been altered Suggest using DEFAULTS:
  • Slide 8
  • SQL Server 2005 Data Columns Use Unicode datatypes in: Table columns, CONVERT() and CAST() operations nchar nvarchar nvarchar(max) ntext Catalog view sys.types reports length in bytes, not characters Substitute: ASCII() and CHAR() with: UNICODE() and NCHAR() Define variables and parameters of Stored Procedure and triggers in Unicode Prefix Unicode string constants with the letter N Important even if the column name being references is Unicode: e.g. EXECUTE Product_Info @name = NChain
  • Slide 9
  • SQL Server 2005 Unicode SQL Server 2005 uses UCS-2 Some characters not included: Additional Chinese characters SQL Server stores these as: supplementary characters - stored as two unified Unicode character Supplementary characters sorted in 90 series collations: Japnese_90 Korean_90 Chinese_PRC_90Chinese_PRC_Stroke_90 Chinese_Taiwan_Bopomofo_90Chinese_Taiwan_Stroke_90 Chinese_Hong_Kong_Stroke_90_CI_AS
  • Slide 10
  • SQL Server 2005 Collation SQL Server 2005 uses two collation Types Windows Collation Defined to support Windows locales Uses the same code pages, sorting, comparisons as an application on a Windows system Recommended if you mix Unicode and non-Unicode columns in the database applies Unicode based sorting rules to both Unicode and non-Unicode data (internally converts non-Unicode data to Unicode for comparison operations), unlike SQL Collations Default setting Latin1_General supports 33 locales SQL Collations Legacy for prior SQL versions Sorts Unicode fields as Unicode, and non-Unicode as non-Unicode
  • Slide 11
  • SQL Server 2005 Sorting Order Sort order concepts Three sort values Primary value basic character ignoring case and accents Secondary value A = a Tertiary value - typically accents Options: Case Sensitive Accent Sensitive Kana sensitive distinguish between Japanese Kana and Hiragana Width sensitive - distinguish between half-width and full-width chars. BinaryBinary Code
  • Slide 12
  • SQL Server 2005 SQL statements Specifying Collation in SQL Collate clause: Example: SELECT name FROM customer ORDER BY name COLLATE Japanese_Unicode Append options: _CS_CICase sensitiveCase insensitive _AS_AIAccent sensitiveAccent inensitive _KSKana sensitive, if omitted, Kana insensitive _WSWidth sensitive, if omitted, width insensitive Examples: Latin1_General_CI_AS
  • Slide 13
  • Establish the Users preferred culture
  • Slide 14
  • Culture Description of a language, and OPTIONALLY a region System.Globalization.CultureInfo class Culture string representation based on RFC 1766: languagecode2[-country/regioncode2[-script]] Examples: en represents neutral English en-GB represents UK English CultureInfo object Invariant:absence of culture (may be English) NeutralenLanguage NOT specific to a particular region Specificen-GB Language in a specific region, and region info, e.g., formatting
  • Slide 15
  • Default International behavior Default internationalization behavior is determined by: - CurrentCulture and CurrentUICulture Determined from either: CultureInfo class, or the current thread Assigned only from the current thread CurrentCulture must be a SPECIFIC culture: default culture for System.Globalization affects culture specific formatting (date/time, number,currency, AND display of Calendar control) CurrentUICulture Can be neutral or specific culture: default culture used by ResourceManager
  • Slide 16
  • Setting the Culture Web.config Or, Page Automatic (browsers first requested culture) with default: Programmatically: Analyze complete list of browsers culture requests Based upon setting in the Users Profile
  • Slide 17
  • Setting the Culture Collation SQL Server 2005 Collations Two types: Windows Collations recommended Based upon Windows locales attempt to match SQL Server 2005 and Windows locales Default Latin1_General SQL Collations -- Legacy with prior version of SQL Server Called very early in the page life cycle: - before ALL page events - during the FrameworkInitialize method before controls are created Can set culture based upon LCID instead of Culture Name - useful for alternative Sort Orders
  • Slide 18
  • Set Culture reviewing all culture requests from the browser Matching browsers culture requests: Automatic method:
  • Set Culture reviewing all browser requests CODE Sample Iterate through the browsers requested cultures Part 1 of 2 (Sample taken from.NET Internationalization book, pp 148-9) protected override void InitializeCulture() { if (Request.UserLanguages != null && Request.UserLanguages.GetLength(0) > 0) { foreach (string userLanguage in Request.UserLanguages) { CultureInfo cultureInfo = GetCultureInfo(userLanguage, true); if (cultureInfo != null) { Thread.CurrentThread.CurrentUICulture = cultureInfo; Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureInfo.Name); break; } } } }
  • Slide 20
  • Set Culture reviewing all browser requests CODE Sample Iterate through the browsers requested cultures -- Part 2 of 2 (Sample taken from.NET Internationalization book, pp 148-9) protected virtual CultureInfo GetCultureInfo( string userLanguage, bool useUserOverride) { int semiColonIndex = userLanguage.IndexOf(";"); if (semiColonIndex != -1) userLanguage = userLanguage.Substring(0, semiColonIndex); try { return new CultureInfo(userLanguage, useUserOverride); } catch (ArgumentException) { return null; } }
  • Slide 21
  • Set Culture Using Culture Information from User Profile User Profile : Store users preferred culture information in the ASP.NET 2.0 Membership/Profile system For each page, or using a new base class for all pages (Except the Logon-on pages) See: Core Internet Application Development with ASP.NET 2.0 page 971
  • Slide 22
  • Resource Code Formatting Respond to the Users preferred culture
  • Slide 23
  • Resource Code
  • Slide 24
  • Setting the Culture - Page InitializeCulture method for a page Method is new to ASP.NET 2.0 Called very early in the page life cycle: - before ALL page events - during the FrameworkInitialize method before controls are created Can set culture based upon LCID instead of Culture Name - useful for alternative Sort Orders
  • Slide 25
  • Resource code Managers ASP.NET Built-in: System.Resources.ResourceManager Uses standard.resx format Easily handled by localization firms Directly supported in VS 2005 Built-in tool to generate.resx files from non-localized ASP.NET project Cached good performance Custom resource managers Directly use SQL Server Slower performance
  • Slide 26
  • Creating Resource Files VS 2005 Tool Visual Studio 2005 tool: Generate Local Resources Generates resource file for a particular page -- from Design view Tools > Generate Local Resoruces Automatically creates.resx file that includes all properties marked: Localizable(true) By default, most Webcontrols: Text, Title, ToolTip NOT HTLM controls, except: HtmlAnchor, HtmlImage HtmlInputImage, HtmlTitle Automatically modifies the page source Does NOT work with raw HTLM, e.g.: text can substitute Localize control
  • Slide 27
  • Resource File Hierarchy The Generate Local Resource tool only creates the default page resource files. You must copy the default resource files and rename then to create the language resource hierarchy.