Permalink
Browse files

Internationalized slowparse-errors.

This is sort of weird and inefficient right now because we convert
from HTML to an i18nbundle and back again. However, in production
builds, we will be replacing the 'nls' paths with pre-built bundles
anyways, so only one direction will be computed in production.

Ideally we might want to move all this i18n stuff into slowparse,
though, and just couple slowparse to requirejs.
  • Loading branch information...
1 parent 4799d9a commit 6183f651f9f5ba965f11d3b13ddcb3ee3e8178ea @toolness committed Dec 3, 2012
@@ -52,6 +52,7 @@ var require = {
exports: "CodeMirror"
}
},
+ packages: ['slowparse-errors'],
paths: {
jquery: "jquery.no-conflict",
"jquery-tipsy": "jquery.tipsy",
@@ -1,12 +0,0 @@
-"use strict";
-
-define([
- 'jquery-slowparse',
- 'text!slowparse/spec/errors.base.html',
- 'text!slowparse/spec/errors.forbidjs.html'
-], function($, base, forbidjs) {
- [base, forbidjs].forEach(function(html) {
- var div = $('<div></div>').html(html);
- $.errorTemplates = $.errorTemplates.add($(".error-msg", div));
- });
-});
@@ -0,0 +1,14 @@
+define(function() {
+ return function htmlToI18nBundle(html) {
+ var result = {};
+ var div = document.createElement('div');
+
+ div.innerHTML = html;
+ [].slice.call(div.querySelectorAll('.error-msg')).forEach(function(el) {
+ var name = el.className.split(' ').slice(-1)[0];
+ result[name] = el.innerHTML;
+ });
+
+ return result;
+ };
+});
@@ -0,0 +1,17 @@
+"use strict";
+
+define([
+ 'jquery-slowparse',
+ 'i18n!./nls/base',
+ 'i18n!./nls/forbidjs'
+], function($, base, forbidjs) {
+ function addI18nBundleToErrorTemplates(bundle) {
+ Object.keys(bundle).forEach(function(key) {
+ var div = $('<div></div>').html(bundle[key])
+ .addClass("error-msg").addClass(key);
+ $.errorTemplates = $.errorTemplates.add(div);
+ });
+ }
+
+ [base, forbidjs].forEach(addI18nBundleToErrorTemplates);
+});
@@ -0,0 +1,6 @@
+define([
+ '../html-to-i18n-bundle',
+ 'text!slowparse/spec/errors.base.html'
+], function(htmlToI18nBundle, base) {
+ return {root: htmlToI18nBundle(base)};
+});
@@ -0,0 +1,6 @@
+define([
+ '../html-to-i18n-bundle',
+ 'text!slowparse/spec/errors.forbidjs.html'
+], function(htmlToI18nBundle, forbidjs) {
+ return {root: htmlToI18nBundle(forbidjs)};
+});

0 comments on commit 6183f65

Please sign in to comment.