Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

29
Creating Multi- lingual Applications and Websites with Microsoft Visual Studio 2005 Achim Ruopp International Program Manager Microsoft Corporation

description

Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005. Achim Ruopp International Program Manager Microsoft Corporation. Agenda. Resource Improvements Strongly Typed Resources Fallback to Satellite Assembly Editing Resources ASP.NET Localization - PowerPoint PPT Presentation

Transcript of Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Page 1: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005Achim Ruopp

International Program Manager

Microsoft Corporation

Page 2: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Agenda Resource Improvements

Strongly Typed Resources Fallback to Satellite Assembly Editing Resources

ASP.NET Localization Detecting the Browser Language Declarative Localization Model with designer support Extensibility Deployment Bidirectional Web Pages

Smart Client Applications Windows Forms

Table Layout/Grid Layout Controls Bidirectional Languages Performance Improvements

ClickOnce Deployment

Page 3: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Visual Studio and .NET Framework Versions

Visual Studio .NET .NET Framework v1.0

Visual Studio .NET 2003 .NET Framework v1.1

Visual Studio 2005(code name: Whidbey)

.NET Framework v2.0 (code name: Whidbey)

Page 4: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Strongly Typed Resources Resources have types

Strings Boolean Images Audio Files …

Strongly Typed Resources What are they?

Provide ability to creates classes containing read-only properties for resources

Benefits: Eliminates mismatches between code and resource identifiers Provides Intellisense on resource identifiers ResourceManager is created for you No need to cast objects to other types

Page 5: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Resources Then and Now

private ResourceManager rm; rm = new ResourceManager("MyImages", this.GetType().Assembly); PictureBox.Image = (System.Drawing.Image)rm.GetObject("MyImage");

PictureBox.Image = ResourceFilename.MyImage;

.NET Framework v1.0/v1.1

.NET Framework v2.0

Page 6: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Fallback To Satellite Assembly Fallback

Best fit UI language for user (CurrentUICulture) Example: fr-CA → fr → fallback (e.g. de)

Additional fallback resource location v 1.0/1.1 – ResourceManager only loaded fallback

resources from the main assembly v 2.0 – Adds ability to build fallback resources in a

satellite assembly [assembly: NeutralResourcesLanguageAttribute("de" , UltimateResourceFallbackLocation.Satellite)]

Clean separation of code and user interface Useful for servicing Can potentially reduce download size for updates

Page 7: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Editing Resources

New Resource Editor Integrated in Visual Studio 2005 For .resx format Uses link syntax for complex type resources

(images, sounds, …)

XML editors and localization tools can still be used

More on Windows Forms and ASP.NET resource editing later

Page 8: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Creating and Using Creating and Using ResourcesResources

Page 9: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

ASP.NET Localization v. 1.0/1.1

.NET resource model can be used No design time assistance

v. 2.0 Uses .NET resource model Provides a simple declarative model for

localization Automatic generation of resources in designer Editing of resources using the resource editor Server side compilation of .resx files Auto-detection of browser culture

Page 10: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Detecting the Browser Language HTTP Accept-Language header v 1.0/1.1

Write code to detect browser language Specify preferred culture in web.config, page or code

2.0 Use “auto” for automatically detecting browser

language Can override in InitializeCulture() It is still possible to specify preferred culture in

web.config, page or code

<%@ Page Culture=“auto:fr” UICulture=“auto:fr-FR” .. %>

Page 11: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

ASP.NET Resources Local Resources

Use for page resources Stored in \App_LocalResources folder Generated through the designer

Tools/Generate Local Resources command used in design view of the page

Global Application Resources Use for global strings or binary types Stored in \App_GlobalResources folder Strongly-typed, available to all pages through

Resources member Default Resource format

Author .resx in the resource or XML editor Other formats possible through extensibility

Page 12: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Retrieving Resources Declaratively

Explicit or implicit expressions

Programmatic GetLocalResourceObject()/GetGlobalResourceObject()

System.Web.UI.TemplateControl Class System.Web.HttpContext Class

foo.aspx\App_LocalResources foo.aspx.resx foo.aspx.fr.resxDeclaratively: <asp:label runat="server" text="<%$ Resources:foo %>" /> <asp:label runat="server"

meta:ResourceKey="LabelResource1" %>Programmatically: foo.Text = (string)GetLocalResourceObject(“foo");

Page 13: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Expressions Declarative syntax

Access local or global resources Interpreted at parse time Explicit and implicit forms

Can be mixed, but should not collide Designer creates implicit expression syntax Explicit expressions can be edited in Expressions

property of controls

Explicit form: <%$ Resources:[classKey,]resourceKey %><asp:label runat=“server” text=“<%$ Resources:MainTitle %>” /><asp:button runat=“server” text=“<%$ Resources:MyStrings,OK_Key %>”/>

Implicit form: meta:ResourceKey=“keyprefix”<asp:label runat=“server” meta:resourcekey=“LabelResource1” />

Page 14: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Extensibility Other resource formats

Databases Existing XML formats …

Option 1: Localization expressions can be extended Subclass ResourceProviderFactory Allows design-time support for custom resource formats

Option 2: Create expression builder for new resource format Subclass System.Web.Compilation.ExpressionBuilder Design-time support only through ExpressionEditor

Deployment of e.g. a database is more difficult

Page 15: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Deployment ASP.NET v2.0 has 3 compilation models

Uncompiled Source files including .resx files are copied to server Resources are compiled on server Compiled resources are cached on first use

Precompiled excluding markup Deploy .resx/.aspx files like in uncompiled case Page design changeable Global resource satellite assemblies precompiled

Precompiled including markup Page design cannot be changed Everything precompiled into assemblies

Additional languages can be added in all 3 models Application domain needs to be restarted

Page 16: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Bidirectional Web Pages Direction property on <asp:panel>

Can be explicitly defined Can be loaded using a resource expression Useful for mixed left-to-right/right-to-left pages

Full right-to-left pages Set DIR attribute on HTML tag using an explicit resource expression

<asp:panel runat=“server” meta:resourcekey=“MainTitle” />

<data name=“MainTitle.Direction”> <value>RightToLeft</value></data>

Page 17: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

ASP .NET LocalizationASP .NET Localization

Page 18: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Windows Forms Localization v1.0/v1.1 Each form has a Localizable property

Creates single .resx file for default resources Each form has Language property

Creates one additional .resx file per selected language Edit source/localized .resx files in

Visual Studio Windows Forms designer XML editor WinRes tool (.NET Framework SDK tool)

Images serialized into .resx file Pulled each localizable property from the .resx file Built satellite assemblies directly in VS Setup projects available in 9 languages

Page 19: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Windows Forms Localization v2.0 Localizable/Language properties remain the same

One .resx file per form per language Edit source/localized .resx files in

Visual Studio Windows Forms designer WinRes tool (.NET Framework SDK tool) Visual Studio Resource Editor XML editor

Images Linked into .resx files rather than serialized Default to application-wide .resx file

New code generation using the ComponentResourceManager improves performance

New layout functionality reduces resizing during localization Deploy Click Once projects in any language

Page 20: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Localize Without Resizing

v1.0/v1.1 Use docking and anchoring properties

new layout controls in v2.0 Use TableLayoutPanel for

Resizing a group of controls proportionallyDynamically generating UI with customizable fieldsCreating a fixed size UI while still allowing

localization Use FlowLayoutPanel for

Creating a series of horizontal controls which may wrap vertically but aren’t proportional to each other

Mechanism for “bumping” controls relative to other controls

Page 21: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

RightToLeft Languages RightToLeft property (v 1.0/v 1.1/v 2.0)

Determines reading order for text Affects layout for some controls

RightToLeftLayout (v 2.0) Determines layout of controls Form, TabControl, TreeView, ListView, TrackBar,

ProgressBar, MonthCalendar and DateTimePicker Does not inherit down control hierarchy

Controls support full “mirroring” Set both RightToLeft and RightToLeftLayout

Determining text direction for culture CultureInfo.TextInfo.IsRightToLeft

Page 22: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Click Once New deployment mechanism

versioning update service installation over the web …

Deploy multiple languages from a single project Language property determines

language satellite assemblies language external dependencies ClickOnce language resources (.xml files)

Can extend ClickOnce resource languages by localizing setup.xml

Page 23: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Layout Controls and Layout Controls and ClickOnceClickOnce

Page 24: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

References Visual Studio 2005/.NET Framework v2.0

http://lab.msdn.microsoft.com/vs2005/

Microsoft Globaldev website http://www.microsoft.com/globaldev/

Newsgroup news:microsoft.public.dotnet.internationalization

Blogs http://blogs.msdn.com/michkap http://blogs.msdn.com/AchimR http://www.dasblonde.net/ http://blogs.msdn.com/BCLTeam

Page 25: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005
Page 26: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

AppendixASP.NET Localization Expressions

Page 27: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Implicit Expressions

Used to partially or fully localize an ‘object’ with minimal syntax Controls, sub-objects, page directive

Only used to access local resources Generated by the designer

Page 28: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Implicit Expressions Runtime

Default .resx interrogated for keyprefix and properties set

Key: filter, keyprefix, control property, sub-property Design-time

Control properties marked [Localizable(true)] are ‘pushed’ to .resx

<asp:label runat=“server” meta:resourcekey=“MainTitle” />

<data name=“MainTitle.Text”> <value xml:space=“preserve”>Welcome to the site</value></data><data name=“MainTitle.Font.Bold”> <value>true</value></data>

Page 29: Creating Multi-lingual Applications and Websites with Microsoft Visual Studio 2005

Explicit Expressions Used on any control or object property Fine-grained handling for properties which are not

localizable by default Can be used for HTML attributes Access global or local resources Runtime

Used to obtain resource value and perform property assignment

Design-time Developer can create expressions against control

properties in “Expressions…” dialog