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: 6,026 | Comments: 44,842

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.


No future posts left, oh my!


  1. Technical observations from my wife (3):
    13 Nov 2015 - Production issues
  2. Production postmortem (13):
    13 Nov 2015 - The case of the “it is slow on that machine (only)”
  3. Speaking (5):
    09 Nov 2015 - Community talk in Kiev, Ukraine–What does it take to be a good developer
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats