Click here to Skip to main content
13,293,950 members (61,456 online)
Click here to Skip to main content
Add your own
alternative version


34 bookmarked
Posted 23 Aug 2004

Create multilingual web pages very easily

, 23 Aug 2004
Rate this:
Please Sign up or sign in to vote.
Create multilingual web pages very easily, without using localization and resources.

Sample Image - The page in German

Sample Image - The page in english


This article describes, how you can write multilingual web pages in an easy way, without using resources or localizations.

This article doesn't describe how you can translate a word or sentence from any language to another!


I am developing a big web application in the company I work for and the application should be multilingual.

In the complete project, we have a COM-component that translates words or sentences from any language to another. The basic mechanism of this component is a big text file and a hashlist.

I my example project, there exists an instance of a translation class with example translations. In real life, this is the instance of the translation-COM-component! Here you should write your own solution!

The base and default language in my example project is German. I use a session-variable to store the actual language over the session, and global for the complete web application. The switch-language-dropdownlist can be placed in a menuframe. Server side code should only refresh all frames to switch language on the fly.

Using the code

First step is to take the class CMLPageControl into your project. Copy the file CMLPageControl.vb in the project directory, and add the following lines to the vbproj-file.

    RelPath = "CMLPageControl.vb"
    SubType = "ASPXCodeBehind"
    BuildAction = "Compile"


All your WebForms must be derived from this class:

Public Class WebForm1
 Inherits CMLPageControl
End Class

Third and last:

To translate texts, you should put between the translation tags <ML_TAG> and </ML_TAG>.

<asp:Label id="Label1" runat="server">
  <ML_TAG>Hallo, hier wird demonstriert</ML_TAG>
<asp:Label id="Label2" font-bold="True" runat="server">
  <ML_TAG>wie man on the fly die Sprache wechselt!</ML_TAG>
<asp:Button id="Button1" runat="server" Text="<ML_TAG>Drück mich</ML_TAG>">
<asp:CheckBox id="CheckBox1" runat="server" 

          Text="<ML_TAG>Klick mich</ML_TAG>">

The translation-tag is defined as a constant in the base class.

Imports System.ComponentModel
Imports System.Web.UI

<DefaultProperty("Text"), ToolboxData("<{0}:CMLPageControl _
        runat="server"></{0}:CMLPageControl>")> _
        Public Class CMLPageControl _
        Inherits System.Web.UI.Page

End Class

The solution

The base class is a custom control to overload the Render method.

One problem is to agree the ready rendered HTML-code of the page including all sub user controls and placeholders and so on. I solved this problem while I creating my own HtmlTextWriter-Object and let the base class System.Web.UI.Page render the page in my writer. Now, I can get the HTML as string to translate all texts between the translation tags.

Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
  ' generate your own writer
  ' without this, you don't have a chance
  ' to get the rendered HTML-Code
  Dim oStringBuilder As New System.Text.StringBuilder
  Dim oWriter As New System.Web.UI.HtmlTextWriter(New _

  ' Render HTML-Code

Second problem was that the Render-methods of all .NET controls replace the brakes < and > from the translation-tags by &lt; and &gt;, if the text is set in code behind instead of the static presentation tier (aspx- or ascx-file). Example:

List1.Items.Add(New ListItem("<ML_TAG>Deutsch</ML_TAG>", _
List1.Items.Add(New ListItem("<ML_TAG>Englisch</ML_TAG>", _

To solve this, the translation routine is called twice. First to find all "normal" translation tags <ML_TAG>, second to find all modified translation tags &lt;ML_TAG&gt;.

' translate the page and write the result to the stream
output.Write(TranslatePage(TranslatePage(oStringBuilder.ToString(), _

The translation itself is a very simple search and replace. I think here is a great tuning potential. But in my real customer application, the translation of page with 200-300KB rendered HTML-code needs a duration of < 0.1 seconds. Most of the time is needed to find the text in the translation-component. The data behind this a 2MB text file.

Points of Interest

If you make mistakes while using the translation-tags (i.e., forget closing-tag or syntax error), the translation parser shows you the point of the mistake.

In the next screenshot, a start tag has a writing error:

<asp:Label id="Label1" runat="server">
  <ML_xTAG>Hallo, hier wird demonstriert</ML_TAG>

Detecting mistakes in translation tags


Initial version.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Stephan Pilz
Web Developer
Germany Germany
I started 1987 when I was about 14 years old, with Basic and Pascal on 8Bit Atari with insanely 130KB of memory, later 16Bit Atari (4Megs). In study I learn C, C++, Modula-2, Assembler and other science languages (Prolog, ADA). I hold a german engineer's degree Dipl.-Ing. (FH) in "Technical Computer Science" from the University of Applied Sciences Mittweida, Germany (comparable with a Master Degree).

Now I develop PPS and Supply-Chain-Software for middle and great companies in Chemnitz/Germany with Web- and MFC-Frontends in C, C++, ASP.NET, ADO.NET, XML, HTML, JavaScript.

My main tasks are specify and write down solutions of problems and implement the first code snippets.

In my spare time I like to drive a (fast) motocycle, read many science fiction and fantasy books and I'm a enthusiastically shotokan karate fighter. In winter I falling down from hill with alpin ski on foots, because snowboards are only for drug sniffers Wink | ;-)

You may also be interested in...


Comments and Discussions

GeneralAtlas UpdatePanel problem Pin
vlad.pitaru18-Dec-06 10:25
membervlad.pitaru18-Dec-06 10:25 
GeneralRe: Atlas UpdatePanel problem Pin
Stephan Pilz18-Dec-06 21:37
memberStephan Pilz18-Dec-06 21:37 
QuestionHow to enter data in particular language itself Pin
tnsentil12-Oct-06 6:26
membertnsentil12-Oct-06 6:26 
AnswerRe: How to enter data in particular language itself Pin
Stephan Pilz12-Oct-06 22:01
memberStephan Pilz12-Oct-06 22:01 
GeneralRe: How to enter data in particular language itself Pin
tnsentil12-Oct-06 23:41
membertnsentil12-Oct-06 23:41 
GeneralRe: How to enter data in particular language itself Pin
Stephan Pilz13-Oct-06 0:20
memberStephan Pilz13-Oct-06 0:20 
GeneralAnother Useful way for multilingual web pages Pin
mis003324-Jul-06 22:42
membermis003324-Jul-06 22:42 
AnswerRe: Another Useful way for multilingual web pages Pin
Stephan Pilz25-Jul-06 0:08
memberStephan Pilz25-Jul-06 0:08 
GeneralRe: Another Useful way for multilingual web pages Pin
mis003325-Jul-06 1:09
membermis003325-Jul-06 1:09 
GeneralPlease help Pin
sreejith ss nair18-Sep-05 22:11
membersreejith ss nair18-Sep-05 22:11 
AnswerRe: Please help Pin
Stephan Pilz18-Sep-05 22:45
memberStephan Pilz18-Sep-05 22:45 
GeneralRe: Please help Pin
sreejith ss nair20-Sep-05 20:38
membersreejith ss nair20-Sep-05 20:38 
GeneralSIMPLE &amp; DIRECT Pin
helif22-Feb-05 8:42
memberhelif22-Feb-05 8:42 
GeneralRe: SIMPLE &amp; DIRECT Pin
stp22-Feb-05 22:29
memberstp22-Feb-05 22:29 
GeneralRe: SIMPLE &amp; DIRECT Pin
Louisa Chen22-May-07 16:08
memberLouisa Chen22-May-07 16:08 
GeneralThis is quite brilliant! Pin
yrleu14-Jan-05 7:23
memberyrleu14-Jan-05 7:23 
GeneralRe: This is quite brilliant! Pin
stp14-Jan-05 11:32
memberstp14-Jan-05 11:32 
Generalgood method Pin
benoityip13-Sep-04 16:43
memberbenoityip13-Sep-04 16:43 
GeneralRe: good method Pin
stp13-Sep-04 21:44
memberstp13-Sep-04 21:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 24 Aug 2004
Article Copyright 2004 by Stephan Pilz
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid