A question on ASP.net localization

Discussion in 'ASP .Net' started by JollyK, Mar 1, 2004.

  1. JollyK

    JollyK Guest

    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, Mar 1, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:emSJ3i7$...
    > 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, Mar 1, 2004
    #2
    1. Advertising

  3. JollyK

    bruce barker Guest

    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" <> wrote in message
    news:emSJ3i7$...
    > 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, Mar 1, 2004
    #3
  4. JollyK

    JollyK Guest

    Hi Bruce,
    How about an example


    "bruce barker" <> wrote in message
    news:#p9TC17$...
    > 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" <> wrote in message
    > news:emSJ3i7$...
    > > 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, Mar 1, 2004
    #4
  5. 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-us/cptutorials/html/resourcemanager_and_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" <> wrote in message
    news:#p9TC17$...
    > 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" <> wrote in message
    > news:emSJ3i7$...
    > > 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, Mar 1, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    647
  2. Kai Iske

    ASP.NET Localization not working

    Kai Iske, Aug 20, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    566
    Kai Iske
    Aug 20, 2003
  3. Stoyan
    Replies:
    0
    Views:
    321
    Stoyan
    Aug 20, 2003
  4. Buu Nguyen
    Replies:
    0
    Views:
    412
    Buu Nguyen
    Aug 23, 2004
  5. Julia
    Replies:
    2
    Views:
    353
    Julia
    Feb 22, 2005
Loading...

Share This Page