locked
Programatically changing UICulture and Culture RRS feed

  • Question

  • User326230061 posted

    Hello everyone,

    I'm having a big of an issue. I'm trying to change the value of the language and culture values via a database entry and then appending the culture to the returned value. IE: "en" is in the database, I add "-CA" via VB code.
    When I hardcode the values, it does work no problem. However, appding the "-CA" makes it crash with the following error message:

    Exception Details: System.ArgumentException: Culture name '-ca' is not supported.
    Parameter name: name

    Now, I'm retrieving the language value from a database and, since the information is used all over the web site, I cannot really change the data within the database.
    The following code is posted in the Default.aspx page, called by the master page.
    The function "siteSetLanguage" retrieves from the database the base language (EN/FR) and returns the value. Null values are checked for and if a null value is returned from the database, it defaults to EN.

    Protected Overrides Sub InitializeCulture()
            Dim strLanguage As String
    
            If (Response.Cookies("webApp")("language") IsNot Nothing) Then
                strLanguage = CStr(Response.Cookies("webApp")("language"))
            Else
                strLanguage = CStr(siteSetLanguage(userID))
            End If
    
            strLanguage = strLanguage & "-CA"
    
            UICulture = strLanguage
            Culture = "en-CA"
    
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-CA")
            Thread.CurrentThread.CurrentUICulture = New CultureInfo(strLanguage)
    
            MyBase.InitializeCulture()
        End Sub

    I do want to force UICulture to english as everything in the databases and external files are stored through the english canadian regional method. However, I've been trying to use .resx files using the above method, but to no avail.
    Needless to say, my language files don't seem to work no matter what I do.

    Can anyone point me in the right direction?
    Thanks a lot in advance. :)

    Thursday, July 15, 2010 5:02 PM

All replies

  • User-1734649046 posted

    Hi,

    Please refer following

    http://stackoverflow.com/questions/868880/culture-name-is-not-supported

    hope this helps

    Thursday, July 15, 2010 10:55 PM
  • User326230061 posted

     Hello Ketan and thanks for the help! :)

    However, nothing in that link helped. I did manage to find where my issue was: I didn't know initializeCulture was called before the preInit event, so some of my variables were not being populated in time for the SQL query. Now that I included the userID check within initializeCulture, things are smooth when it comes to setting the Culture variable.

    Thanks a lot nonetheless though! :)

    Friday, July 16, 2010 10:52 AM