Localization on node.js + express + jquery templates

I just published jqtpl-express-i18n, a module for translations using jquery templates and express. It takes a string from the .html template and looks for a suitable translation according to the received Accept-Language header.

My first idea was to add a getter called .i18n to String.prototype using defineGetter:

String.prototype.__defineGetter__ 'i18n', () ->
    return strings['pt']?[this] || this

And this in the templates:

<p>${"Look ma I'm being translated".i18n}</p>


This didn’t work though, because you can’t access the request’s scope from the getter. I ended up extending jQuery templates after following this example, and it turned out to be much cleaner. Now my templates look like this:

	<li>{[e "Something"}}</li>
	<li>{[e "Another something"}}</li>
<input type="submit" value="{[e 'submit'}}" />

(ignore the bracket, markdown can’t handle the double braces)

I wish I could just use {["text here"}} - but I’d have to break into node-jqtpl’s house and mess with it’s privates, that wouldn’t be nice. Right?

I’m currently rewriting it to use .json files and update strings automagically, hope to get v0.2 up soon. You can get it from npm or github. Questions or issues go to https://github.com/ricardobeat/jqtpl-express-i18n.