Is translations possible using only route attributes?
As I am using a custom scaffolder, it would be much easier if the translations would be replaced by a route attribute on the controllers/actions.
Something like: [LocalizedRoute("{culture}/services/contact-us", "en-CA")] [LocalizedRoute("{culture}/services/nous-joindre", "fr-CA")]
Is this something that is already supported? If not, is there another way around to meet my goal and can this feature be added?
It's not supported out of the box, but maybe you could do something like this?
Hmmm I fail to see how I could define 2 localized routes for an action using that method. I can't do a redirect.
See this localized-route-attribute branch and the RouteConfig.cs and HomeController.cs of the sample project.
Thanks Dresel! It's working exactly as expected. The only thing I cannot get working is the CurrentCulture and CurrentUICulture to switch automatically. I tried both of your CultureSensitiveActionFilterAttribute and CultureSensitiveHttpModule but no change.
Does it work in the sample project of the localized-route-attribute? "en/Welcome" should switch to englisch culture and "de/Willkommen" to german culture. Maybe you have something else registered that overrides the filter / module.
Yes your branch works. I got it working on my test project. My LocalizedRouteAttribute was inheriting from RouteFactoryAttribute. I also didn't have the [Route("Index")]. Anyway to drop the [Route] attribute altogether? I imagine this serves as the default route that is then translated by the LocalizedRoute attribute.