Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 10 | Comments: 31

filter by tags archive

Handling javascript localization in Mono Rail

time to read 2 min | 282 words

I run into the issue of having to alert the user of some error, and it brought home the fact that English & Hebrew are not easy to mix. In fact, code such as this is consider a very bad sign, usually code that you don't really want to touch, see or believe in:


So, we need some sort of a way to externalize those strings, even if the only language that this application is going to use is Hebrew, simply because of the pain of mixing the two together.

After thinking about it for a while, I decided to create this view (JavascriptResources/index.brail):

for de in controller.Resources:
	resourceName = de.Key
	var ${resourceName} = {
	<% for item in GetParameter(resourceName): %>
		${item.Key}: '${item.Value.Replace("'","\\'") }',
	<% end %>
		Empty: ''

And here is the definition of the controller:

[Resource("Processes", "MyApp.Resources.Javascript.Processes")]
[Resource("Errors", "MyApp.Resources.Javascript.Errors")]
[Resource("Messages", "MyApp.Resources.Javascript.Messages")]
public class JavascriptResourcesController : Controller
	public void Index()

But what the hell does this do, anyway? Not much, actually, but it will iterate over all the registered resources for the controller, and output something that looks like this for each of those resources:

var Processes = {
 	EmploymentType: 'Employment Type',
	Details: 'Details',
	Dates: 'The dates',
	Empty: ''

The nice thing is that I can now write: alert(Errors.RecursiveError);*. As a side affect (as I said, the application is just in Hebrew so I don't care about that much), I also get the usual benefits of localization.

* You have to read Hebrew to get the joke, I am afraid.


Justin-Josef Angel [MVP]

The horrer.

It's not strongly typed! it's evil!

This is string based reference - the anti christ!

Seriously, anything gained in "easy globalzation" is lost in "oops, I changed the name of this file/group/field and everything compiled OK".

Any managed code that's compiled to Javascript should be as strongly typed as possiable as javascript is far harder to debug then managed code.

Ayende Rahien

You get a null object if you mistype something, that about it.

I know that you did a lot of stuff with JS and strong typing, but I don't see the need for those in many many cases.

Debugging JS is very easy, usually requiring merely that I would be able to run the JS in FireBug.

Debugging JS in IE is to be avoided.

Will Sahatdjian

Its 2007, your users deserve a higher level of usability than the obnoxious alert dialog. For all the time spent coming up with beautiful APIs you should round out all those amazing dev skills.


With a longer delay and a better color choice you have yourself a big improvement.

Ayende Rahien


My users are using MS CRM, obviously usability isn't a concern.

That is actually fitting in to the standard UI practices in the application, not an insult, I am more direct with those.

Comment preview

Comments have been closed on this topic.


  1. Production postmortem: The case of the memory eater and high load - 3 days from now
  2. Production postmortem: The case of the lying configuration file - 4 days from now
  3. Production postmortem: The industry at large - 5 days from now
  4. The insidious cost of allocations - 6 days from now
  5. Find the bug: The concurrent memory buster - 7 days from now

And 4 more posts are pending...

There are posts all the way to Sep 10, 2015


  1. Find the bug (5):
    20 Apr 2011 - Why do I get a Null Reference Exception?
  2. Production postmortem (10):
    14 Aug 2015 - The case of the man in the middle
  3. What is new in RavenDB 3.5 (7):
    12 Aug 2015 - Monitoring support
  4. Career planning (6):
    24 Jul 2015 - The immortal choices aren't
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats