Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Configuration for route localization in ASP.NET MVC app
namespace RouteLocalizationDemo
{
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using RouteLocalization.Mvc;
using RouteLocalization.Mvc.Setup;
using Controllers;
public class RouteConfig
{
/* Public static methods */
public static void RegisterRoutes(RouteCollection routes)
{
const string DefaultCulture = "en";
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes(Localization.LocalizationDirectRouteProvider);
ISet<string> acceptedCultures = new HashSet<string>() { "en", "de" };
var configuration = new Configuration
{
DefaultCulture = DefaultCulture,
AcceptedCultures = acceptedCultures,
AttributeRouteProcessing = AttributeRouteProcessing.AddAsNeutralAndDefaultCultureRoute,
AddCultureAsRoutePrefix = true
};
var localization = new Localization(configuration);
localization.TranslateInitialAttributeRoutes();
localization.ForCulture("de")
.ForController<HomeController>()
.ForAction(x => x.About())
.AddTranslation("ÜberUns")
.ForAction(x => x.Contact())
.AddTranslation("Kontakt");
CultureSensitiveHttpModule.GetCultureFromHttpContextDelegate = Localization.DetectCultureFromBrowserUserLanguages(acceptedCultures, DefaultCulture);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.