views:

184

answers:

1

I wanted to see if there is a way to use the request URL/URL rewriting to set the language a page is rendered in by examining a portion of the URL in ASP.NET. We have a site that already works with ASP.NET’s resource localization and user’s can change the language that they see pages/resources on the site in, however the current mechanism in not very search engine friendly since the language variations for each language all appear as one page. It would be much better if we could have pages like www.site.com/en-mx/realfolder/realpage.aspx that allow linking to culture specific versions of a page.

I know lots of people have likely done localization through URL structures before and I wanted to know if one of your could share how to do this in the Global.asax file or with an HTTP Module (pointing to links to blog postings would be great too). We have a restriction that the site is based on ASP.NET 2.0 (so we can't used the 3.5+ features yet).

Here is the example scenario:

A real page exits at: www.site.com/realfolder/realpage.aspx

The page has a mechanism for the user to change the language it is displayed in via a dropdown.

There are search engine optimization and user links sharing benefits to doing this since people can link directly to a page that has content that is applicable to a certain language (this could also include right-to-left layouts for languages like Japanese).

I would like to use an HTTP module to see if the first part of the URL after www.site.com, site.com, subdomain.site.com, etc. contains a valid culture code (e.g. en-us, es-mx) then use that value to set the localization culture of the page/resources based on that URL.

So if the user accesses the URL www.site.com/en-MX/realfolder/realpage.aspx

Then the page will render in Mexico’s variant of Spanish.

If the user goes to www.site.com/realfolder/realpage.aspx directly the page would just use their browser’s language settings.

A: 

Im doing it in the global.asax, as this answer explains, then I set up different urls in the master page to change the language depending on the current one:

ie:

    If Request.Path.Contains("/en/") Then
        DestinationPathEs = Request.Path.Replace("/en/", "/es/")
        DestinationPathPt = Request.Path.Replace("/en/", "/pt/")

        litLangBar.Text = "<span id='langbares'><a href='" & DestinationPathEs & "'>Español</a></span>"
        litLangBar.Text += "<span id='langbarpt'><a href='" & DestinationPathPt & "'>Portugues</a></span>"
        litLangBar.Text += "<span id='langbaren' class='active'>English</span>"
Eduardo Molteni