Wednesday 9 February 2011

ASP: Multilingual web sites (AddHeader, CodePage and CharSet)

   


I've been working with multilingual web sites for a long time and - believe me - they sometimes are not so easy to manage. At the moment, one of the sites I manage, lets the user choose between 8 languages (including Cyrillic).
One of the issues you might have to face when dealing with languages, is how to manage charsets. I know there's a lot of talking about it, especially in relation to specific browsers and characters rendering. The only thing I remember is that it was a real pain! Being completely sure on how the web page was rendered seemed to be almost impossible.

Some tech forums and informational web sites make things easy, but in reality you might end up banging your head to the wall in despair. So here I am to give my solution (which in the end is quite simple).
In order to be sure to manage all languages and charset, you should include in your pages - every page - the following snippet:
<%Response.ContentType = "text/html" 
Response.AddHeader "Content-Type", "text/html;charset=UTF-8" 
Response.CodePage = 65001 
Response.CharSet = "UTF-8"%>
The page of your site should be created using UTF-8 as charset. That means you should have
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
in the <head> of your document.
And that is all.

If you want to understand what's behind the code, please refer to this MSDN page.

0 thoughts:

Post a Comment

Comments are moderated. I apologize if I don't publish comments immediately.

However, I do answer to all the comments.