locked
Culture Codes RRS feed

  • Question

  • User1729454657 posted

    Hi everyone,

    I am writing a sign up page for my application. I want the ability to default to the correct country on the drop down list. I currently have the following:

    FOREACH ListItem in ddlCountries
    
    if (Request.UserLanguages[0].ToUpper() == ListItem.Value.ToUpper())
    {
        ListItem.Selected = true;
    }
     
    This works well in IE, but in Firefox I it gives me en-GB even though I am in Ireland and in Chrome it gives me en-US. I dont want to have to depend on users of my application to have changed their browser language. Is there a better way to accomplish this?
     
    Thanks in advance!


     

    Wednesday, October 28, 2009 6:28 AM

Answers

  • User2130758966 posted

    The request.userlanguages depends on the language that they have set their browser to. This is often provided to the browser by the operating system.


    You can look into two options to take this idea further, one is geolocation which means you take their IP, send it off to a 3rd party service to query their database and they tell you where in the world that ip address is located. The other is to use the new location services features which are in ff3 at least.

    Neither of the solutions are fool proof though. It could end up being a lot of work for a simple feature.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 28, 2009 9:38 AM

All replies

  • User2130758966 posted

    The request.userlanguages depends on the language that they have set their browser to. This is often provided to the browser by the operating system.


    You can look into two options to take this idea further, one is geolocation which means you take their IP, send it off to a 3rd party service to query their database and they tell you where in the world that ip address is located. The other is to use the new location services features which are in ff3 at least.

    Neither of the solutions are fool proof though. It could end up being a lot of work for a simple feature.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 28, 2009 9:38 AM
  • User1729454657 posted

    Thanks for your reply rtpHarry,

    The Geolocation method does seem like a lot of work for a simple feature. I have looked at the RegionInfo class.
    I can get the CurrentRegions "TwoLetterISORegionName" (e.g. US, GB, IE) and use it to match to correct country.

    How is the region set? Is it a more reliable method to the other mentions?

     

    Thanks again.

    Wednesday, October 28, 2009 10:11 AM
  • User2130758966 posted

    As far as i know its is just the culture split in half and the information comes from the same place - the browser settings.


    Ok clearly i didnt know very far :)

    Looking at the documentation:

    you will see that it is simply a class for manipulating the regional information.


    It doesnt get its information automatically from anywhere - it just shows whatever region you configure by passing info into its constructor.

    Wednesday, October 28, 2009 10:52 AM
  • User1729454657 posted

    Hmm...strange one.

    So we dont know how it sets its info. Well it seems to be working here anyway. I just called it statically and it populated everything correctly.

    Methinks I will go with that, unless anyone has any other ideas?

    P.S. Thanks rtpHarry!

    Wednesday, October 28, 2009 11:15 AM
  • User2130758966 posted

    So we dont know how it sets its info. Well it seems to be working here anyway. I just called it statically and it populated everything correctly.

    Methinks I will go with that, unless anyone has any other ideas?

    My final idea for the day is to get .net reflector and use it to open it up and look at the code:

    Wednesday, October 28, 2009 3:47 PM
  • User1577733570 posted

    Hi,

     Instead of changing users browser language, you can get the geographical info for a user getting his/her IP and change your application culture accordingly.

    After you get his IP all you need is to use any third party web service that gets geographical info for the user by his/her.

     

    Thursday, October 29, 2009 2:46 AM
  • User1729454657 posted

    Thanks everyone,

    It looks like using the IP to find the correct country seems to be the most reliable solution. Cheers again! 

    Thursday, October 29, 2009 10:43 AM