473,385 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

trying to write a multilingual web site

I created a
==============
public class LangModule : IHttpModule
{
public void Dispose() {}

public void Init(HttpApplication application)
{
HttpContext context = application.Context;
HttpCookie lc = context.Request.Cookies[LangCookieName];
if (lc == null)
return;

CultureInfo ci = new CultureInfo(lc.Value);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
}
public static string LangCookieName = "UserSelectedLanguage";
public static void SetLocale(HttpContext context, CultureInfo locale)
{
if (locale == null)
return;
HttpCookie lc = new HttpCookie(LangCookieName, locale.Name);
lc.Expires = DateTime.Now.AddDays(360);
context.Response.Cookies.Add(lc);
Thread.CurrentThread.CurrentCulture = locale;
Thread.CurrentThread.CurrentUICulture = locale;
}
}
==============
SetLocale() is successfully called by a LinkButton to either "en-AU" or "fr-FR" and the Init() method is called when there is an incoming query.
I'm trying to test if it works with a very simple literal:
==============
<asp:Literal runat="server" Text="<%$ Resources: Standart, Email %>" />
==============

And in App_GlobalResources I have 2 resources: "Standart.resx" & "Standart.fr-FR.resx".
However I always get the default (English) label, I never get the French label.

Any idea what I'm missing or I have done wrong?

--
I have taken a vow of poverty. If you want to really piss me off, send me money.

Jan 8 '06 #1
4 2723
First, Init() happens once per module load, not per request. To get code working on each request, you need to write it like:

public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(application_BeginRequest);
}

void application_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
//code here
}

Your real problem is timing. By the time the event handler fires, the thing's already been decided and switching the thread's culture doesn't do much.

If possible, I would suggest that you use links with querystring values, which can be read during BeginRequest.

I have an example that uses URL rewriting which could easily be modified to use querystrings:
http://openmymind.net/index.aspx?doc...d=4#urlrewrite

Karl

--
http://www.openmymind.net/

"Lloyd Dupont" <net.galador@ld> wrote in message news:ur**************@TK2MSFTNGP10.phx.gbl...
I created a
==============
public class LangModule : IHttpModule
{
public void Dispose() {}

public void Init(HttpApplication application)
{
HttpContext context = application.Context;
HttpCookie lc = context.Request.Cookies[LangCookieName];
if (lc == null)
return;

CultureInfo ci = new CultureInfo(lc.Value);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
}
public static string LangCookieName = "UserSelectedLanguage";
public static void SetLocale(HttpContext context, CultureInfo locale)
{
if (locale == null)
return;
HttpCookie lc = new HttpCookie(LangCookieName, locale.Name);
lc.Expires = DateTime.Now.AddDays(360);
context.Response.Cookies.Add(lc);
Thread.CurrentThread.CurrentCulture = locale;
Thread.CurrentThread.CurrentUICulture = locale;
}
}
==============
SetLocale() is successfully called by a LinkButton to either "en-AU" or "fr-FR" and the Init() method is called when there is an incoming query.
I'm trying to test if it works with a very simple literal:
==============
<asp:Literal runat="server" Text="<%$ Resources: Standart, Email %>" />
==============

And in App_GlobalResources I have 2 resources: "Standart.resx" & "Standart.fr-FR.resx".
However I always get the default (English) label, I never get the French label.

Any idea what I'm missing or I have done wrong?

--
I have taken a vow of poverty. If you want to really piss me off, send me money.

Jan 8 '06 #2
damn....
You completely open my mind on that!
(interesting link on your web page, BTW)

I did like that
============== Module ==============
public class LangModule : IHttpModule
{
HttpApplication application;
public void Dispose()
{
if (application != null)
{
application.BeginRequest -= HTranslate;
application = null;
}
}
public void Init(HttpApplication application)
{
this.application = application;
application.BeginRequest += HTranslate;
}
public void HTranslate(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
string lang = context.Request["lang"];

if (lang != null && lang != "" && SetLocale(context, lang))
return;
HttpCookie lc = context.Request.Cookies[LangCookieName];
if (lc == null)
return;

CultureInfo ci = new CultureInfo(lc.Value);
Thread.CurrentThread.CurrentUICulture = ci;
}
public static string LangCookieName = "UserSelectedLanguage";
public static bool SetLocale(HttpContext context, string locale)
{
if (locale == null)
return false;

CultureInfo ci = null;
try { ci = new CultureInfo(locale); }
catch { return false; }

HttpCookie lc = new HttpCookie(LangCookieName, locale);
lc.Expires = DateTime.Now.AddDays(360);
context.Response.Cookies.Add(lc);
Thread.CurrentThread.CurrentUICulture = ci;
return true;
}
}
========== WebControl ==============
<a href="?lang=en-AU"><img id="Img4" runat="server" src="~/datas/flag_au.gif" border="1" width="23" height="17" alt="English" /></a>
<a href="?lang=fr-FR" ><img id="Img5" runat="server" src="~/datas/flag_fr.gif" border="1" width="23" height="17" alt="Fran&ccedil;ais" /></a>
==================================

BTW, since there is a Dispose() method in the module it looks to me as an appropriate place to unregister the event handler, what do you think?

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:e1**************@TK2MSFTNGP09.phx.gbl...
First, Init() happens once per module load, not per request. To get code working on each request, you need to write it like:

public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(application_BeginRequest);
}

void application_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
//code here
}

Your real problem is timing. By the time the event handler fires, the thing's already been decided and switching the thread's culture doesn't do much.

If possible, I would suggest that you use links with querystring values, which can be read during BeginRequest.

I have an example that uses URL rewriting which could easily be modified to use querystrings:
http://openmymind.net/index.aspx?doc...d=4#urlrewrite

Karl

--
http://www.openmymind.net/

"Lloyd Dupont" <net.galador@ld> wrote in message news:ur**************@TK2MSFTNGP10.phx.gbl...
I created a
==============
public class LangModule : IHttpModule
{
public void Dispose() {}

public void Init(HttpApplication application)
{
HttpContext context = application.Context;
HttpCookie lc = context.Request.Cookies[LangCookieName];
if (lc == null)
return;

CultureInfo ci = new CultureInfo(lc.Value);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
}
public static string LangCookieName = "UserSelectedLanguage";
public static void SetLocale(HttpContext context, CultureInfo locale)
{
if (locale == null)
return;
HttpCookie lc = new HttpCookie(LangCookieName, locale.Name);
lc.Expires = DateTime.Now.AddDays(360);
context.Response.Cookies.Add(lc);
Thread.CurrentThread.CurrentCulture = locale;
Thread.CurrentThread.CurrentUICulture = locale;
}
}
==============
SetLocale() is successfully called by a LinkButton to either "en-AU" or "fr-FR" and the Init() method is called when there is an incoming query.
I'm trying to test if it works with a very simple literal:
==============
<asp:Literal runat="server" Text="<%$ Resources: Standart, Email %>" />
==============

And in App_GlobalResources I have 2 resources: "Standart.resx" & "Standart.fr-FR.resx".
However I always get the default (English) label, I never get the French label.

Any idea what I'm missing or I have done wrong?

--
I have taken a vow of poverty. If you want to really piss me off, send me money.

Jan 9 '06 #3
Event handlers don't need to be explicitely released for them to be cleaned up. The only time you'd really remove a handler is if you don't want it to fire anymore but you kept your instance around. Your dispose() isn't bad, but it is unecessary.

Karl

--
http://www.openmymind.net/

"Lloyd Dupont" <net.galador@ld> wrote in message news:OG**************@TK2MSFTNGP12.phx.gbl...
damn....
You completely open my mind on that!
(interesting link on your web page, BTW)

I did like that
============== Module ==============
public class LangModule : IHttpModule
{
HttpApplication application;
public void Dispose()
{
if (application != null)
{
application.BeginRequest -= HTranslate;
application = null;
}
}
public void Init(HttpApplication application)
{
this.application = application;
application.BeginRequest += HTranslate;
}
public void HTranslate(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
string lang = context.Request["lang"];

if (lang != null && lang != "" && SetLocale(context, lang))
return;
HttpCookie lc = context.Request.Cookies[LangCookieName];
if (lc == null)
return;

CultureInfo ci = new CultureInfo(lc.Value);
Thread.CurrentThread.CurrentUICulture = ci;
}
public static string LangCookieName = "UserSelectedLanguage";
public static bool SetLocale(HttpContext context, string locale)
{
if (locale == null)
return false;

CultureInfo ci = null;
try { ci = new CultureInfo(locale); }
catch { return false; }

HttpCookie lc = new HttpCookie(LangCookieName, locale);
lc.Expires = DateTime.Now.AddDays(360);
context.Response.Cookies.Add(lc);
Thread.CurrentThread.CurrentUICulture = ci;
return true;
}
}
========== WebControl ==============
<a href="?lang=en-AU"><img id="Img4" runat="server" src="~/datas/flag_au.gif" border="1" width="23" height="17" alt="English" /></a>
<a href="?lang=fr-FR" ><img id="Img5" runat="server" src="~/datas/flag_fr.gif" border="1" width="23" height="17" alt="Fran&ccedil;ais" /></a>
==================================

BTW, since there is a Dispose() method in the module it looks to me as an appropriate place to unregister the event handler, what do you think?

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:e1**************@TK2MSFTNGP09.phx.gbl...
First, Init() happens once per module load, not per request. To get code working on each request, you need to write it like:

public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(application_BeginRequest);
}

void application_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
//code here
}

Your real problem is timing. By the time the event handler fires, the thing's already been decided and switching the thread's culture doesn't do much.

If possible, I would suggest that you use links with querystring values, which can be read during BeginRequest.

I have an example that uses URL rewriting which could easily be modified to use querystrings:
http://openmymind.net/index.aspx?doc...d=4#urlrewrite

Karl

--
http://www.openmymind.net/

"Lloyd Dupont" <net.galador@ld> wrote in message news:ur**************@TK2MSFTNGP10.phx.gbl...
I created a
==============
public class LangModule : IHttpModule
{
public void Dispose() {}

public void Init(HttpApplication application)
{
HttpContext context = application.Context;
HttpCookie lc = context.Request.Cookies[LangCookieName];
if (lc == null)
return;

CultureInfo ci = new CultureInfo(lc.Value);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
}
public static string LangCookieName = "UserSelectedLanguage";
public static void SetLocale(HttpContext context, CultureInfo locale)
{
if (locale == null)
return;
HttpCookie lc = new HttpCookie(LangCookieName, locale.Name);
lc.Expires = DateTime.Now.AddDays(360);
context.Response.Cookies.Add(lc);
Thread.CurrentThread.CurrentCulture = locale;
Thread.CurrentThread.CurrentUICulture = locale;
}
}
==============
SetLocale() is successfully called by a LinkButton to either "en-AU" or "fr-FR" and the Init() method is called when there is an incoming query.
I'm trying to test if it works with a very simple literal:
==============
<asp:Literal runat="server" Text="<%$ Resources: Standart, Email %>" />
==============

And in App_GlobalResources I have 2 resources: "Standart.resx" & "Standart.fr-FR.resx".
However I always get the default (English) label, I never get the French label.

Any idea what I'm missing or I have done wrong?

--
I have taken a vow of poverty. If you want to really piss me off, send me money.

Jan 9 '06 #4
OK, thanks for the precision.
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl...
Event handlers don't need to be explicitely released for them to be cleaned up. The only time you'd really remove a handler is if you don't want it to fire anymore but you kept your instance around. Your dispose() isn't bad, but it is unecessary.

Karl

--
http://www.openmymind.net/

"Lloyd Dupont" <net.galador@ld> wrote in message news:OG**************@TK2MSFTNGP12.phx.gbl...
damn....
You completely open my mind on that!
(interesting link on your web page, BTW)

I did like that
============== Module ==============
public class LangModule : IHttpModule
{
HttpApplication application;
public void Dispose()
{
if (application != null)
{
application.BeginRequest -= HTranslate;
application = null;
}
}
public void Init(HttpApplication application)
{
this.application = application;
application.BeginRequest += HTranslate;
}
public void HTranslate(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
string lang = context.Request["lang"];

if (lang != null && lang != "" && SetLocale(context, lang))
return;
HttpCookie lc = context.Request.Cookies[LangCookieName];
if (lc == null)
return;

CultureInfo ci = new CultureInfo(lc.Value);
Thread.CurrentThread.CurrentUICulture = ci;
}
public static string LangCookieName = "UserSelectedLanguage";
public static bool SetLocale(HttpContext context, string locale)
{
if (locale == null)
return false;

CultureInfo ci = null;
try { ci = new CultureInfo(locale); }
catch { return false; }

HttpCookie lc = new HttpCookie(LangCookieName, locale);
lc.Expires = DateTime.Now.AddDays(360);
context.Response.Cookies.Add(lc);
Thread.CurrentThread.CurrentUICulture = ci;
return true;
}
}
========== WebControl ==============
<a href="?lang=en-AU"><img id="Img4" runat="server" src="~/datas/flag_au.gif" border="1" width="23" height="17" alt="English" /></a>
<a href="?lang=fr-FR" ><img id="Img5" runat="server" src="~/datas/flag_fr.gif" border="1" width="23" height="17" alt="Fran&ccedil;ais" /></a>
==================================

BTW, since there is a Dispose() method in the module it looks to me as an appropriate place to unregister the event handler, what do you think?

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:e1**************@TK2MSFTNGP09.phx.gbl...
First, Init() happens once per module load, not per request. To get code working on each request, you need to write it like:

public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(application_BeginRequest);
}

void application_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
//code here
}

Your real problem is timing. By the time the event handler fires, the thing's already been decided and switching the thread's culture doesn't do much.

If possible, I would suggest that you use links with querystring values, which can be read during BeginRequest.

I have an example that uses URL rewriting which could easily be modified to use querystrings:
http://openmymind.net/index.aspx?doc...d=4#urlrewrite

Karl

--
http://www.openmymind.net/

"Lloyd Dupont" <net.galador@ld> wrote in message news:ur**************@TK2MSFTNGP10.phx.gbl...
I created a
==============
public class LangModule : IHttpModule
{
public void Dispose() {}

public void Init(HttpApplication application)
{
HttpContext context = application.Context;
HttpCookie lc = context.Request.Cookies[LangCookieName];
if (lc == null)
return;

CultureInfo ci = new CultureInfo(lc.Value);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
}
public static string LangCookieName = "UserSelectedLanguage";
public static void SetLocale(HttpContext context, CultureInfo locale)
{
if (locale == null)
return;
HttpCookie lc = new HttpCookie(LangCookieName, locale.Name);
lc.Expires = DateTime.Now.AddDays(360);
context.Response.Cookies.Add(lc);
Thread.CurrentThread.CurrentCulture = locale;
Thread.CurrentThread.CurrentUICulture = locale;
}
}
==============
SetLocale() is successfully called by a LinkButton to either "en-AU" or "fr-FR" and the Init() method is called when there is an incoming query.
I'm trying to test if it works with a very simple literal:
==============
<asp:Literal runat="server" Text="<%$ Resources: Standart, Email %>" />
==============

And in App_GlobalResources I have 2 resources: "Standart.resx" & "Standart.fr-FR.resx".
However I always get the default (English) label, I never get the French label.

Any idea what I'm missing or I have done wrong?

--
I have taken a vow of poverty. If you want to really piss me off, send me money.

Jan 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ed | last post by:
I want to create a multilingual website in ASP. Is the Dictionary object created with the application-level scope the way to go?
7
by: J?rg Keller | last post by:
Hi all I have to localize an Access 2002 application: The application using several form, tables etc. is currently only in English. Now the frontend has to be bilingual, so the user can choose...
5
by: HALLES | last post by:
HI ! Is there a way to write append rewrite a XML Multilingual file. Two parallele aims Multilingual and Xml File format or Xml Lile file Format. Is there an editor to do that. HALLES .
3
by: charliewest | last post by:
Building Multilingual Portal I have been assigned a new project to build a multilingual portal using ASP.NET and the expected Microsoft technologies including C#, ADO.NET and SQL Server 2000. ...
1
by: Lloyd Dupont | last post by:
I'm trying to write a multilingual web site where the user could choose his language explicitely. I have 2 flag, the user could click on the flag to change the culture. The core of the logic goes...
64
by: Manfred Kooistra | last post by:
I am building a website with identical content in four different languages. On a first visit, the search engine determines the language of the content by the IP address of the visitor. What the...
2
by: | last post by:
Best practices and recommendations for asp.net 2 multilingual web sites? Thanks
6
by: CAH | last post by:
I need to make at multilingual website, with php and mysql, and I have placed the different language in different columns in a database. But when the user chooses a language, should I make the...
3
pradeepjain
by: pradeepjain | last post by:
Hii guys!! I need to create a multilingual site say another 2 languages! I am using indic scripts as of now! in which i need to create say another 3 pages in 3 languages . Its...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.