Localization ASP.NET MVC2 and JQuery
Wednesday, August 04 2010 - mvc
I hate localization (who doesn’t). It’s one of those things that are always painful, even when you build for it.
I somewhat unexpectedly need to localize some greenfield development. The main site is MVC2, but also makes use of JQuery and reuses some existing domain logic. So here’s the stumbling block. How do I localize the JQuery and various javascript functions, especially around validation?
MVC2 has a pretty good story here. Your annotations on the model’s can contain the error messages, which can easily be localized. MVC2 also has client-side validation built in so you can use the same type of procedure to get that working and again localization is easy and pretty slick. The problem, is that MVC2’s client-side validation isn’t all that robust, so I’ve used JQuery.Validation on some pages.
Any thoughts on how I localize my error messages strictly from javascript? I only need to support a couple of languages so my first thought was to build a couple of arrays each containing the language specific strings and then do a lookup into each array grabbing the correct string. It’s blunt force localization, but it will work at the cost of carrying around those heavy strings on each page.
Another thought was to use the controllers/views to inject the correct language specific strings into the javascript. This has the benefit of being a lighter weight solution and (somewhat) easier to test.
The final thought was to abandon JQuery.Validate and go with what’s available in MVC2. That means I will lose some of the slick features I want, unless I rewrite them using custom code, but it does give me a consistent localization experience.
Any advice?




