473,804 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trying to write a multilingual web site

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

public void Init(HttpApplic ation application)
{
HttpContext context = application.Con text;
HttpCookie lc = context.Request .Cookies[LangCookieName];
if (lc == null)
return;

CultureInfo ci = new CultureInfo(lc. Value);
Thread.CurrentT hread.CurrentCu lture = ci;
Thread.CurrentT hread.CurrentUI Culture = ci;
}
public static string LangCookieName = "UserSelectedLa nguage";
public static void SetLocale(HttpC ontext context, CultureInfo locale)
{
if (locale == null)
return;
HttpCookie lc = new HttpCookie(Lang CookieName, locale.Name);
lc.Expires = DateTime.Now.Ad dDays(360);
context.Respons e.Cookies.Add(l c);
Thread.CurrentT hread.CurrentCu lture = locale;
Thread.CurrentT hread.CurrentUI Culture = 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_GlobalResou rces I have 2 resources: "Standart.r esx" & "Standart.f r-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 2743
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(HttpApplic ation application)
{
application.Beg inRequest += new EventHandler(ap plication_Begin Request);
}

void application_Beg inRequest(objec t sender, EventArgs e)
{
HttpApplication application = (HttpApplicatio n)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******** ******@TK2MSFTN GP10.phx.gbl...
I created a
==============
public class LangModule : IHttpModule
{
public void Dispose() {}

public void Init(HttpApplic ation application)
{
HttpContext context = application.Con text;
HttpCookie lc = context.Request .Cookies[LangCookieName];
if (lc == null)
return;

CultureInfo ci = new CultureInfo(lc. Value);
Thread.CurrentT hread.CurrentCu lture = ci;
Thread.CurrentT hread.CurrentUI Culture = ci;
}
public static string LangCookieName = "UserSelectedLa nguage";
public static void SetLocale(HttpC ontext context, CultureInfo locale)
{
if (locale == null)
return;
HttpCookie lc = new HttpCookie(Lang CookieName, locale.Name);
lc.Expires = DateTime.Now.Ad dDays(360);
context.Respons e.Cookies.Add(l c);
Thread.CurrentT hread.CurrentCu lture = locale;
Thread.CurrentT hread.CurrentUI Culture = 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_GlobalResou rces I have 2 resources: "Standart.r esx" & "Standart.f r-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.Beg inRequest -= HTranslate;
application = null;
}
}
public void Init(HttpApplic ation application)
{
this.applicatio n = application;
application.Beg inRequest += HTranslate;
}
public void HTranslate(obje ct sender, EventArgs e)
{
HttpApplication application = (HttpApplicatio n)sender;
HttpContext context = application.Con text;
string lang = context.Request["lang"];

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

CultureInfo ci = new CultureInfo(lc. Value);
Thread.CurrentT hread.CurrentUI Culture = ci;
}
public static string LangCookieName = "UserSelectedLa nguage";
public static bool SetLocale(HttpC ontext context, string locale)
{
if (locale == null)
return false;

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

HttpCookie lc = new HttpCookie(Lang CookieName, locale);
lc.Expires = DateTime.Now.Ad dDays(360);
context.Respons e.Cookies.Add(l c);
Thread.CurrentT hread.CurrentUI Culture = 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&ccedi l;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******** ******@TK2MSFTN GP09.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(HttpApplic ation application)
{
application.Beg inRequest += new EventHandler(ap plication_Begin Request);
}

void application_Beg inRequest(objec t sender, EventArgs e)
{
HttpApplication application = (HttpApplicatio n)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******** ******@TK2MSFTN GP10.phx.gbl...
I created a
==============
public class LangModule : IHttpModule
{
public void Dispose() {}

public void Init(HttpApplic ation application)
{
HttpContext context = application.Con text;
HttpCookie lc = context.Request .Cookies[LangCookieName];
if (lc == null)
return;

CultureInfo ci = new CultureInfo(lc. Value);
Thread.CurrentT hread.CurrentCu lture = ci;
Thread.CurrentT hread.CurrentUI Culture = ci;
}
public static string LangCookieName = "UserSelectedLa nguage";
public static void SetLocale(HttpC ontext context, CultureInfo locale)
{
if (locale == null)
return;
HttpCookie lc = new HttpCookie(Lang CookieName, locale.Name);
lc.Expires = DateTime.Now.Ad dDays(360);
context.Respons e.Cookies.Add(l c);
Thread.CurrentT hread.CurrentCu lture = locale;
Thread.CurrentT hread.CurrentUI Culture = 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_GlobalResou rces I have 2 resources: "Standart.r esx" & "Standart.f r-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******** ******@TK2MSFTN GP12.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.Beg inRequest -= HTranslate;
application = null;
}
}
public void Init(HttpApplic ation application)
{
this.applicatio n = application;
application.Beg inRequest += HTranslate;
}
public void HTranslate(obje ct sender, EventArgs e)
{
HttpApplication application = (HttpApplicatio n)sender;
HttpContext context = application.Con text;
string lang = context.Request["lang"];

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

CultureInfo ci = new CultureInfo(lc. Value);
Thread.CurrentT hread.CurrentUI Culture = ci;
}
public static string LangCookieName = "UserSelectedLa nguage";
public static bool SetLocale(HttpC ontext context, string locale)
{
if (locale == null)
return false;

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

HttpCookie lc = new HttpCookie(Lang CookieName, locale);
lc.Expires = DateTime.Now.Ad dDays(360);
context.Respons e.Cookies.Add(l c);
Thread.CurrentT hread.CurrentUI Culture = 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&ccedi l;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******** ******@TK2MSFTN GP09.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(HttpApplic ation application)
{
application.Beg inRequest += new EventHandler(ap plication_Begin Request);
}

void application_Beg inRequest(objec t sender, EventArgs e)
{
HttpApplication application = (HttpApplicatio n)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******** ******@TK2MSFTN GP10.phx.gbl...
I created a
==============
public class LangModule : IHttpModule
{
public void Dispose() {}

public void Init(HttpApplic ation application)
{
HttpContext context = application.Con text;
HttpCookie lc = context.Request .Cookies[LangCookieName];
if (lc == null)
return;

CultureInfo ci = new CultureInfo(lc. Value);
Thread.CurrentT hread.CurrentCu lture = ci;
Thread.CurrentT hread.CurrentUI Culture = ci;
}
public static string LangCookieName = "UserSelectedLa nguage";
public static void SetLocale(HttpC ontext context, CultureInfo locale)
{
if (locale == null)
return;
HttpCookie lc = new HttpCookie(Lang CookieName, locale.Name);
lc.Expires = DateTime.Now.Ad dDays(360);
context.Respons e.Cookies.Add(l c);
Thread.CurrentT hread.CurrentCu lture = locale;
Thread.CurrentT hread.CurrentUI Culture = 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_GlobalResou rces I have 2 resources: "Standart.r esx" & "Standart.f r-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******** ********@TK2MSF TNGP14.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******** ******@TK2MSFTN GP12.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.Beg inRequest -= HTranslate;
application = null;
}
}
public void Init(HttpApplic ation application)
{
this.applicatio n = application;
application.Beg inRequest += HTranslate;
}
public void HTranslate(obje ct sender, EventArgs e)
{
HttpApplication application = (HttpApplicatio n)sender;
HttpContext context = application.Con text;
string lang = context.Request["lang"];

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

CultureInfo ci = new CultureInfo(lc. Value);
Thread.CurrentT hread.CurrentUI Culture = ci;
}
public static string LangCookieName = "UserSelectedLa nguage";
public static bool SetLocale(HttpC ontext context, string locale)
{
if (locale == null)
return false;

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

HttpCookie lc = new HttpCookie(Lang CookieName, locale);
lc.Expires = DateTime.Now.Ad dDays(360);
context.Respons e.Cookies.Add(l c);
Thread.CurrentT hread.CurrentUI Culture = 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&ccedi l;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******** ******@TK2MSFTN GP09.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(HttpApplic ation application)
{
application.Beg inRequest += new EventHandler(ap plication_Begin Request);
}

void application_Beg inRequest(objec t sender, EventArgs e)
{
HttpApplication application = (HttpApplicatio n)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******** ******@TK2MSFTN GP10.phx.gbl...
I created a
==============
public class LangModule : IHttpModule
{
public void Dispose() {}

public void Init(HttpApplic ation application)
{
HttpContext context = application.Con text;
HttpCookie lc = context.Request .Cookies[LangCookieName];
if (lc == null)
return;

CultureInfo ci = new CultureInfo(lc. Value);
Thread.CurrentT hread.CurrentCu lture = ci;
Thread.CurrentT hread.CurrentUI Culture = ci;
}
public static string LangCookieName = "UserSelectedLa nguage";
public static void SetLocale(HttpC ontext context, CultureInfo locale)
{
if (locale == null)
return;
HttpCookie lc = new HttpCookie(Lang CookieName, locale.Name);
lc.Expires = DateTime.Now.Ad dDays(360);
context.Respons e.Cookies.Add(l c);
Thread.CurrentT hread.CurrentCu lture = locale;
Thread.CurrentT hread.CurrentUI Culture = 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_GlobalResou rces I have 2 resources: "Standart.r esx" & "Standart.f r-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
2869
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
4404
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 if he wants the form content in English or in French. I have never done something like this before with Access. One way I think would be like that: - creating a table tblLanguage with the following fields: - FormName
5
1938
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
1962
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. To date, all of my Web Solutions use ADO.NET to access data which is stored in SQL SERVER. Given the need to develop a solution that is very easy to localize, I wonder if now I should consider instead using XML rather than SQL SERVER, or a...
1
2079
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 in an HttpModule: =========== public class LangModule : IHttpModule { public void Dispose() {} public void Init(HttpApplication application) {
64
6438
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 user sees is content in only one language at a time. He or she can then switch to another language and set this as the preferred language, but again he or she sees content in only this one other language. The question now is: How do I get search...
2
2502
by: | last post by:
Best practices and recommendations for asp.net 2 multilingual web sites? Thanks
6
12757
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 choice stick with a cookie or a session or something else? Mads
3
2203
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 tedious job! Is there any other way to do the conversions on the fly and show the page to the end users! Hope i have asked the question in correct forum as ma site is developed using php and mysql Db driven!
0
9712
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10089
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.