views:

25

answers:

1

Have an ASP.NET MVC site that is localized. The localization functionality adds the two digit language ID to the URL, e.g. /es/Page. If no language Id is found in the URL, the site switches to the user's browser culture. All's good. However, the site's hyperlinks, a mixture of hard-coded href tags, actionlinks, etc., don't include the base language ID, so when clicking through the site the set culture is lost, and the site reverts to the user's browser culture.

My (lazy) thought is to replace all href values, that don't point to an external site, with the localized URL (e.g. include the /es/). Otherwise, all site links will need to be updated to include the culture code.

Is this just plain dumb? Or, reasonable, and should be done using a custom view engine, or some other approach?

A: 

My answer is (currently):

The app has a base controller, there I've added:

if (PathLanguageCode == "" && requestContext.HttpContext.Session["LanguageCode"] != null && requestContext.HttpContext.Request.RequestType == "GET")
{
    requestContext.HttpContext.Response.Redirect("/" + requestContext.HttpContext.Session["LanguageCode"] + requestContext.HttpContext.Request.RawUrl);
}

This example doesn't show how the PathLanguageCode variable is defined, but it should at least suffice to show how this can be handled centrally, without replacing string values.

The one downside to this approach, that I can see, is that the site really isn't friendly for search engines, etc., since we end up doing a lot of redirects.

Roger Rogers