Loading...
 
Multi-Language Add-In for Visual Studio

Multi-Language Add-In for Visual Studio


Re: Language Menu Drop Down

Germany

I have just made a simple test with two imagebutton controls. This test is based on the code which the Add-In will to your pages when you use the command "Language Switching Support for Web Projects".

This is the minimum code required in the event handlers for the buttons (in VB.NET):

Protected Sub btGerman_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btGerman.Click

    Session.Add ( "MLCulture",   "de-DE" )    'MLHIDE
    Session.Add ( "MLUICulture", "de" )       'MLHIDE
    Response.Redirect(Request.Url.AbsolutePath)

  End Sub

  Protected Sub btEnglish_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btEnglish.Click

    Session.Add ( "MLCulture",   "en-GB" )    'MLHIDE
    Session.Add ( "MLUICulture", "en" )       'MLHIDE
    Response.Redirect(Request.Url.AbsolutePath)

  End Sub


As I mentioned above, this code is based on the code generated by the Add-In, which has two parts:

The function ml_InitCulture()

Private Sub ml_InitCulture
  
    Dim MLCultureName     as String = Session("MLCulture")            'MLHIDE
    Dim MLUICultureName   as String = Session("MLUICulture")          'MLHIDE
  
    if MLCultureName IsNot Nothing AndAlso MLCultureName.Length > 0 Then
      Page.Culture = MLCultureName
    End If
  
    if MLUICultureName IsNot Nothing AndAlso MLUICultureName.Length > 0 Then
      Page.UICulture = MLUICultureName
    End If
  
  End Sub


and a call to this function, which it adds to the Page.InitializeCulture() method.

Protected Overrides Sub InitializeCulture()
    ml_InitCulture()
  End Sub


Of course, if your project is in C#, these will be generated in C#.

As you can see, this mechanism relies on session variables. It might be better to pass the selected language in as pert of the URL. I will try to make an example of how to do this in the near future and also extend the Add-In to generate appropriate code.

Phil
22st April 2008