Dresel / RouteLocalization

RouteLocalization is an MVC and Web API package that allows localization of your attribute routes.
MIT License
67 stars 13 forks source link

Is translations possible using only route attributes? #77

Open vallieresch opened 5 years ago

vallieresch commented 5 years ago

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?

Dresel commented 5 years ago

It's not supported out of the box, but maybe you could do something like this?

vallieresch commented 5 years ago

Hmmm I fail to see how I could define 2 localized routes for an action using that method. I can't do a redirect.

Dresel commented 5 years ago

See this localized-route-attribute branch and the RouteConfig.cs and HomeController.cs of the sample project.

vallieresch commented 5 years ago

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.

Dresel commented 5 years ago

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.

vallieresch commented 5 years ago

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.