Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > A question on ASP.net localization

Reply
Thread Tools

A question on ASP.net localization

 
 
JollyK
Guest
Posts: n/a
 
      03-01-2004
Hi everyone...

I am creating a web app that will support english and french languages.

My code is fairly simple and it working fine. In my global.asax file I have
the
following code in the Application_BeginRequest event.

try
{
Thread.CurrentThread.CurrentCulture = new
CultureInfo(Request.UserLanguages[0]);
}
catch(Exception)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
}

I have a resource file for french and a resource file for english, and if
the browser langauge
is set to french, then french info is displayed, and if the browser
langauage is set to english,
then english is displayed. So far everything is perfectly.
My issue is, suppose the browser is set to Arabic, or Italian, or any other
langauge, I want to
default it to English. How do I do this ?


 
Reply With Quote
 
 
 
 
Martin Dechev
Guest
Posts: n/a
 
      03-01-2004
Hi, JollyK,

It is the CurrentUICulture property on the Thread class that is taken in
consideration by the Resource Manager to look up culture-specific resources
at run time. If you replace CurrentCulture with CurrentUICulture in the code
you posted, and if everything else works, you should be set.

Greetings
Martin
"JollyK" <(E-Mail Removed)> wrote in message
news:emSJ3i7$(E-Mail Removed)...
> Hi everyone...
>
> I am creating a web app that will support english and french languages.
>
> My code is fairly simple and it working fine. In my global.asax file I

have
> the
> following code in the Application_BeginRequest event.
>
> try
> {
> Thread.CurrentThread.CurrentCulture = new
> CultureInfo(Request.UserLanguages[0]);
> }
> catch(Exception)
> {
> Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
> }
>
> I have a resource file for french and a resource file for english, and if
> the browser langauge
> is set to french, then french info is displayed, and if the browser
> langauage is set to english,
> then english is displayed. So far everything is perfectly.
> My issue is, suppose the browser is set to Arabic, or Italian, or any

other
> langauge, I want to
> default it to English. How do I do this ?
>
>



 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      03-01-2004
this code will have problems because of asp.net thread agility. the same
thread is not necessarily used for a page process, so if a thread switch is
done, you will have the wrong culture.

you need to set the thread culture before any calls that need it (you should
also restore it, before the threads returned to the pool)

-- bruce (sqlwork.com)




"JollyK" <(E-Mail Removed)> wrote in message
news:emSJ3i7$(E-Mail Removed)...
> Hi everyone...
>
> I am creating a web app that will support english and french languages.
>
> My code is fairly simple and it working fine. In my global.asax file I

have
> the
> following code in the Application_BeginRequest event.
>
> try
> {
> Thread.CurrentThread.CurrentCulture = new
> CultureInfo(Request.UserLanguages[0]);
> }
> catch(Exception)
> {
> Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
> }
>
> I have a resource file for french and a resource file for english, and if
> the browser langauge
> is set to french, then french info is displayed, and if the browser
> langauage is set to english,
> then english is displayed. So far everything is perfectly.
> My issue is, suppose the browser is set to Arabic, or Italian, or any

other
> langauge, I want to
> default it to English. How do I do this ?
>
>



 
Reply With Quote
 
JollyK
Guest
Posts: n/a
 
      03-01-2004
Hi Bruce,
How about an example


"bruce barker" <(E-Mail Removed)> wrote in message
news:#p9TC17$(E-Mail Removed)...
> this code will have problems because of asp.net thread agility. the same
> thread is not necessarily used for a page process, so if a thread switch

is
> done, you will have the wrong culture.
>
> you need to set the thread culture before any calls that need it (you

should
> also restore it, before the threads returned to the pool)
>
> -- bruce (sqlwork.com)
>
>
>
>
> "JollyK" <(E-Mail Removed)> wrote in message
> news:emSJ3i7$(E-Mail Removed)...
> > Hi everyone...
> >
> > I am creating a web app that will support english and french languages.
> >
> > My code is fairly simple and it working fine. In my global.asax file I

> have
> > the
> > following code in the Application_BeginRequest event.
> >
> > try
> > {
> > Thread.CurrentThread.CurrentCulture = new
> > CultureInfo(Request.UserLanguages[0]);
> > }
> > catch(Exception)
> > {
> > Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
> > }
> >
> > I have a resource file for french and a resource file for english, and

if
> > the browser langauge
> > is set to french, then french info is displayed, and if the browser
> > langauage is set to english,
> > then english is displayed. So far everything is perfectly.
> > My issue is, suppose the browser is set to Arabic, or Italian, or any

> other
> > langauge, I want to
> > default it to English. How do I do this ?
> >
> >

>
>



 
Reply With Quote
 
Martin Dechev
Guest
Posts: n/a
 
      03-01-2004
Hi, bruce baker,

Could you prove your point with some documentation?

There is a tutorial that in fact shows how to set the CurrentUICulture in
the Application_BeginRequest handler:

http://msdn.microsoft.com/library/en...nd_asp_net.asp

I personally don't see a situation in which more than one thread could be
used in the execution of a Page class given the used model for the page
lifecycle.

Greetings
Martin
"bruce barker" <(E-Mail Removed)> wrote in message
news:#p9TC17$(E-Mail Removed)...
> this code will have problems because of asp.net thread agility. the same
> thread is not necessarily used for a page process, so if a thread switch

is
> done, you will have the wrong culture.
>
> you need to set the thread culture before any calls that need it (you

should
> also restore it, before the threads returned to the pool)
>
> -- bruce (sqlwork.com)
>
>
>
>
> "JollyK" <(E-Mail Removed)> wrote in message
> news:emSJ3i7$(E-Mail Removed)...
> > Hi everyone...
> >
> > I am creating a web app that will support english and french languages.
> >
> > My code is fairly simple and it working fine. In my global.asax file I

> have
> > the
> > following code in the Application_BeginRequest event.
> >
> > try
> > {
> > Thread.CurrentThread.CurrentCulture = new
> > CultureInfo(Request.UserLanguages[0]);
> > }
> > catch(Exception)
> > {
> > Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
> > }
> >
> > I have a resource file for french and a resource file for english, and

if
> > the browser langauge
> > is set to french, then french info is displayed, and if the browser
> > langauage is set to english,
> > then english is displayed. So far everything is perfectly.
> > My issue is, suppose the browser is set to Arabic, or Italian, or any

> other
> > langauge, I want to
> > default it to English. How do I do this ?
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Localization ASP.NET WebControl question PJ ASP .Net 1 09-11-2007 02:35 AM
Localization Question - Level of Effort Corey B ASP .Net 3 01-17-2007 03:00 PM
Localization question =?Utf-8?B?am9l?= ASP .Net 1 03-07-2006 11:47 AM
Localization Question Matthias S. ASP .Net 4 04-11-2005 12:52 PM
A question regarding localization /internationalization Praveen Java 1 05-26-2004 06:37 AM



Advertisments