MvcLanguageUrls helps you to apply permanent language switch in all of your MVC application Urls.

By using this module you'll have Urls like this: www.example.com/en/sample or www.example.com/fr/sample

  • NuGet Package

PM> Install-Package MvcLanguageUrls

  • Easy to use

Usage of this module is pretty straightforward. In RegisterRoutes method of your application, just replace the default Route map with this line of code:

MvcUrlExtension.MapLocalizedRoute(routes, "en", "fr", "de", "uk");

This line indicates that application will be support these languages.

If you wish to transfer any non-localized url to use this route, insert this line of code after previous one:

MvcUrlExtension.RedirectToLocalizedRoute(routes, true);

With this code any request to "www.example.com/sample" will redirect to "www.example.com/en/sample"

Finally your RegisterRoutes will look like this:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    MvcUrlExtension.MapLocalizedRoute(routes, "en", "fr", "de", "uk");
    MvcUrlExtension.RedirectToLocalizedRoute(routes, true);
}

And that's it, you're done.

  • Additional Methods

If you wish to switch the language by generating different language Urls, there are two additional extension methods.

Html.ActionLinkLang which accepts language parameter, and of course if you don't mention it will use current culture language. And Url.ActionLang which again accepts additional language parameter.

Last edited Feb 19 at 2:58 AM by salar2k, version 8