For a website that supports multiple languages, it is important to tell the client what the selected language is. This is done in the <html> tag in the lang or xml:lang attribute and could look something like this for an XHTML document:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" xml:lang="en-US">

The DOCTYPE and <html> tag is usually static text that doesn’t get generated by the server, but for localized websites we need to adjust the lang or xml:lang attribute to make it correspond to the selected language.

In ASP.NET this is very easy because the thread knows about the selected language, so all we have to do is to print it out in the attribute in the <html> tag. You can do it easily by inserting directly on the aspx page like so:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" xml:lang="<%=Thread.CurrentThread.CurrentCulture.IetfLanguageTag %>">

As long as you remember to set the selected language, or culture as it’s called in .NET, on the executing thread it will work. You can set it up globally in the web.config or do it manually like so:

CultureInfo lang = CultureInfo.CreateSpecificCulture("en-US");

Thread.CurrentThread.CurrentCulture = lang;

Thread.CurrentThread.CurrentUICulture = lang;


Comments are closed