Getting Started
  Introduction
  What is ASP.NET?
  Language Support

ASP.NET Web Forms
  Introducing Web Forms
  Working with Server Controls
  Applying Styles to Controls
  Server Control Form Validation
  Web Forms User Controls
  Data Binding Server Controls
  Server-Side Data Access
  Data Access and Customization
  Working with Business Objects
  Authoring Custom Controls
  Web Forms Controls Reference
  Web Forms Syntax Reference

ASP.NET Web Services
  Introducing Web Services
  Writing a Simple Web Service
  Web Service Type Marshalling
  Using Data in Web Services
  Using Objects and Intrinsics
  The WebService Behavior
  HTML Pattern Matching

ASP.NET Web Applications
  Application Overview
  Using the Global.asax File
  Managing Application State
  HttpHandlers and Factories

Cache Services
  Caching Overview
  Page Output Caching
  Page Fragment Caching
  Page Data Caching

Configuration
  Configuration Overview
  Configuration File Format
  Retrieving Configuration

Deployment
  Deploying Applications
  Using the Process Model
  Handling Errors

Security
  Security Overview
  Authentication & Authorization
  Windows-based Authentication
  Forms-based Authentication
  Authorizing Users and Roles
  User Account Impersonation
  Security and WebServices

Localization
  Internationalization Overview
  Setting Culture and Encoding
  Localizing ASP.NET Applications
  Working with Resource Files

Tracing
  Tracing Overview
  Trace Logging to Page Output
  Application-level Trace Logging

Debugging
  The SDK Debugger

Performance
  Performance Overview
  Performance Tuning Tips
  Measuring Performance

ASP to ASP.NET Migration
  Migration Overview
  Syntax and Semantics
  Language Compatibility
  COM Interoperability
  Transactions

Sample Applications
  A Personalized Portal
  An E-Commerce Storefront
  A Class Browser Application
  IBuySpy.com

  Get URL for this page

Localizing ASP.NET Applications


Copy and Translate

The easiest way to localize a Web page is usually to create a copy and translate it to the target language. This works well for static content that does not require a lot of maintenance. To support this model for ASP.NET pages, you can set the Culture attribute using the Page directive. All locale-dependent methods pick up the value of the Culture attribute.

The following sample shows how to do this for three independent, localized versions of a page. The Culture property is set on each page to determine the format of the date:


<%@Page Culture="de-DE" Language="VB" %>
...
<%=DateTime.Now.ToString("f", Nothing)%>
VB

 
VB news-en-us.aspx

[Run Sample] | [View Source]
 
VB news-de.aspx

[Run Sample] | [View Source]
 
VB news-ja.aspx

[Run Sample] | [View Source]


Localization and Controls

An improvement over the simple copy-and-translate approach is to use controls to pick up the culture of the main page. In the following sample, the image of the flag and the search bar are controls. Depending on the culture of the hosting page, they render different content. To support this, the UICulture attribute is also added to each page:

VB

The flag control (Flag.ascx), for example, just uses the culture name to build the Src attribute of an <img> tag:


<%@Import Namespace="System.Globalization"%>

<script runat="Server" Language="VB">
Overrides Protected Sub Render(writer As HtmlTextWriter)
    FlagImage.Src = "../../flags/" & CultureInfo.CurrentCulture.Name & ".jpg"
    FlagImage.Alt = CultureInfo.CurrentCulture.NativeName
    MyBase.Render(writer)
End Sub
</script>

<img runat="server" id="FlagImage" />
VB

The search control (Search.ascx) uses a switch statement to initialize the values of a label and a text box, but the culture name could also be the parameter for a database query:


Sub LocalizeSearchText()
  Select Case String.Intern(CultureInfo.CurrentUICulture.Name))
    Case "en-US"
      SearchText.Text = "Clinton"
      SearchButton.Text = "Search"

    Case "de-DE"
      ...
    Case "ja-JP"
      ...
    Case Else
      SearchButton.Text = "Search"
  End Select
End Sub
VB

 
VB news-en-us.aspx

[Run Sample] | [View Source]
 
VB news-de.aspx

[Run Sample] | [View Source]
 
VB news-ja.aspx

[Run Sample] | [View Source]

Section Summary

  1. ASP.NET pages support Culture and UICulture attributes to support independent localized pages.
  2. Controls on pages can pick the culture of the page and can render culture-dependent content.


Copyright 2001 Microsoft Corporation. All rights reserved.