2

Thre's a number of post on StackOverflow as well as other sites around this topic. I was however having hard time finding anything related to MVC3 and it's specific resource keys.

In order to globally localize generic MVC messages one should:

  • Create a resource file under App_GlobalResources folder
  • set DefaultModelBinder.ResourceClassKey to the resource name (without .resx)
  • Create localized copies of MvcResources.resx under that folder and resource name

I've tested this and according to MSDN, if I set the ResourceClassKey to something non existent it should throw exception. It doesn't happen so I must be doing something wrong.

If anyone has got this working under MVC3 and Razor, here's the questions:

  • where to find the correct MvcResources.resx for MVC3? I was only able to find one for version 2
  • Where should one set the DefaultModelBinder.ResourceClassKey property? Would that be under Global.asax -> Application_Start or for each request?

Any ideas greatly appreciated.

Ales Potocnik Hahonina
  • 2,977
  • 2
  • 26
  • 32
  • 3
    Do you want to solve it in that way or do you want something easier? http://blog.gauffin.org/2011/09/easy-model-and-validation-localization-in-asp-net-mvc3/ – jgauffin Dec 16 '11 at 15:56
  • @Jonas: great article! didn't know that was possible! – Eduardo Molteni Dec 16 '11 at 19:57
  • I want the right way :) And this way seems easier in the long run. There will potentially be many, many screens that need global localization on messages and I want the set once, forget about it approach. – Ales Potocnik Hahonina Dec 16 '11 at 21:47
  • Sorry jgauffin. I posted a comment before I read your approach. Seems promising. Will give it a try on Monday. And I'm glad we agree on on the "don't do that" part. – Ales Potocnik Hahonina Dec 16 '11 at 21:52
  • I've tested the Griffin.MvcContrib library and the approach seems very appealing. However, there seems to be a problem when Thread.CurrentThread.CurrentCulture and CurrentUICulture is changed dynamically after application startup. Because in Application_Start one would register a specific resource manager it would appear the approach only works for when application is localized only to one specific language - not when it supports multiple languages (cultures) and allows users to change it. Please correct me if I'm wrong. – Ales Potocnik Hahonina Dec 19 '11 at 09:51
  • 1
    Got it to work properly. Programmer error, as usual - one of the resource files was set as Content instead of Embedded Resource. Can you please add a formal answer so it can be accepted. – Ales Potocnik Hahonina Dec 19 '11 at 11:35

1 Answers1

0

where to find the correct MvcResources.resx for MVC

http://aspnetwebstack.codeplex.com/SourceControl/latest

RouR
  • 6,136
  • 3
  • 34
  • 25