469,934 Members | 2,607 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

Multilanguage System (TAKE LABEL NAME) SOS

ok. im try to make a multilanguage system based on that
tutorial :


in my aspx pages all text are in labels , and i want to
take the name labels ( in one loop ) and for each label
take on the XML document the right(in the right language)
Value (text).

Above you can see what im doing , it works , however im
trying to make a function that look at all aspx and when
found a LABEL , take the value ( text) from one xml
document like the function in the end of this document.
************************************************** ********

I have created an object that will retrieve the correct
data from an XML file. The code in C# is displayed below.
using System;
using System.Xml;
namespace diffudessnet
public class XmlLang
protected XmlDataDocument X;
protected String Lang;
public XmlLang(String FileName,String
String Name
= "http://localhost/myapp/xml/"+ FileName;
X = new XmlDataDocument();
Lang = Language;

public XmlLang(String FileName)
String Name
= "http://localhost/myapp/xml/"+ FileName;
X = new XmlDataDocument();
Lang = "N";
public String GetString(String Name)
XmlNode node;
node = X.SelectSingleNode
("//main/language[@id='" +Lang + "']/" + Name);
if (node == null) return "";
string value =
return value;


This object has three methods:

XmlLang::XmlLang(String FileName, String Language)
XmlLang::XmlLang(String FileName)
String XmlLang::GetString(String Name)
To start, we will assume all XML documents are in the same
directory. In this way, they can be made inaccessible to
all users. The path of this directory is hardcoded in the
source of the object. A good alternative is using the
ConfigurationSettings.AppSettings method and saving all
values in the web.config file.

In the first version of the constructor, the name of the
XML file and the selected language are passed to the
constructor. If you want to select a name for the
document, it might be useful to select the same name as
you aspx file. The language parameter is a simple string.
Possible values are "N" for Dutch, "F" for French, "E" for
English, . The format of the XML document will be
discussed later.

The second version of the constructor will automatically
select the Dutch version of the texts. This option is very
handy if you only want to use the Dutch version, and other
languages are only planned for the future.

The method GetString(String Name) will retrieve the text
belonging to the node named Name from the XML file. All
text items in the XML document are marked by keywords. The
value of a keyword is the word in the specified language.
XML Document
< language id ="N">
<name>Naam</ name>
</ language >
< language id ="E">

Different languages are separated by the <language
id="languageid" /> tags. The languageid attribute should
be passed to the constructor of the class.
Using the class
Using the object is pretty straightforward. You create a
new instance of the object in the OnInit(.) member
function of your page object. Suppose we have a page
called client.aspx containing client data. The name of the
codebehind file is client.aspx.cs. To make things simple,
we name the xml file client.xml.

override protected void OnInit(EventArgs e)

XmlLang Lang = new XmlLang("client.xml",Session

this.NameLabel.Text = Lang.GetString("name");

this.StreetLabel.Text = Lang.GetString("street");

this.CountryLabel.Text = Lang.GetString("country");

Instead of hard-coding all static text in client.aspx, we
use labels as a replacement. In the OnInit member
function, these labels are filled with the right contents,
depending on the selected language. In this example, the
chosen language is stored in a session variable : Session
["LANGUAGE"]. The method as it is mentioned also allows
you to change column headers from a datagrid object.
************************************************** ********
-----Original Message-----
I do something very similar with all labels on a page (though I only use c#so the vb code is difficult for me to follow!). May I ask what actuallyhappens when you run this ? My first thought is that you must make theroutine recursive by calling itself on each sub-control within each toplevel control on the page.

"Giovane Calabrese" <gi*********@brturbo.com> wrote in messagenews:08****************************@phx.gbl...
( aspx + vb )
hi everyone !
I really need make that function work !
im brazilian , and i want to make a multilanguage system , that function above must look at all ASPX take the labels ID and send as a parameter
,... so Please , help me ,.. cause it doest work !

'------------------------------------------------------- --- --------------
'------------------------------------------------------- --- --------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

end sub

Sub TraduzLbl(byval parent As Control)
Dim XmlLang1 as new XmlLang
Dim varxml as string
Dim c As Control

For each c In parent.Controls
If c.GetType() is GetType (system.web.ui.webcontrols.Label) Then
varxml = CType(c,system.web.ui.webcontrols.Label).text
CType(c,system.web.ui.webcontrols.Label).text =

End If

End Sub


Nov 18 '05 #1
0 1625

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Mariano López | last post: by
8 posts views Thread by Aftab Alam | last post: by
5 posts views Thread by Michal Táborský | last post: by
reply views Thread by HelmutStoneCorner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.