Click here to Skip to main content
12,695,049 members (33,598 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads

Stats

357.2K views
5.6K downloads
210 bookmarked
Posted

Creating multilingual websites - Part 2

, 25 Aug 2004
Creating multilingual websites - Part 2
LocalizedSample
bin
Localization.dll
LocalizedSample.dll
language
en-CA
fr-CA
Localization
bin
Localization.csproj.user
Localization.resharperoptions
LocalizedSample.csproj.webinfo
LocalizedSample.resharperoptions
LocalizedSampleVB
bin
Localization.dll
LocalizedSampleVB.dll
language
en-CA
fr-CA
Localization
bin
Localization.dll
Localization.vbproj.user
LocalizedSampleVB.resharperoptions
LocalizedSampleVB.vbproj.webinfo
Imports System.Web
Imports System.Threading
Imports System.Globalization

Public Class LocalizationHttpModule
   Implements IHttpModule

   Public Sub Dispose() Implements IHttpModule.Dispose
   End Sub

   Public Sub Init(ByVal context As HttpApplication) Implements IHttpModule.Init
      AddHandler context.BeginRequest, AddressOf context_BeginRequest
   End Sub

   Private Sub context_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
      Dim request As HttpRequest = CType(sender, HttpApplication).Request
      Dim context As HttpContext = CType(sender, HttpApplication).Context
      Dim applicationPath As String = request.ApplicationPath
      If applicationPath = "/" Then
         applicationPath = String.Empty
      End If
      Dim requestPath As String = request.Url.AbsolutePath.Substring(applicationPath.Length)
      LoadCulture(requestPath)
      context.RewritePath(applicationPath + requestPath)
   End Sub

   Private Sub LoadCulture(ByRef path As String)
      Dim pathParts() As String = path.Trim("/"c).Split("/"c)
      Dim defaultCulture As String = LocalizationConfiguration.GetConfig.DefaultCultureName
      If pathParts.Length > 0 AndAlso pathParts(0).Length > 0 Then
         Try
            Thread.CurrentThread.CurrentCulture = New CultureInfo(pathParts(0))
            path = path.Remove(0, pathParts(0).Length + 1)
         Catch ex As Exception
            If Not TypeOf ex Is ArgumentNullException AndAlso Not TypeOf ex Is ArgumentException Then
               Throw
            End If
            Thread.CurrentThread.CurrentCulture = New CultureInfo(defaultCulture)
         End Try
      End If
      Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture
   End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Karl Seguin
Canada Canada
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 26 Aug 2004
Article Copyright 2004 by Karl Seguin
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid