123

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?

splattne
  • 102,760
  • 52
  • 202
  • 249
pirho
  • 2,972
  • 4
  • 23
  • 17
  • Alternatively to duplicated views, you can use standard ResX files for storing culture specific strings. Unfortunately, managing and editing this files, especially by translators is a bit uncomfortable and difficult. It can be simplified by storing resources in database and using some external localization tool. You can look at this free library delivering database resource provider: http://globsite.net/GlobsiteGlobalizationLibrary – Kryszal Jan 10 '16 at 21:40

9 Answers9

73

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
  • 3,996
  • 2
  • 42
  • 55
  • 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 Aug 24 '10 at 19:01
  • I used to use this approach in my projects, I should say that this approach is better. – fyasar Aug 25 '10 at 06:49
  • @fyasar hi, we have a shopping website in asp mvc , so when user selects arabic language, we want to make the whole site arabic , can we use microsoft bing [translator](https://www.bing.com/translator/) or microsoft [translator API](http://www.microsoft.com/en-us/translator/products.aspx) or should i buy [localize.js](https://localizejs.com/features) to achieve this fast ? – Shaiju T Oct 06 '15 at 22:41
22

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
  • 17,923
  • 17
  • 72
  • 79
9

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,441
  • 1
  • 13
  • 15
3

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

Kyle
  • 17,317
  • 32
  • 140
  • 246
Joel Cunningham
  • 13,620
  • 8
  • 43
  • 49
2

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
  • 33
  • 3
2

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

user405803
  • 29
  • 1
1

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.

Michael Sander
  • 2,677
  • 23
  • 29
0

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/

Vlad
  • 201
  • 2
  • 2
  • 1
    While your article may in fact answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. Stack Overflow is only as useful as its questions and answers, and if your blog host goes down or your URLs get moved around, this answer becomes useless. Thanks! – sarnold Feb 25 '12 at 02:07
-1

And another tutorial for different solution

Tutorial: Create ASP.NET MVC localization with language detection

Nikola
  • 144
  • 1
  • 3