Scott on Writing

Musings on technical writing...

DEV392: Building Applications with Globalization in Mind

Notes from Michele Leroux Bustamante's TechEd 2004 break-out session "Building Applications with Globalization in Mind." (The slides and code for this talk should be available from her blog; see the comments for a direct link.) Michele is a globalization expert and has written an article on said topic on MSDN online (see Globalization Architecture for ASP.NET). For more information on globalization check out the Ask Dr. International or Microsoft .NET Internationalization sections on MSDN. The following is an outline of Michele's talk.

  • What is Globalization? (Separating culture dependencies from code; content translation).
  • Locale / Culture is represented by a language code and country code (i.e., en-US, en-UK, es-EC, etc.). There are ISO codes for language and country. RFC 3066 specifies tags for identifying languages.
  • What to Localize and How to Store Localized Content?
    • Static content - menu captions, control captions, Web page content, etc.
    • Dynamic content - content populated at runtime. Need to have location of content to be organized by culture, and things like queries or filenames may differ based on culture.
    • Things to consider:
      • Windows vs. Web app
      • How often the content changes
      • Where to place culture-specific information (resource files, XML files, database)

A Windows Forms assembly contains resource information. We can also have satelite assemblies that store resource information for a particular culture. These satelite assemblies can be dropped in independent of recompiling the application. In addition to satellite assemblies, some content will likely need to be placed in a database. The database table names should be named according to the ISO standard country/language codes - perhaps by suffixing the table name with code.

For Web apps, typically a site's pages are duplicated for globalized apps. That is, a set of Web pages for each locale supported. Usually implemented as subdirectories - www.yoursite.com/en/*, www.yoursite.com/es/*, etc. These directories would contain locale-specific translations, images, etc. A better approach is to use a single content base with satelite assemblies that contain the locale-specific information.

  • What are .NET Resources?
    • Resources are generated via an XML resource file (.resx).
    • Automatically generated by VS.NET for each Windows Form and Web Form
    • By default, compiled and embedded in project assembly
    • Can add custom resources to the project
    • Can build assemblies that contain shared resources
    • Can manually edit the .resx files via VS.NET
    • The resource information is stored in the assembly's manifest - can view this information via ILDASM.
  • Localizing Windows Forms applications
    • Can set a WinForm to Localizable via the Properties pane. This adds a ResourceManager in the code section.
    • Can also specify the language via the Language option in the Forms' properties pane.
    • The invariant culture is stored in the assembly - culture-specific information is stored in satelite assemblies. The satelitte assemblies are in appropriately named folders in the same directory as the project assembly.
    • Satelite assemblies contain only resources - no code.
    • Runtime follows a "resource fallback process" to find closest match - i.e., en-US rolls back to en rolls back to the invariant culture.
    • In addition to satelite assemblies with locale-specific information, could also have other assemblies with common error messages. To create these, build a Class Library project with no code, just resource information.
    • VS.NET / runtime are very picky on resource file naming conventions.
    • The satelite assembly used depends on the culture setting of the executing thread's culture information.
    • Can use the NeutralResourcesLanguageAttribute attribute to specify a default resource rather than relying on the runtime's fallback technique.
    • WinForms control properties automatically sotred in embedded resources. Allows translators toedit individual form layout without touching your code. Other content can be stored in shared resources.
  • Accessing Resources via System.Resources.ResourceManager
    • Access specific resource type based on a Form, strings, errors, etc. Specify the typeof ResourceManager and then can request resource entries by key name.
    • The GetString()/GetObject() methods gets the specific resource by name using the fallback technique. Can also use GetResourceSet() to get all resources for a particular culture.
    • The current thread's culture setting dictate resource selection via the CurrentUICulture and CurrentCulture properties. CurrentUICulture touches the satelite assembly to load resources; CurrentCulture does not access resource information, but dictates how things like date/time information is formatted, how currency is formatted, etc.
  • Localizing ASP.NET Web Applications
    • Option #1: Duplicate Content
      • Facilitate rapid 1.0 release, deal with translation later
      • Translate content for each culture in Web Forms, User Controls, HTML pages, XML files, etc.
      • Redirect user to localized set of pages via browser's accept language HTTP header
      • Duplicate content is error prone, since translators must edit content source.
      • Typically implemented via culture-specific directories - www.yoursite.com/en/*, www.yoursite.com/es/*, etc.
      • Can set culture and UI culture settings via <globalization> element in maching.config/Web.config; can also do it on a page-by-page basis via the @Page directive
    • Option #2: Single Content Base
      • One code base; low impact on future translations
      • Dynamic page content sotring locale-specific information in resource files, databases, XML files, etc.
      • XML resource files provided for Global.asax and each Web Form - embedded in main assembly. Michele recommends placing static page content in database rather than in resource for each Web page.
      • Browsers send an Accept-Language HTTP header; can use this to set the current culture on the thread rendering the ASP.NET page. Might also want to let user select culture, to override browser setting. Need to reset the thread's culture on each and every trip to the server.

Another great talk from Michele. Being an ASP.NET guy, I was most interested in the globalization for ASP.NET applications. The track looked at both WinForms and Web Forms applications, but focused more on WinForms, unfortunately (for me). Check out the blog's comments for a direct link to the slides and code.

posted on Thursday, May 27, 2004 10:20 AM

Feedback

# re: DEV392: Building Applications with Globalization in Mind 5/27/2004 7:36 PM Scott Mitchell

The slides and support material are available on Michele's blog at:
http://www.dotnetdashboard.net/sessions/globalization.aspx

# Building Applications with Globalization 6/4/2004 7:16 AM Yuri Vanzine

Some traditional techniques of asp.net globalization of web apps fall short of expectations. One of them is use of satellite assemblies. You do not want to use them for language content. Recompile your dlls, every time a label is changed? What about allowing prompt translation of content or adding a new language? Replace satellite assemblies with filesystemwatched xml resources as prompted by Mr. Wilson of wilsondotnet.com.

Another issue is do you put your data in xml or in database? The answer is maintain both for flexibility. Have small highly hierarchical data? Xml is the answer. Have large tabular data? Put it in database.

See http://webserver3.tft.com/languages.aspx for supported languages. The web app that I wrote is supporting ALL .NET specific cultures.

I agree with Michele on idea of rapid rollout and subsequent support of translation. You SHOULD plan addition of new languages with .NET. Otherwise you are not taking full advantage of the great framework.

If further discussion is needed, contact me at yuri@vanzine.org.

# TechEd Wrapup 6/9/2004 2:33 PM Scott on Writing

# re: DEV392: Building Applications with Globalization in Mind 7/21/2005 6:25 AM Dave

Great post Yuri - thanks for the information. No comments Scott?

# re: DEV392: Building Applications with Globalization in Mind 7/21/2005 12:47 PM Scott Mitchell

Dave, comments about what? Yuri's comments? I agree with them.

Interestingly, I have been working on and off on a project where localization is important. Rather than doing resources/sat. assemblies, the architecture present uses databases. There's a table that ties together a page's elements - Labels, Button text, etc. - to a 'string label', which is joined to another table that provides the translations for each of those 'string labels.'

When a particular page is loaded up it takes the logged on user's language setting and queries the database for all 'strings' for that current page for the specified language. This result is stored in a StringDictionary, which is then enumerated and applied to the elements on the page automatically. It's all done in a base class so basically translation works without having to write a lick of code. The only challenge is ensuring that there is synchrony between the names of the translate-able elements on the page and the 'string label' names in the database.

# re: DEV392: Building Applications with Globalization in Mind 10/28/2005 5:10 AM G.I.

I have a question about storing translations in a database: When you are using a website, all is about performance. The client doesn't want to wait so long before he sees the page. One of the bottlenecks in this picture is networking. And often you have your database on another server. Which means that for every page you have to get all the translations over the network to the server. This is a lot of overhead I think. I think storing translations locally on the webserver is the best way.

Title:  
Name:  
Url:
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments   

Add To Your Reader

My Links

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<May 2008>
SMTWTFS
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

Comment Stats

DayTotal% of Total
Sunday 1866.8%
Monday 37913.9%
Tuesday 45316.7%
Wednesday 50418.5%
Thursday 53519.7%
Friday 49418.2%
Saturday 1666.1%
Total 2717100.0%

Hour1Total% of Total
12:00 AM 652.4%
1:00 AM 682.5%
2:00 AM 622.3%
3:00 AM 742.7%
4:00 AM 572.1%
5:00 AM 1033.8%
6:00 AM 1084.0%
7:00 AM 1585.8%
8:00 AM 1716.3%
9:00 AM 1475.4%
10:00 AM 1716.3%
11:00 AM 1816.7%
12:00 PM 1886.9%
1:00 PM 1696.2%
2:00 PM 1605.9%
3:00 PM 1324.9%
4:00 PM 1073.9%
5:00 PM 923.4%
6:00 PM 913.3%
7:00 PM 963.5%
8:00 PM 833.1%
9:00 PM 782.9%
10:00 PM 792.9%
11:00 PM 772.8%
Total 2717100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 5.54144
Monday 5.22339
Tuesday 4.28419
Wednesday 7.67637
Thursday 6.90607
Friday 5.48411
Saturday 5.33160
Total 5.842717

Hour1 Entry MadeAvg.Total
12:00 AM 5.0035
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 7.0035
8:00 AM 5.35107
9:00 AM 6.32278
10:00 AM 6.47246
11:00 AM 4.41181
12:00 PM 6.88330
1:00 PM 3.00111
2:00 PM 5.41222
3:00 PM 8.64285
4:00 PM 4.0589
5:00 PM 5.92154
6:00 PM 4.52113
7:00 PM 9.67174
8:00 PM 9.80147
9:00 PM 5.05111
10:00 PM 5.4265
11:00 PM 4.5732
Total 5.842717

Learn More About Comment Stats
1 - All times GMT -8...


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles