how do i set the current culture to es-US

Last post 07-14-2007 10:18 AM by aweil. 7 replies.

Sort Posts:

  • how do i set the current culture to es-US

    07-12-2007, 1:38 PM
    • Loading...
    • Karenros
    • Joined on 11-08-2006, 2:54 PM
    • Charlotte, NC
    • Posts 900

    how do i set a the current culture to es-US???

    Regards

    Karen

  • Re: how do i set the current culture to es-US

    07-12-2007, 3:19 PM
    • Loading...
    • ps2goat
    • Joined on 11-17-2006, 5:43 PM
    • Posts 1,651

    Do you mean setting your browser to test culture changes, or manual changing by a user who prefers one culture over another?

    ---------------------------------------
    MCP - Web Based Client Development .NET 2.0
  • Re: how do i set the current culture to es-US

    07-12-2007, 3:33 PM
    • Loading...
    • Karenros
    • Joined on 11-08-2006, 2:54 PM
    • Charlotte, NC
    • Posts 900

    i am using a dropdownlist and asking the user to select it.

    REgards

    Karen

  • Re: how do i set the current culture to es-US

    07-12-2007, 3:54 PM
    • Loading...
    • ps2goat
    • Joined on 11-17-2006, 5:43 PM
    • Posts 1,651

    You have to override the Page's InitializeCulture() method, and set the culture inside of it.  More info: http://msdn2.microsoft.com/en-us/library/bz9tc508.aspx

    ---------------------------------------
    MCP - Web Based Client Development .NET 2.0
  • Re: how do i set the current culture to es-US

    07-12-2007, 4:00 PM
    • Loading...
    • Karenros
    • Joined on 11-08-2006, 2:54 PM
    • Charlotte, NC
    • Posts 900

    Ps2goat,

      thanks for your answer, this is what i am doing?

     

    <tr>
    				<td align = "center" >
    				<asp:Label ID = "lblLanguage" runat ="server" Text = "Select a langauage" />
    				<asp:DropDownList ID = "ddlLanguage" AutoPostBack = "true" runat ="server" >
    				<asp:ListItem Value = "en-US">English</asp:ListItem>
    				<asp:ListItem Value = "es">Spanish</asp:ListItem>
    				</asp:DropDownList>
    				</td>
    				</tr>
      
    Protected Overrides Sub InitializeCulture()
            If Request.Form("ddlLanguage") IsNot Nothing Then
                Dim selectedLanguage As String = _
                    Request.Form("ddlLanguage")
                UICulture = Request.Form("ddlLanguage")
                Culture = Request.Form("ddlLanguage")
                Thread.CurrentThread.CurrentCulture = _
                    CultureInfo.CreateSpecificCulture(selectedLanguage)
                Thread.CurrentThread.CurrentUICulture = New _
                    CultureInfo(selectedLanguage)
            End If
            MyBase.InitializeCulture()
        End Sub

     but i am getting an error called

    Culture 'es' is a neutral culture. It cannot be used in formatting and parsing and therefore cannot be set as the thread's current culture

    regards,

    Karen

  • Re: how do i set the current culture to es-US

    07-12-2007, 5:15 PM
    • Loading...
    • ps2goat
    • Joined on 11-17-2006, 5:43 PM
    • Posts 1,651

    I had never tried to set this myself, so I never ran into this problem before.  I know that in order to set a specific culture, you need to set the region (i.e. en-US is the US version of English, which helps with formatting like using $ instead of British pounds.)

     So, you can either let the user select a country from another list box and append that country code, or set an arbitrary default that everyone must use, such as Spanish for Spain.  The latter is what you would be doing, anyway.  However, in the terms of globalization, I think that someone with their browser set to Spanish for Mexico would actually get English (or whatever the default language is).

     

    Another workaround would be to not set the UICulture or Culture properties (at least not he Culture property, as that is causing your error).  I tested the following code (no controls, to be concise) and it worked:

     

    	Protected Overrides Sub InitializeCulture()
    		System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CreateSpecificCulture("es")
    		System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("es")
    		MyBase.InitializeCulture()
    	End Sub
     
    ---------------------------------------
    MCP - Web Based Client Development .NET 2.0
  • Re: how do i set the current culture to es-US

    07-12-2007, 5:34 PM
    • Loading...
    • Karenros
    • Joined on 11-08-2006, 2:54 PM
    • Charlotte, NC
    • Posts 900

    So do u mean in order to get it work in the spanish i need to change the regional setting to the following lang?

  • Re: how do i set the current culture to es-US

    07-14-2007, 10:18 AM
    • Loading...
    • aweil
    • Joined on 09-09-2005, 6:57 PM
    • Paris, France
    • Posts 118

    Hi Karen,

    Your code is good. The only problem is that there is no culture "es-US". What you want is the spanish spoken in the USA, right? Well, it's mexican spanish so just use "es-MX" and you're done!

    Hope this helps,

    Arnaud
     

    Microsoft .net Training and Consulting
    http://www.dreamdotnet.com/
    Microsoft .net 3.0 Training and Consulting
    Filed under: ,
Page 1 of 1 (8 items)
Microsoft Communities
Page view counter