Visual Studio 2008 And Generate Local Resources

Some of the changes in Visual Studio 2008 are a bit subtle. One of them is the way the Generate Local Resources option works (Tools | Generate Local Resources is used to make a web form localizable). In both Visual Studio 2005 and 2008 Generate Local Resources adds culture="auto" and uiculture="auto" to the page’s directives. These settings make the page responsive to the browser’s language setting (in IE7 select Tools | Internet Options and click on the Languages button). This is very convenient for testing and can also be acceptable for development purposes depending on how you expect to learn your user’s language preference. However, it is slightly flawed in Visual Studio 2005. The problem is that if you set the culture and uiculture in the website’s web.config (in order to force the entire website to use a single culture) the values are overridden at the page level rendering the web.config’s values meaningless. The solution would appear to be obvious and that is to delete the culture="auto" and uiculture="auto" attributes from the page directives. This solution works fine but unfortunately Visual Studio 2005 doesn’t respect your change and the next time you run Generate Local Resources the values are restored.

In Visual Studio 2005 the simplest solution to this problem is to remember to delete the culture and uiculture attributes from the page immediately after you run Generate Local Resources. An alternative but potentially debateable solution is to set the culture and uiculture values to a valid culture that you will never use - effectively a dummy culture. Then you override the page’s InitializeCulture method and check the culture and uiculture values to see if they are the dummy culture and if they are you set the culture back to your chosen culture.

Visual Studio 2008, however, solves this problem simply by only adding the culture and uiculture attributes the first time it is run on a page and so if you delete them then they stay deleted. This is a small change to Visual Studio but it has a big impact if this is your model. Remember this is a change to the Visual Studio 2008 IDE and so you can benefit from this in your .NET Framework 2.0 applications if you maintain them using Visual Studio 2008 (because it is multi-targetting).

Technorati Tags: Visual Studio 2008, Visual Studio 2005, Generate Local Resources, Localization, Internationalization

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Guy Smith-Ferrier
Posted on: Monday, March 31, 2008 at 8:59 PM
Categories: Internationalization
Actions: E-mail | Kick it! | DZone it! |
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Related posts