0

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?

2 Answers 2

3

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)

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

2 Comments

I don't quite agree with your argument in favor of unchanged CurrentCulture: If you have some processing that depend on a culture that isn't visitor's culture, which culture do you use then?
@Serge-appTranlator: If you do have a need to change the culture in the server by all means do it, just be aware that there are implications. Most people just change it because of the convenience of number and date formatting without realizing that there are other implications to be aware of.
1

Yes, nothing have changed from the routing perspective.

Comments

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.