Thursday, January 19, 2006

Wicked Code asp.net 2.0 -- (feature 3/5)

Feature 3: Auto Culture Handling

PROBLEM: How do we handle localization in our web sites...?

SOLUTION:
Let's look first at ASP .net 1.x:-

void Application_BeginRequest (Object sender, EventArgs e)
{
try
{
if (Request.UserLanguages.Length > 0)
{
CultureInfo ci = CultureInfo.CreateSpecificCulture(
Request.UserLanguages[0]);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
}
}
catch (ArgumentException)
{
// Do nothing if CreateSpecificCulture fails
}
}

ASP.net 2.0 (almost no code....) [Auto culture]:-

<%@ Page Culture="auto" UICulture="auto" Language="C#" CompileWith="AutoCulture.aspx.cs" ClassName="AutoCulture_aspx" %>

Obviously, there's more to localizing an entire Web site than simply enabling auto-culture handling. Auto-culture handling does not, for example, localize static Web site content. But ASP.NET 2.0 offers other new localization features as well, including the new tag for localizing static content and $ Resources expressions for loading localization resources declaratively.

No comments: