mccalltd / AttributeRouting

Define your routes using attributes on actions in ASP.NET MVC and Web API.
http://mccalltd.github.io/AttributeRouting/
MIT License
416 stars 89 forks source link

Need to understand Localization in AR so I can apply to MVC 5. Please, help. #275

Closed mdmoura closed 11 years ago

mdmoura commented 11 years ago

Hello,

I am trying to replicate, in MVC 5, what Attribute Routing does in Localization.

So in ASP.NET MVC 4 with Attribute Routing I would have:

[GET("{culture}/about")]
public virtual ActionResult About() { }

When I check it in Glimpse I have two routes:

URL: "{culture}/about" URL: "{culture}/quemsomos"

Placeholder (Default): controller (Home) // action (About)

Parameter Name (Constraint Is Match) inboundHttpMethod (Castle.Proxies.IRouteConstraintProxy) culture (Castle.Proxies.IRouteConstraintProxy_1)

How exactly does Attribute Routing makes this to work?

My idea was to have two routes with two culture constrains and default values.

URL: "{culture}/about" with default value "en" and constraint "en" URL: "{culture}/quemsomos" with default value "pt" and constraint "pt"

But I get an error when setting the second culture constraint ...

Could some one clarify how does AR does the route localization?

And where should I look in the code?

Thank You, Miguel

Dresel commented 11 years ago

I used AttributeRouting with localization with "real" translated routes - not just a culture prefix (~/about and ~/quemsomos in your case). I migrated from MVC4 to MVC5 and implemented / migrated some localization functions (see https://github.com/Dresel/RouteLocalizationMVC), it may be useful for you...

mdmoura commented 11 years ago

Dresel, I am going to take a look and test it ... I will give some feedback on the project Github.