public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapMvcAttributeRoutes(Localization.LocalizationDirectRouteProvider); // Route Translations Provider Configuration & Registration routes.Localization(config => { config.DefaultCulture = "en"; config.AcceptedCultures = new HashSet <string>() { "en", "fr" }; config.AttributeRouteProcessing = AttributeRouteProcessing.AddAsNeutralAndDefaultCultureRoute; config.AddTranslationToSimiliarUrls = true; }).TranslateInitialAttributeRoutes().Translate(localization => { localization.RegisterRouteTranslations(); }); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); }
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.AppendTrailingSlash = true; routes.LowercaseUrls = true; routes.MapMvcAttributeRoutes(Localization.LocalizationDirectRouteProvider); routes.Localization(configuration => { configuration.DefaultCulture = LocalizationConfig.DefaultCulture; configuration.AcceptedCultures = LocalizationConfig.AcceptedCultures; configuration.AttributeRouteProcessing = AttributeRouteProcessing.AddAsNeutralAndDefaultCultureRoute; configuration.AddCultureAsRoutePrefix = true; }).Translate(localization => { localization.TranslateInitialAttributeRoutes(); localization.ForCulture("da") .ForController<HomeController>() .ForAction(x => x.Index()) .AddTranslation(string.Empty); }); CultureSensitiveHttpModule.GetCultureFromHttpContextDelegate = Localization.DetectCultureFromBrowserUserLanguages(LocalizationConfig.AcceptedCultures, LocalizationConfig.DefaultCulture); // Default route fallback routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); }
public static void RegisterRoutes(RouteCollection routes) { /* routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); */ routes.MapMvcAttributeRoutes(Localization.LocalizationDirectRouteProvider); Localization localization = routes.Localization(x => { x.DefaultCulture = "pt"; x.AcceptedCultures = new HashSet<string>() { "pt", "en" }; x.AttributeRouteProcessing = RouteLocalization.Mvc.Setup.AttributeRouteProcessing.AddAsDefaultCultureRoute; x.AddCultureAsRoutePrefix = true; x.AddTranslationToSimiliarUrls = true; }); localization.TranslateInitialAttributeRoutes().Translate(x => { x.ForCulture("en").ForNamedRoute("home.index").AddTranslation("home"); x.ForCulture("en") .ForController<AccountController>().ForAction("Login").AddTranslation("home"); x.ForCulture("en") .ForController<HomeController>().ForAction("OwinTest").AddTranslation("owin-test") .ForController<HomeController>().ForAction("FormTest").AddTranslation("form-test"); }); CultureSensitiveHttpModule.GetCultureFromHttpContextDelegate = context => { return new CultureInfo("pt"); }; RouteTable.Routes.MapRoute("Start", String.Empty, new { controller = "Home", action = "Start" }); // Missing routes RouteTable.Routes.MapRoute("404", "{*url}", new { controller = "Error", action = "NotFound_" }); // Register areas AreaRegistration.RegisterAllAreas(); }
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // New workflow since 5.2 // This provider wraps generated attribute routes with LocalizationCollectionRoute routes ////LocalizationDirectRouteProvider provider //// = new LocalizationDirectRouteProvider(new DefaultDirectRouteProvider()); // For less code preparation use the static provider stored in Localization class routes.MapMvcAttributeRoutes(Localization.LocalizationDirectRouteProvider); const string defaultCulture = "en"; ISet<string> acceptedCultures = new HashSet<string>() { defaultCulture, "en-US", "de", "de-AT" }; // Add translations // You can translate every specific route that contains default Controller and Action (which MapMvcAttributeRoutes does) routes.Localization(configuration => { // Important: Set the route collection from LocalizationDirectRouteProvider if you specify your own //// configuration.LocalizationCollectionRoutes = provider.LocalizationCollectionRoutes; configuration.DefaultCulture = defaultCulture; configuration.AcceptedCultures = acceptedCultures; // Define how attribute routes should be processed: // * None: There will be no routes except the ones you explicitly define in Translate() // * AddAsNeutralRoute: Every attribute route will be added as neutral route // * AddAsDefaultCultureRoute: Every attribute route will be added as localized route for defined default culture // * AddAsNeutralAndDefaultCultureRoute: Every attribute route will be added as neutral route and // as localized route for defined default culture // * AddAsNeutralRouteAndReplaceByFirstTranslation: Every attribute route will be added as neutral route first, but when // you add a translation for a route, the neutral route will be removed configuration.AttributeRouteProcessing = AttributeRouteProcessing.AddAsNeutralAndDefaultCultureRoute; // Uncomment if you do not want the culture (en, de, ...) added to each translated route as route prefix configuration.AddCultureAsRoutePrefix = true; configuration.AddTranslationToSimiliarUrls = true; }).TranslateInitialAttributeRoutes().Translate(localization => { // Use extension methods if you want to separate route configuration localization.AddDefaultRoutesTranslation(); localization.AddAreaRoutesTranslation(); // DefaultRoutes.cs ////localization.ForCulture("de") //// .ForController<HomeController>() //// .ForAction(x => x.Index()) //// .AddTranslation("Willkommen") //// .ForAction(x => x.Book()) //// .AddTranslation("Buch/{chapter}/{page}"); ////localization.ForCulture("de") //// .ForController<HomeWithRoutePrefixAttributeController>() //// .SetRoutePrefix("RoutePrefixDE") //// .ForAction(x => x.Index()) //// .AddTranslation("Willkommen") //// .ForAction(x => x.Book()) //// .AddTranslation("Buch/{chapter}/{page}"); ////localization.ForCulture("de") //// .SetAreaPrefix("AreaPrefixDE") //// .ForController<HomeWithRouteAreaAttributeController>() //// .ForAction(x => x.Index()) //// .AddTranslation("Willkommen") //// .ForAction(x => x.Book()) //// .AddTranslation("Buch/{chapter}/{page}"); // AreaRoutes.cs ////localization.ForCulture("de") //// .SetAreaPrefix("Area") //// .ForController<Areas.Area.Controllers.HomeController>() //// .ForAction(x => x.Index()) //// .AddTranslation("Willkommen") //// .ForAction(x => x.Book()) //// .AddTranslation("Buch/{chapter}/{page}"); }); // Optional // Setup CultureSensitiveHttpModule // This Module sets the Thread Culture and UICulture from http context // Use predefined DetectCultureFromBrowserUserLanguages delegate or implement your own CultureSensitiveHttpModule.GetCultureFromHttpContextDelegate = Localization.DetectCultureFromBrowserUserLanguages(acceptedCultures, defaultCulture); // Optional // Add culture sensitive action filter attribute // This sets the Culture and UICulture when a localized route is executed GlobalFilters.Filters.Add(new CultureSensitiveActionFilterAttribute() { // Set this options only if you want to support detection of region dependent cultures // Supports this use case: https://github.com/Dresel/RouteLocalization/issues/38#issuecomment-70999613 AcceptedCultures = acceptedCultures, TryToPreserverBrowserRegionCulture = true }); }
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // New workflow since 5.2 // This provider wraps generated attribute routes with LocalizationCollectionRoute routes ////LocalizationDirectRouteProvider provider //// = new LocalizationDirectRouteProvider(new DefaultDirectRouteProvider()); // For less code preparation use the static provider stored in Localization class routes.MapMvcAttributeRoutes(Localization.LocalizationDirectRouteProvider); const string defaultCulture = "en"; ISet <string> acceptedCultures = new HashSet <string>() { defaultCulture, "en-US", "de", "de-AT" }; // Add translations // You can translate every specific route that contains default Controller and Action (which MapMvcAttributeRoutes does) routes.Localization(configuration => { // Important: Set the route collection from LocalizationDirectRouteProvider if you specify your own //// configuration.LocalizationCollectionRoutes = provider.LocalizationCollectionRoutes; configuration.DefaultCulture = defaultCulture; configuration.AcceptedCultures = acceptedCultures; // Define how attribute routes should be processed: // * None: There will be no routes except the ones you explicitly define in Translate() // * AddAsNeutralRoute: Every attribute route will be added as neutral route // * AddAsDefaultCultureRoute: Every attribute route will be added as localized route for defined default culture // * AddAsNeutralAndDefaultCultureRoute: Every attribute route will be added as neutral route and // as localized route for defined default culture // * AddAsNeutralRouteAndReplaceByFirstTranslation: Every attribute route will be added as neutral route first, but when // you add a translation for a route, the neutral route will be removed configuration.AttributeRouteProcessing = AttributeRouteProcessing.AddAsNeutralAndDefaultCultureRoute; // Uncomment if you do not want the culture (en, de, ...) added to each translated route as route prefix configuration.AddCultureAsRoutePrefix = true; configuration.AddTranslationToSimiliarUrls = true; }).TranslateInitialAttributeRoutes().Translate(localization => { // Use extension methods if you want to separate route configuration localization.AddDefaultRoutesTranslation(); localization.AddAreaRoutesTranslation(); // DefaultRoutes.cs ////localization.ForCulture("de") //// .ForController<HomeController>() //// .ForAction(x => x.Index()) //// .AddTranslation("Willkommen") //// .ForAction(x => x.Book()) //// .AddTranslation("Buch/{chapter}/{page}"); ////localization.ForCulture("de") //// .ForController<HomeWithRoutePrefixAttributeController>() //// .SetRoutePrefix("RoutePrefixDE") //// .ForAction(x => x.Index()) //// .AddTranslation("Willkommen") //// .ForAction(x => x.Book()) //// .AddTranslation("Buch/{chapter}/{page}"); ////localization.ForCulture("de") //// .SetAreaPrefix("AreaPrefixDE") //// .ForController<HomeWithRouteAreaAttributeController>() //// .ForAction(x => x.Index()) //// .AddTranslation("Willkommen") //// .ForAction(x => x.Book()) //// .AddTranslation("Buch/{chapter}/{page}"); // AreaRoutes.cs ////localization.ForCulture("de") //// .SetAreaPrefix("Area") //// .ForController<Areas.Area.Controllers.HomeController>() //// .ForAction(x => x.Index()) //// .AddTranslation("Willkommen") //// .ForAction(x => x.Book()) //// .AddTranslation("Buch/{chapter}/{page}"); }); // Optional // Setup CultureSensitiveHttpModule // This Module sets the Thread Culture and UICulture from http context // Use predefined DetectCultureFromBrowserUserLanguages delegate or implement your own CultureSensitiveHttpModule.GetCultureFromHttpContextDelegate = Localization.DetectCultureFromBrowserUserLanguages(acceptedCultures, defaultCulture); // Optional // Add culture sensitive action filter attribute // This sets the Culture and UICulture when a localized route is executed GlobalFilters.Filters.Add(new CultureSensitiveActionFilterAttribute() { // Set this options only if you want to support detection of region dependent cultures // Supports this use case: https://github.com/Dresel/RouteLocalization/issues/38#issuecomment-70999613 AcceptedCultures = acceptedCultures, TryToPreserverBrowserRegionCulture = true }); }
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.LowercaseUrls = true; #region Route Localization string defaultCulture = ""; ISet <string> acceptedCultures = new HashSet <string>(); foreach (CultureElement c in CommonStaticData.CulturesSection.Cultures) { acceptedCultures.Add(c.Name); if (c.IsDefault) { defaultCulture = c.Name; } } routes.MapMvcAttributeRoutes(RouteLocalization.Mvc.Localization.LocalizationDirectRouteProvider); // Add translations // You can translate every specific route that contains default Controller and Action (which MapMvcAttributeRoutes does) routes.Localization(configuration => { // Important: Set the route collection from LocalizationDirectRouteProvider if you specify your own //// configuration.LocalizationCollectionRoutes = provider.LocalizationCollectionRoutes; configuration.DefaultCulture = defaultCulture; configuration.AcceptedCultures = acceptedCultures; // Define how attribute routes should be processed: // * None: There will be no routes except the ones you explicitly define in Translate() // * AddAsNeutralRoute: Every attribute route will be added as neutral route // * AddAsDefaultCultureRoute: Every attribute route will be added as localized route for defined default culture // * AddAsNeutralAndDefaultCultureRoute: Every attribute route will be added as neutral route and // as localized route for defined default culture // * AddAsNeutralRouteAndReplaceByFirstTranslation: Every attribute route will be added as neutral route first, but when // you add a translation for a route, the neutral route will be removed configuration.AttributeRouteProcessing = AttributeRouteProcessing.AddAsNeutralAndDefaultCultureRoute; // Uncomment if you do not want the culture (en, de, ...) added to each translated route as route prefix configuration.AddCultureAsRoutePrefix = true; configuration.AddTranslationToSimiliarUrls = true; }).TranslateInitialAttributeRoutes().Translate(localization => { foreach (CultureElement c in CommonStaticData.CulturesSection.Cultures) { var cultureName = c.Name; if (!c.IsDefault) { foreach (CultureTranslationElement ct in c.Translations) { localization.ForCulture(cultureName) .ForController(ct.Controller, ct.ControllerNamespace) .ForAction(ct.Action) .AddTranslation(ct.Value); } } } }); // Optional // Setup CultureSensitiveHttpModule // This Module sets the Thread Culture and UICulture from http context // Use predefined DetectCultureFromBrowserUserLanguages delegate or implement your own CultureSensitiveHttpModule.GetCultureFromHttpContextDelegate = RouteLocalization.Mvc.Localization.DetectCultureFromBrowserUserLanguages(acceptedCultures, defaultCulture); // Optional // Add culture sensitive action filter attribute // This sets the Culture and UICulture when a localized route is executed GlobalFilters.Filters.Add(new CultureSensitiveActionFilterAttribute() { // Set this options only if you want to support detection of region dependent cultures // Supports this use case: https://github.com/Dresel/RouteLocalization/issues/38#issuecomment-70999613 AcceptedCultures = acceptedCultures, TryToPreserverBrowserRegionCulture = true }); #endregion routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces: new[] { "DigitalLeader.Web.Controllers" } ); }