Skip to content

Instantly share code, notes, and snippets.

@moaschterle
Created July 23, 2013 20:05
Show Gist options
  • Save moaschterle/6065673 to your computer and use it in GitHub Desktop.
Save moaschterle/6065673 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace TestMigration
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
public static void MapRoutes(RouteCollection routes)
{
CultureInfo cultureDE = CultureInfo.GetCultureInfo("DE");
CultureInfo cultureEN = CultureInfo.GetCultureInfo("EN");
CultureInfo cultureIT = CultureInfo.GetCultureInfo("IT");
//Routes aus DB Mappen
DictionaryRouteValueTranslationProvider translationProvider = new DictionaryRouteValueTranslationProvider(
new List<RouteValueTranslation> {
new RouteValueTranslation(cultureDE, "Home", "Heim"),
new RouteValueTranslation(cultureDE, "Forms", "Formulare"),
//new RouteValueTranslation(cultureDE, "DynamicTest", "Lorfer"),
new RouteValueTranslation(cultureDE, "Test2", "Klo"),
new RouteValueTranslation(cultureIT, "Home", "Start"),
new RouteValueTranslation(cultureIT, "Forms", "Formulari"),
new RouteValueTranslation(cultureEN, "Home", "Home"),
new RouteValueTranslation(cultureEN, "Forms", "Forms"),
//new RouteValueTranslation(cultureEN, "DynamicTest", "DynamicTest")
}
);
DictionaryRouteValueTranslationProvider dynamictranslationProvider = new DictionaryRouteValueTranslationProvider(
new List<RouteValueTranslation> {
new RouteValueTranslation(cultureDE, "Home", "Heim"),
new RouteValueTranslation(cultureDE, "Forms", "Formulare"),
new RouteValueTranslation(cultureDE, "DynamicTest", "Lorfer"),
new RouteValueTranslation(cultureDE, "Test2", "Klo"),
new RouteValueTranslation(cultureIT, "Home", "Start"),
new RouteValueTranslation(cultureIT, "Forms", "Formulari"),
new RouteValueTranslation(cultureEN, "Home", "Home"),
new RouteValueTranslation(cultureEN, "Forms", "Forms"),
new RouteValueTranslation(cultureEN, "DynamicTest", "DynamicTest")
}
);
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//routes.MapRoute(
// "Dynamic",
// "{controller}/Dynamic{container}",
// new { controller = "Forms", action = "Dynamic", culture = cultureEN });
routes.MapTranslatedRoute(
"Dynamic",
"{controller}/Dynamic{container}",
new { controller = "Forms", action = "Dynamic", culture = cultureEN },
new { controller = dynamictranslationProvider, action = dynamictranslationProvider },
true
);
routes.MapTranslatedRoute(
"TranslatedRoute",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" },
new { controller = translationProvider, action = translationProvider },
true
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment