Reputation: 10306
I'm going to implement an ASP.NET MVC3 powered site which will be multilingual with distinct Urls for different languages (ie. http://acme.com/en/faq, http://acme.com/de/faq etc).
Is the way outlined in this article still the way to go with ASP.Net MVC3?
Upvotes: 0
Views: 543
Reputation: 26690
I haven't use a route handler like the author of the blog suggest but it seems like a good idea.
I typically just add the language as a parameter to the route, though.
routes.MapRoute("someroute", "{language}/some/path/{p1}/{p2}",
new { controller = "SomeController", action = "SomeAction"});
You can default the language parameter right there on the route definition but I usually do it on the base controller since I try to default to the language that the user has defined on their browser preferences (it comes in the HTTP request.)
One caveat of the approach described in the blog post is that is changes the main "CurrentCulture". You don't want to change the main "CurrentCulture" on every request, you only need to change the "CurrentUICulture". Changing the main "CurrentCulture" would affect the way your server behaves. For example, when talking to the database it will be using the user's culture and that's probably not what you want.
People tend to change the main CurrentCulture to gain formatting on dates and numbers (which is nice) but don't realize there are some side effects to doing that. Instead of changing the main CultureThread you'll need to pass the users' culture to your number and formatting functions (e.g. someDate.ToString(format, culture)
Upvotes: 3