How to localize ASP.NET MVC application?

asp.net MvcLocalizationGlobalization

asp.net Mvc Problem Overview


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 some kind 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?

asp.net Mvc Solutions


Solution 1 - asp.net Mvc

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.

Solution 2 - asp.net Mvc

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.

Solution 3 - asp.net Mvc

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

Solution 4 - asp.net Mvc

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

http://wekeroad.com/2008/04/24/mvcstore-part-5

Solution 5 - asp.net Mvc

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

Solution 6 - asp.net Mvc

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

Solution 7 - asp.net Mvc

We actually went a complete different with overriding the DataAnnotationsMetadaDataProvider. In there you can make sure that the DisplayNameAttribute values are resolved into the correct language. Actually you could even get rid of that attribute and resolve by field names only if that would be any help.

Solution 8 - asp.net Mvc

I wrote this article a while ago. It uses a custom view engine. http://blog.oimae.com/2011/02/20/cultured-view-engine-for-mvc/

Solution 9 - asp.net Mvc

And another tutorial for different solution

Tutorial: Create ASP.NET MVC localization with language detection

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpirhoView Question on Stackoverflow
Solution 1 - asp.net MvcfyasarView Answer on Stackoverflow
Solution 2 - asp.net MvcElijah ManorView Answer on Stackoverflow
Solution 3 - asp.net MvckevintechieView Answer on Stackoverflow
Solution 4 - asp.net MvcJoel CunninghamView Answer on Stackoverflow
Solution 5 - asp.net MvcIan TView Answer on Stackoverflow
Solution 6 - asp.net Mvcuser405803View Answer on Stackoverflow
Solution 7 - asp.net MvcMichael SanderView Answer on Stackoverflow
Solution 8 - asp.net MvcVladView Answer on Stackoverflow
Solution 9 - asp.net MvcNikolaView Answer on Stackoverflow