none
change culture at runtime does not affect in class library RRS feed

  • Question

  • Hi

    I am able to change UI culture at runtime in form page and getting resource strings from related *.resx file .But I want to change culture in class library EuroDate.vb.In this class library I have created resx files for 6 cultures.I have method DisplayDateToUsersLanguage(byval As strlang) in this class . When I call this method by passing approriate language culture, this method needs to return date in specified langauge culture.So I need to apply different culture in this class library only not in form page i.e (*.aspx.vb ) hence I have to change culture and read strings from the approriate *.resx files.

    I have tried as in the following way , but could not read strings from required *.resx file.every time it reads from default culture resx file that is set during page loads.

    Public Function DisplayDateToUsersLanguage(ByVal strDisplayLanguage As String) As String

            Dim strMonth ,strCulture As String
            Try

               

    If strDisplayLanguage.ToUpper = "EN" Then
                            strCulture = "en-US"
                ElseIf strDisplayLanguage.ToUpper = "FR" Then
                            strCulture = "fr-FR"
                ElseIf strDisplayLanguage.ToUpper = "NL" Then
                           strCulture = "nl-NL"
                ElseIf strDisplayLanguage.ToUpper = "DE" Then
                            strCulture = "de-DE"
                ElseIf strDisplayLanguage.ToUpper = "ES" Then
                            strCulture = "es-ES"
                ElseIf strDisplayLanguage.ToUpper = "BR" Then
                            strCulture = "pt-BR"
                ElseIf strDisplayLanguage.ToUpper = "JA" Then
                            strCulture = "ja-JA"
                ElseIf strDisplayLanguage.ToUpper = "ZH" Then
                            strCulture = "zh-ZH"
                Else
                            strCulture = "en-US"
                End If

                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(strCulture)
                Thread.CurrentThread.CurrentUICulture = New CultureInfo(strCulture)

                Dim rmDates As New ResourceManager("AlDotNetPlatformLib.Dates", [GetType]().Assembly)
                strMonth = rmDates.GetString("Jan")
                strMonth = rmDates.GetString("Feb")
                strMonth = rmDates.GetString("Mar")
                strMonth = rmDates.GetString("Apr")
                strMonth = rmDates.GetString("May")
                strMonth = rmDates.GetString("Jun")
                strMonth = rmDates.GetString("Jul")
                strMonth = rmDates.GetString("Aug")
                strMonth = rmDates.GetString("Sep")
                strMonth = rmDates.GetString("Oct")
                strMonth = rmDates.GetString("Nov")
                strMonth = rmDates.GetString("Dec")

            Catch ex As Exception

           End Try

            Return strMonth
        End Function

    We have a page that sends mails to users in their language.we get users language from database. So we have to write one genric method in class library becaue this methods will be used by many pages.so we are calling this method by passing user language.now this method should retrieve month name from this langauge resx file which is in class library project.But on calling by passing user lang,everytime it isretrieving in default lanugage only.

    Please help in resolving this issue.

    Regards

    krishna

    Thursday, June 7, 2012 5:25 AM

Answers

  • This blog can be helpful

    Mark Answered, if it solves your question
    Rohit Arora

    Thursday, June 7, 2012 6:12 AM
  • Hi Krish,

    Welcome to the MSDN Forum.

    And this is another walkthrogh: http://msdn.microsoft.com/en-us/library/aa728892(v=vs.71).aspx 

    When you localize Web Forms pages, the Visual Studio project system does not automatically generate resource files. You must manually create and edit the XML resource files. This walkthrough topic demonstrates how to add a resource file template and then edit the template with the XML Designer to create resources in English, German, and German as spoken in Austria. This topic also discusses how to write code to access these resources.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 8, 2012 9:04 AM
    Moderator

All replies

  • Your ASP.Net program is running on the Server not at the client so the culture is from the Server. There is in HTML 4 no way to get the culture from a webpage, I don't know if that is already fixed in HTML5.

    However, try it in the forum for your kind of questions.

    http://forums.asp.net

     

    Success
    Cor

    Thursday, June 7, 2012 5:47 AM
  • This blog can be helpful

    Mark Answered, if it solves your question
    Rohit Arora

    Thursday, June 7, 2012 6:12 AM
  • Hi Krish,

    Welcome to the MSDN Forum.

    And this is another walkthrogh: http://msdn.microsoft.com/en-us/library/aa728892(v=vs.71).aspx 

    When you localize Web Forms pages, the Visual Studio project system does not automatically generate resource files. You must manually create and edit the XML resource files. This walkthrough topic demonstrates how to add a resource file template and then edit the template with the XML Designer to create resources in English, German, and German as spoken in Austria. This topic also discusses how to write code to access these resources.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 8, 2012 9:04 AM
    Moderator