1

Working with attribute routing for mvc4 and very happy with it.

I have a question though, my site supports 2 languages and I have localized all my url's. The supported languages are french and english.

When the site is in english, I would like to show a link to switch to french, and ve se versa.

With attribute routing, is there way to generate a url for a specific culture/language? Currently when the site is in english, all the url's are localized in English. I am wondering if it would be possible to generate this one link in French.

1
  • I am trying to understand what you meant when you wrote "generate a url", since AttributeRouting does not generate urls--it matches them. Would you please include a code sample? Commented Jun 13, 2013 at 18:46

1 Answer 1

-2

While this guide was written for MVC 2, I think it'll help..

http://adamyan.blogspot.com/2010/02/aspnet-mvc-2-localization-complete.html

Now we'll create simple user control with supported culture hyper links. Add new partial view to Views\Shared folder CultureChooserUserControl.ascx and paste following

<%= Html.ActionLink("English", "ChangeCulture", "Account",  
     new { lang = "en", returnUrl = this.Request.RawUrl }, null)%>
<%= Html.ActionLink("Русский", "ChangeCulture", "Account",  
     new { lang = "ru", returnUrl = this.Request.RawUrl }, null)%>

We just now created two hyper links, first one for English and second one for Russian languages. And now its time to place this culture chooser user control to Site.Master master page. I'll add this to corresponding to login functionality just as an example.

I am not an expert on localization and may be leading you down the wrong path

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the answer, but no, this is not what I required. My question is regarding attribute routing and how it could generate a localized url for a specific culture.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.