Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   A question on ASP.net localization (http://www.velocityreviews.com/forums/t74370-a-question-on-asp-net-localization.html)

JollyK 03-01-2004 06:12 PM

A question on ASP.net localization
 
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 ?



Martin Dechev 03-01-2004 06:35 PM

Re: A question on ASP.net localization
 
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" <JollyK@email.com> wrote in message
news:emSJ3i7$DHA.4052@tk2msftngp13.phx.gbl...
> 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 ?
>
>




bruce barker 03-01-2004 06:44 PM

Re: A question on ASP.net localization
 
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" <JollyK@email.com> wrote in message
news:emSJ3i7$DHA.4052@tk2msftngp13.phx.gbl...
> 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 ?
>
>




JollyK 03-01-2004 06:52 PM

Re: A question on ASP.net localization
 
Hi Bruce,
How about an example


"bruce barker" <nospam_brubar@safeco.com> wrote in message
news:#p9TC17$DHA.2512@TK2MSFTNGP11.phx.gbl...
> 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" <JollyK@email.com> wrote in message
> news:emSJ3i7$DHA.4052@tk2msftngp13.phx.gbl...
> > 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 ?
> >
> >

>
>




Martin Dechev 03-01-2004 07:07 PM

Re: A question on ASP.net localization
 
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" <nospam_brubar@safeco.com> wrote in message
news:#p9TC17$DHA.2512@TK2MSFTNGP11.phx.gbl...
> 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" <JollyK@email.com> wrote in message
> news:emSJ3i7$DHA.4052@tk2msftngp13.phx.gbl...
> > 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 ?
> >
> >

>
>





All times are GMT. The time now is 11:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.