Quantcast

Localized Websites and the html Tag

Get the WebProNews Newsletter:
[ Business]

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 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;

Add to Del.icio.us | Digg | Reddit | Furl

Bookmark WebProNews:

Mads Kristensen currently works as a Senior Developer at Traceworks located
in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in
2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and
web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/

Localized Websites and the html Tag
Comments Off
About Mads Kristensen
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/ WebProNews Writer
Top Rated White Papers and Resources

Comments are closed.

  • Join for Access to Our Exclusive Web Tools
  • Sidebar Top
  • Sidebar Middle
  • Sign Up For The Free Newsletter
  • Sidebar Bottom