locked
Globalization of master page is not working even culture of the master page changes.. RRS feed

  • Question

  • User1784691416 posted

    Hi,

    Whenever my current culture is getting is changed based on the URL, my label/literel values are not getting changed,.. the values are always from the en-us language..

     

    This problem araised only in the master page. ive changed weg.config and  everything.. :(

    <%

    @ Master Language="C#" %>

     

    <!

    DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

    "http://www.w3.org/TR/html4/loose.dtd">

    <%

    @ Import Namespace="Microsoft.SharePoint" %>

    .

    .

    <asp:Literal ID="test" runat="server" Text="<%$Resources:ResourceClass, test %>" ></asp:Literal>

    Please help me regarding this..

     

    Tuesday, September 13, 2011 2:50 AM

Answers

  • User699558600 posted

    This is my master page code

    do you see i again redirect user to the same page so that localized values are set

    Protected Sub SubmitLanguage_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SubmitLanguage.Click
            SetCulture()
        End Sub
        
        Private Sub SetCulture()
            Common.Culture = LanguageList.SelectedValue
            Dim CultureInfo = New Globalization.CultureInfo(Common.Culture) ' see Common.Culture below
            Threading.Thread.CurrentThread.CurrentCulture = CultureInfo
            Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo
               Response.Redirect(Request.RawUrl) ' load same page again
        End Sub
    
    

    here is my page init code

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim CultureInfo = New Globalization.CultureInfo(Common.Culture)
            Dim UserIdentityId%
            Threading.Thread.CurrentThread.CurrentCulture = CultureInfo
            Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo
    End Sub
    

     Here is my method to set the culture it is in Common Class, so i call it like Common.Culture

    ' if no culture is defined it returns english always
    Public Shared Property Culture$()
            Set(ByVal value$)
                HttpContext.Current.Session!Culture = value
            End Set
            Get
                If String.IsNullOrEmpty(HttpContext.Current.Session!Culture) Then
                    Culture = "en-US"
                    Return Culture
                End If
                Return HttpContext.Current.Session!Culture
            End Get
        End Property
    
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 13, 2011 5:18 AM

All replies

  • User699558600 posted

    you have to do this, you have to override InitializeCulture on all pages as below

    Protected Overrides Sub InitializeCulture()
            Dim CultureInfo = New Globalization.CultureInfo(Session["currentCulture"].ToString())
            Threading.Thread.CurrentThread.CurrentCulture = CultureInfo
            Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo
            MyBase.InitializeCulture()
        End Sub

    i read current culture from Session["currentCulture"] but you can read it from url or from database...

    Tuesday, September 13, 2011 3:04 AM
  • User1784691416 posted

    i have already initialized the culture..

    Here the problem is. My current culture is getting changed to the appropriate languages without any issues.. but not able to fetch key values for label/litrel other than english..

    Tuesday, September 13, 2011 3:14 AM
  • User699558600 posted

    if this is the case then surely there is some issue with your resource file naming covention...

    can you share one resource file names for multiple languages

    Here are my for example

    ContactUs.aspx.resx for english

    ContactUs.aspx.ru-RU.resx russian

    ContactUs.aspx.zh-CN.resx Chinese

    Tuesday, September 13, 2011 3:34 AM
  • User1784691416 posted

    Hi Tarun,

    My filename is like

    contacts.resx

    contacts.en-US.resx

    contacts.es-ES.resx.

    Its working fine for pages but not for master pages....

     

    Tuesday, September 13, 2011 4:39 AM
  • User699558600 posted

    Its working fine for pages but not for master pages....

    Master page does not have InitialzeCulture method...so do you set the the Thread culture properly.

    E.g.

    You can set it on dropdown selected indexd changed or on button click

     

    Tuesday, September 13, 2011 4:56 AM
  • User1784691416 posted

    Yes tarun..

    I had set the culture already and its coming proper... but not values for the corresponding culture is not coming

    Tuesday, September 13, 2011 5:03 AM
  • User699558600 posted

    This is my master page code

    do you see i again redirect user to the same page so that localized values are set

    Protected Sub SubmitLanguage_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SubmitLanguage.Click
            SetCulture()
        End Sub
        
        Private Sub SetCulture()
            Common.Culture = LanguageList.SelectedValue
            Dim CultureInfo = New Globalization.CultureInfo(Common.Culture) ' see Common.Culture below
            Threading.Thread.CurrentThread.CurrentCulture = CultureInfo
            Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo
               Response.Redirect(Request.RawUrl) ' load same page again
        End Sub
    
    

    here is my page init code

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim CultureInfo = New Globalization.CultureInfo(Common.Culture)
            Dim UserIdentityId%
            Threading.Thread.CurrentThread.CurrentCulture = CultureInfo
            Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo
    End Sub
    

     Here is my method to set the culture it is in Common Class, so i call it like Common.Culture

    ' if no culture is defined it returns english always
    Public Shared Property Culture$()
            Set(ByVal value$)
                HttpContext.Current.Session!Culture = value
            End Set
            Get
                If String.IsNullOrEmpty(HttpContext.Current.Session!Culture) Then
                    Culture = "en-US"
                    Return Culture
                End If
                Return HttpContext.Current.Session!Culture
            End Get
        End Property
    
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 13, 2011 5:18 AM