tags:

views:

44

answers:

3

There were questions about multilingual apps in MVC here on SO but they were mostly answered by giving details about implementing Resource files and then referencing those Resource strings in Views or Controller. This works fine for me in conjunction with the detection of user's locale.

What I want to do now is support localized routes. For instance, we have some core pages for each website like the Contact Us page.

What I want to achieve is this:

1) routes like this

/en/Contact-us (English route)

/sl/Kontakt (Slovenian route)

2) these two routes both have to go to the same controller and action and these will not be localized (they will be in English because they are hidden away from the user since they are part of the site's core implementation):

My thought is to make the Controller "Feedback" and Action "FeedbackForm"

3) FeedbackForm would be a View or View User control (and it would use references to strings in RESX files, as I said before, I already have set this up and it works)

4) I have a SetCulture attribute attached to BaseController which is the parent of all of my controllers and this attribute actually inherits FilterAttribute and implements IActionFilter - but what does it do? Well, it detects browser culture and sets that culture in a Session and in a cookie (forever) - this functionality is working fine too. It already effects the Views and View User Controls but at this time it does not effect routes.

5) at the top of the page I will give the user a chance to choose his language (sl|en). This decision must override 4). If a user arrives at our website and is detected as Slovenian and they decide to switch to English, this decision must become permanent. From this time on SetCulture attribute must somehow loose its effect.

6) After the switch, routes should immediately update - if the user was located at /sl/Kontakt he should immediately be redirected to /en/Contact-us.

These are the constraints of the design I would like. Simply put, I do not want English routes while displaying localized content or vice-versa.

Suggestions are welcome.

EDIT:

There's some information and guidance here - http://stackoverflow.com/questions/291405/multi-lingual-websites-with-asp-net-mvc, but I would still like to hear more thoughts or practices on this problem.

A: 

Why not create the action names desired and simply RedirectToAction for the single, real implementation?

    public ActionResult Kontakt() {
        return RedirectToAction("Contact");
    }

    public ActionResult Contact() {
        return View();
    }
Tahbaza
No way, that would make a mess out of my controller classes. Just think about it, if you decide to support German or Italian, what our controllers classes will become? That also requires maintainence of controller classes but I would like to limit changes only to global.asax.cs and Resource files.
mare
+2  A: 

Translating routes (ASP.NET MVC and Webforms)

How about this? Create custom translate route class.

takepara
A: 

Localization with ASP.NET MVC using Routing

Preview:

For my site the URL schema should look like this in general:

/{culture}/{site}

Imagine there is a page called FAQ, which is available in different languages. Here are some sample URLs for these pages:

/en-US/FAQ /de-DE/FAQ /de-CH/FAQ

jfar
This is more suited for my case so I'm confirming this.
mare