locked
Please help me create querystrings for each language!! RRS feed

  • Question

  • User558203916 posted

    I am not a programmer, but I managed to make my company's website in 9 languages, using Visual Studio 2010 / VB / ASP.NET 4.0. 

    It's a multilingual site, and I managed to put flags on the homepage. When I click a flag, the page's text changes to that language. When you click the French flag, it gets the information from the "FR" .resx resource file in my apps_GlobalResources folder. Great! Well, not so great. 

    The URL, for instance, about.aspx, remains about.aspx. Granted, the text changes to French, but I've been told that it's recommended to make it look like, if the client chooses French, for example, domain.com/about.aspx?lang=FR

    But I have NO idea how to do this. If anybody can guide me clearly in the right direction, it'd be sincerely appreciated. 

    Jason Weber (For reference, if anybody is kind enough to delve into this issue, which may be a simple one, all of my files I've used in this are included below -- and they're kinda lengthy)

    ----Homepage.master (how I'm calling the languages -- just 2 samples)--

          <asp:LinkButton ID="LinkButton6" runat="server"
          CommandArgument="de" OnClick="RequestLanguageChange_Click"
          class="flagbutton">      
          <asp:Image ID="Image7" runat="server" ImageUrl="~/images/flagde.png"
          tooltip="View this website in Deutsch" title="View this website in Deutsch"/>
          <img class="map" src="images/flaghoverde.png" alt=""/>
          </asp:LinkButton>
            
          <asp:LinkButton ID="LinkButton5" runat="server"
          CommandArgument="fr" OnClick="RequestLanguageChange_Click"
          class="flagbutton">      
          <asp:Image ID="Image6" runat="server" ImageUrl="~/images/flagfr.png"
          tooltip="Voir ce site en français" title="Voir ce site en français"/>
          <img class="map" src="images/flaghoverfr.png" alt=""/>
          </asp:LinkButton>

    ---------------code behind homepage.master.vb---------------------

    Partial Public Class Homepage
        Inherits System.Web.UI.MasterPage
        Protected Sub Page_Load(sender As Object, e As EventArgs)
        End Sub
    
        Protected Sub RequestLanguageChange_Click(sender As Object, e As EventArgs)
            Dim senderLink As LinkButton = TryCast(sender, LinkButton)
    
            'store requested language as new culture in the session
            Session(Udev.MasterPageWithLocalization.Classes.Global.SESSION_KEY_CULTURE) = senderLink.CommandArgument
    
            'reload last requested page with new culture
            Server.Transfer(Request.Path)
        End Sub
    End Class

    ---------------------BasePage.vb in App_Code folder--------------------

    Imports Microsoft.VisualBasic
    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Globalization
    Imports System.Threading
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls
    
    Namespace Udev.MasterPageWithLocalization.Classes
        ''' <summary>
        ''' Custom base page used for all web forms.
        ''' </summary>
        Public Class BasePage
            Inherits Page
            Protected Overrides Sub InitializeCulture()
                'retrieve culture information from session
                Dim culture__1 As String = Convert.ToString(Session([Global].SESSION_KEY_CULTURE))
    
                'check whether a culture is stored in the session
                If culture__1.Length > 0 Then
                    Culture = culture__1
                End If
    
                'set culture to current thread
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture__1)
                Thread.CurrentThread.CurrentUICulture = New CultureInfo(culture__1)
    
                'call base class
                MyBase.InitializeCulture()
            End Sub
        End Class
    End Namespace

    ----------------------Culture.vb in App_Code folder--------------------

    Imports Microsoft.VisualBasic
    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls
    
    Namespace Udev.MasterPageWithLocalization.Classes
        ''' <summary>
        ''' This class provides ISO definitions for all cultures that are supported by this application.
        ''' </summary>
        Public Structure Culture
            'German - Switzerland definition
            Public Const DE As String = "de"
            'English - Great Britain definition
            Public Const EN As String = "en"
        End Structure
    End Namespace

    ------------------Global.vb in App_Code folder------------------------

    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls
    
    Namespace Udev.MasterPageWithLocalization.Classes
        ''' <summary>
        ''' Summary description for Global
        ''' </summary>
        Public Structure [Global]
            Public Const SESSION_KEY_CULTURE As String = "culture"
        End Structure
    End Namespace

     

    Sunday, January 29, 2012 11:05 PM

All replies

  • User-744022866 posted

    You can access the querystring value in the InitializeCulture() method of page, then set the corresponding culture.

    refer this for similar sample

    http://weblogs.asp.net/sreejukg/archive/2010/11/23/multi-lingual-web-applications-using-asp-net-4.aspx

    Sunday, January 29, 2012 11:16 PM
  • User558203916 posted

    Hi Sree.  Again, I'm not a programmer.  I'm with a smaller engineering firm, so I don't have the capacity to hire somebody to do this, which is why I have gotten this far by myself.  I have all the resource files (.resx) in place, and it works fine.  Just the URLs don't add querystrings to the end.  

    I read the link you provided.  But it directly conflicts with how I set my languages up in the resource files.  So I understood the article, but I don't think it applies to my situation.  That said, I think you want me to do somethign with the InitializeCulture() in my BasePage.vb, but I'm not sure exactly what you want me to do.  If you can still help in any capacity, I'd surely appreciate any help you could offer!

    Monday, January 30, 2012 1:31 AM
  • User-744022866 posted

    How the user is going to change the language? How the client is going to choose a desired language? share some code so that I can suggest how you need to address this...

    Monday, January 30, 2012 1:17 PM