locked
find my current culture RRS feed

  • Question

  • User-269404413 posted

    hi there,

    i changed my IE language to German(Germany) by this way http://whatismyipaddress.ricmedia.com/help/browser_language/internet_explorer_7/

    after that i execute below code from front-end

    string strCurrentCutlture = string.Empty;
                strCurrentCutlture = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
                Response.Write("Currrent Cutture is " + strCurrentCutlture);

    but its always giving output us English. why its gave me always English? and how can i get the exact culture? 

    Tuesday, August 9, 2011 3:45 AM

Answers

  • User1508394307 posted

    Use HttpRequest.UserLanguages or the Headers collection in the Request object - Request.Headers["Accept-Language"].

    The Thread.CurrentCulture Property gets or sets the culture for the current thread, not a client.

    To set current culture according to browser settings, use

    using System.Globalization;
    using System.Threading;
    
    private void Page_Load(object sender, System.EventArgs e)
    {
        Thread.CurrentThread.CurrentCulture = 
            CultureInfo.CreateSpecificCulture(Request.UserLanguages[0].ToString());
        Thread.CurrentThread.CurrentUICulture = 
            new CultureInfo(Request.UserLanguages[0].ToString());
    
        lblToday.Text = Today;
    
        lblMessage.Text = "Culture Info Display Name " + 
                          Thread.CurrentThread.CurrentCulture.DisplayName;
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 9, 2011 3:47 AM
  • User1508394307 posted

    You mean how to access the Request class?

    System.Web.HttpContext.Current.Request.UserLanguages[0].ToString();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 9, 2011 4:02 AM

All replies

  • User1508394307 posted

    Use HttpRequest.UserLanguages or the Headers collection in the Request object - Request.Headers["Accept-Language"].

    The Thread.CurrentCulture Property gets or sets the culture for the current thread, not a client.

    To set current culture according to browser settings, use

    using System.Globalization;
    using System.Threading;
    
    private void Page_Load(object sender, System.EventArgs e)
    {
        Thread.CurrentThread.CurrentCulture = 
            CultureInfo.CreateSpecificCulture(Request.UserLanguages[0].ToString());
        Thread.CurrentThread.CurrentUICulture = 
            new CultureInfo(Request.UserLanguages[0].ToString());
    
        lblToday.Text = Today;
    
        lblMessage.Text = "Culture Info Display Name " + 
                          Thread.CurrentThread.CurrentCulture.DisplayName;
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 9, 2011 3:47 AM
  • User-269404413 posted

    Sminov,

    Thanks for your response.

    Request.UserLanguages[0].ToString(); its good in aspx.cs file but how can we get the language from a class file (without uqerystring concept)

    Tuesday, August 9, 2011 3:55 AM
  • User1508394307 posted

    You mean how to access the Request class?

    System.Web.HttpContext.Current.Request.UserLanguages[0].ToString();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 9, 2011 4:02 AM