I somehow managed to make my company's website in 9 languages, using Visual Studio 2010 / VB / ASP.NET 4.0. I believe I'm using sessions. But you can tell for sure if you see the code provided below. I know this message is long, but I really need help.
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. It stays on that language for the end-user's entire session. 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!!!
(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