views:

10584

answers:

8

What would be best practice to localize your ASP .Net MVC application ?

I would like to cover two situations:

  • one application deployment in IIS which would handle multiple languages
  • one language / application deployment.

In first situation should you go with somekind of view based thing like, ~/View/EN, ~/View/FI, ~/View/SWE or something different ?

What about second case, just application based config via Web.config and point these different languages to different urls ?

+8  A: 

You would localize your ASP.NET MVC application very much in the same way you would a classic ASP.NET Web Form application.

You wouldn't use different pages/views for each language, but each page would support multiple languages using satellite assemblies.

You can look at Matt Hawley's blog entry for more explanation and examples.

Elijah Manor
+4  A: 

Have a look at Rob Connery's MvcStore project. He does a screencast showing one way to solve the globalization problem.

http://blog.wekeroad.com/mvc-storefront/mvcstore-part-5/

Joel Cunningham
+8  A: 

Unfortunately, Matt Hawley's original code doesn't work in the release version of ASP.NET MVC. Check out an updated post: http://blog.eworldui.net/post/2008/10/ASPNET-MVC-Localization-via-View-Engines.aspx

In general, the localization process isn't as smooth in the VS 2008 / ASP.NET MVC world as it is with traditional web forms. http://www.guysmithferrier.com/post/2009/05/Localizing-ASPNET-MVC.aspx

kevintechie
+1  A: 

I've never been convinced of handling localization within a form as Elijah suggests - the different lengths and directions can lead to very complex or vary naff looking forms.

I'm only just starting with MVC but taking the decoupling method you would wan to use the same controller regardless of the language (treating language just as a view) - this would then give you /Controller/Action/language/form

Ian T
A: 

@kevintechie I have updated my sample to work with MVC 2 RTM.

matthawley
I realize this thread has been "necromancered", but I'm seeing 404s on the links in Elijah Manor and kevintechie's answers. Got an updated link?
mmacaulay
I updated my blog, and it seems they changed the URLs, http://blog.eworldui.net/post/2008/10/22/ASPNET-MVC-Simplified-Localization-via-ViewEngines.aspx
matthawley
+18  A: 

Hi, You can also take a look here ASP.NET MVC 2 Localization complete guide and ASP.NET MVC 2 Model Validation With Localization these entires will help you if you working with ASP.NET MVC 2.

fyasar
Thank you for this updated answer! A year ago I used Matt Hawley's approach but ran into serious problems with Unit tests. I tried mocking the controller context, but something else was still missing and I gave up. I'll go through this MVC2 way, and hope they have figured this out.
Lauri Larjo
I used to use this approach in my projects, I should say that this approach is better.
fyasar
A: 

And another tutorial for different solution

Tutorial: Create ASP.NET MVC localization with language detection

Nikola
+1  A: 

There is good tutorial with recent update on How to localize asp.net mvc application covering all aspects including DisplayName localization, Validation, using Routing (storing culture name in URL), issues with output cache and so on... Alex Adamyan Blog - While my keyboard gently weeps