25
Localization Support in Microsoft .NET Framework François Liger Program Manager Microsoft Corporation

Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Embed Size (px)

Citation preview

Page 1: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Localization Support in

Microsoft .NET Framework

François LigerProgram Manager

Microsoft Corporation

Page 2: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Key Terms (as used in this talk)

Globalization (a.k.a. Internationalization) Core application handles international data

Character encodings Date and time, numeric, currency formats …

Market adaptation Additional functionality for a given market

Localization = translation Localizable = ready for translation Resources

Application elements (error messages, UI) to be translated in localized versions

Page 3: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

.NET Framework Namespace

System

System.Data System.Xml

System.Web

Globalization

Diagnostics

Configuration

Collections

Resources

Reflection

Net

IO

Threading

Text

ServiceProcess

Security

Design

ADO

SQLTypes

SQL

XPath

XSLT

RuntimeInteropServices

Remoting

Serialization

Serialization

Configuration SessionState

Caching Security

ServicesDescription

Discovery

Protocols

UIHtmlControls

WebControls

System.Drawing

Imaging

Drawing2DTextPrinting

System.WinForms

Design ComponentModel

Page 4: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

System.Resources namespace ResourceManager

Provides access to culture-correct resources at runtime.

ResourceWriter Writes resources to an output stream or file

ResourceReader Reads resources name-value pairs from

resources files and streams ResourceSet

Stores all resources localized for a particular culture

Page 5: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

System.Globalization.CultureInfo Provider of cultural preferences Two roles

CurrentCulture Date and number formatting String comparison and casing

CurrentUICulture Resource selection for user interface

Can be controlled on a per thread basis RFC 1766 derived hierarchy CultureInfo.CreateSpecificCulture

Optional mapping from neutral to specific

Page 6: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

CultureInfo Neutral culture

Based on language Resource only No formatting CurrentUICulture only

Specific culture Based on language & region Resource & Formatting specifics CurrentCulture & CurrentUICulture

Page 7: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Resource Model .NET Framework uses a new resource

model ResX file format Resources files Satellite Resources DLLs

Naming conventions Resource Fallback

Page 8: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

ResX Files Simple, (almost) human-readable XML

format Can include arbitrary objects Created with .NET Framework SDK Can also be created with Visual Studio

See other talk on this topic

Page 9: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Resource generation process .resx file

XML-based file Describes resources

.resources file binary compiled file

Satellite .resources.dll: Embedded .resources

file(s)

.resx file

.resources file

.resources.dll file

Page 10: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Naming convention Naming pattern conventions

.resources files: <myproject>.<xx-XX>.resources

Satellite assemblies <myproject>.resources.dll

Directory locations for satellites: A subdirectory per culture either neutral or specific cultures can be used Myproject.dll

\fr\myproject.resources.dll (neutral) \de-DE\myproject.resources.dll (specific)

Page 11: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Resource Fallback

Main Assembly•Code•Default resources (fallback)

Greeting=“Hello”Farewell=“Goodbye”Logo=<graphic data>

French•No code•“fr” resources

Greeting = “Bonjour”Farewell = “Au revoir”

French (France) (fr-FR)•No code•“fr-FR” resources

Greeting=“Salut”

Page 12: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Loading Resources Creating a Resource Manager

The RM constructor indicates the file from which resources are to be loaded.

Several alternatives Load from a loose .resources file Load from this assembly Load from another assembly Load from a custom resource format if you write

your own resource manager (e.g. a database)

See .NET SDK, Samples and Tutorials, ASP.NET QuickStarts, and How Do I … samples

Page 13: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Loading Resources, continued

Resource manager can be used to load both strings and objects: RM.GetString (“mystring”, new CultureInfo(“en-NZ”) ) RM.GetString (“mystring”) RM.GetObject(“Button1.Cursor”)

Loads requested resources based on Thread.CurrentThread.CurrentUICulture

Fallback hierarchy derived from RFC 1766

Page 14: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Localization Process Start with a .txt or a .resx file

.txt files (string data only) .resx files (string data and arbitrary objects) XML tools can be used with .resx files External localization tools vendor support

Lionbridge, http://www.lionbridge.com WinRes

Resize WindowsForms forms WinRes does not require access to source Visual Studio IDE: integrates this capability

ResGen: Compile data to .resources binary files

Page 15: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Localization Process AL (or compiler):

add .resources into assembly. (AL is an SDK linker)

al /t:lib /culture:en-NZ /embed:strings.en-NZ.resources /out:myapp.resources.dll

Optional: use SN for strong-naming VS IDE : add translated .resx file into

project

Page 16: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

ASP.NET And Localization ASP.NET has a flexible resource model

There is not one single way to organize localizable resources

Applications vary; developers can choose. The following section shows a few

alternatives. .NET Framework SDK has additional samples

ASP.NET QuickStarts, localization section, working with resources files.

Page 17: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

ASP.NET Localization OptionsA: Resources included in source (like ASP) Copy of each page per language Specify culture in page directive or web.config

Advantages: Good for static content Rapid initial development

Disadvantages: High maintenance costs Not suitable for dynamic content Localizers and developers are working on the same

source file. Potential for conflicting updates

Not recommended

Page 18: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

ASP.NET Localization OptionsB: Resources separated from source Use Resource Manager to load resources

• Resources could be in • Loose .resources files• Satellites below each main assembly• A separate (parallel) main assembly with satellites below

it

• One .resources file or satellite per language

• Slightly different ResourceManager constructors for each case

Page 19: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

ASP.NET Localization Options

B: Resources separate from source, continued:

Advantages: Can deploy additional languages incrementally, without

redeploying core code Lower maintenance costs, as there is one central app, not many

parallel versions.

Disadvantages: More files Loose .resources can have locking issue.

No locking issue for satellites or parallel main assembly with satellites.

Shadow-copying done for exes and dlls (main assemblies and satellites).

Samples: ASP.NET Quickstarts, Localization section

Page 20: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

ASP.NET Localization OptionsC: Satellite Resource DLLs Advantages:

Can deploy additional languages incrementally, without redeploying core code

Lower maintenance costs, as there is one central app, not many parallel versions.

Shadow-copying done for exes and dlls (main assemblies and satellites).

Disadvantages: More files Added initial application development complexity

Page 21: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Demo Localizing a WebForm application

Page 22: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Summary .NET Framework provides built-in support for

localization and globalization ASP.NET builds on Framework support for

international app development More options for specifying encoding Can separate code from resources Can utilize .NET Frameworks classes Developers can develop/host multi-cultural apps on a

single server Visual Studio makes it easier to build localized

apps See Achim Ruopp’s talk

Page 23: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Additional References .NET Framework SDK Tutorial:

Resources and localization (includes tools)

.NET Framework SDK Samples ASP.NET Quickstart Localization section WinForms Quickstart Localization sample How Do I … samples: Resources

Globalization

.NET Framework SDK Tools: ResGen, WinRes, AL, SN

Page 24: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Additional References Documentation

.NET Framework SDK: Developing World-Ready Applications

Visual Studio : Visual Studio.NET\Visual Basic and VisualC#\

Globalizing and Localizing\Walkthroughs General info on .NET Framework:

http://msdn.microsoft.com/net http://www.GotDotNet.com

Page 25: Localization Support in Microsoft.NET Framework François Liger Program Manager Microsoft Corporation

Questions ?