Localizing web applications
with ASP.NET 2.0
Milan Negovan
AspNetResources.com
Definitions
Let's define internationalization and localization.
Inter·nation·al·i·zation (i18n)
Adaptation of products for potential use virtually everywhere.
Efforts include:
- Date/time format
- Calendars
- Numbers
- Currencies
- Zip/postal codes
- Names and titles, etc
(Source: Wikipedia)
Local·i·zation (L10n)
The process of customizing an application for a given culture.
Localization consists primarily of translating the user interface.
(Source: MSDN)
Meet CultureInfo Class
Provides information about a specific culture, such as the names of the
culture, the writing system, the calendar used, and how to format dates
and sort strings.
You can run from CultureInfo, but you can't hide.
i18n Demo
Show off the magic of CultureInfo.
Neutral and Specific Cultures
- A neutral culture is specified by a two-letter lowercase culture code.
E.g. "fr" for French, "de" for German, etc.
- A specific culture is the culture code and two-letter uppercase
subculture code. E.g. "fr-FR" for French in France, "fr-CA" for French in Canada.
Resource Files
XML files that contain the strings that you want to translate into different languages.
You create a separate resource file for each language (e.g, English and French) or for a language
and culture (e.g. English [U.K.], English [U.S.]).
Example:
- WebResources.resx (default, or fallback)
- WebResources.fr.resx (French, neutral culture)
- WebResources.fr-CA.resx (French, specifically for Canada)
NOTE: basic name is arbitrary, but should be the same!
Global and Local Resource Files
You can read global resources from any page of your web app.
Local resources apply to only one web page. You create one local resource file per page.
Global or Local Resources (I)?
Global (pro):
- Strongly typed (!)
- Very few files to manage
- Share resources between pages
Global (con):
- Resource files get large
- Difficult to have several people work on at the same time
Global or Local Resources (II)?
Local (pro):
- Small and easier to manage for a single page
Local (con)
- Cannot share resources between pages
- Lots of files to manage which leads to a large number of assemblies
Placement of Resource Files
- Global in
App_GlobalResources folder (only in root)
- Local in
App_LocalResources folders (one in any folder)
Culture and UICulture Page Properties
Culture determines results of culture-dependent functions, e.g.
date, number, and currency formatting, etc
UICulture determines which resources are loaded for the page
Setting Culture and UICulture Declaratively
- Individual page: <%@ Page UICulture="es" Culture="es-MX" %>
- In web.config: <globalization uiculture="es" culture="es-MX" />
or
- In web.config: <globalization uiculture="auto" culture="auto" /> to detect
language and culture from users' browser settings.
Setting Culture and UICulture Programmatically
Override InitializeCulture Page method and set Thread.CurrentThread properties accordingly.
L10n Demo
String Operations
String operations can be culture-sensitive or culture-insensitive.
Use CompareInfo class methods to search, compare and sort.
Culture-Sensitive String Operations
Use to display results to the end-user.
Example: elements of user interface, such as lists, pickers, etc.
Culture-Insensitive String Operations
Used to process text internally.
Example:
- file names
- system messages
- XML tags, etc
Consider ordinal operations (next slide).
Ordinal String Operations
Ordinal search is fast and culture-insensitive.
One character is equivalent to another only if the Unicode values are the same.
Tips
- Don't use text in images
- Use nchar, nvarchar and ntext SQL types. Remember to prepend N to strings (N'foo bar')
- Do not concatenate strings. Word order may be different in other languages.
How to Choose Translation Services
Make sure they...
- use software capable of processing Unicode text
- don't change formatting of your resource files
- don't encode HTML in resource strings
- ensure translated resource file are well-formed
- ensure data integrity (no missing text)
How to Choose Translation Services (cont'd)
Make sure they...
- have worked with developers before (translating XML is not the same as translating business letters)
- understand there's little "real estate" in web pages (especially buttons and menus)
- maintain history of previous translations
- do not translate everything, but only what's new
Resources
- Developing International Software, Second Edition
- http://www.microsoft.com/globaldev
- MSDN (search for "Localization")
- http://www.AspNetResources.com
ありがとう
(Thank you!)