Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 6183f651f9f5ba965f11d3b13ddcb3ee3e8178ea 1 parent 4799d9a
Atul Varma authored
1  js/require-config.js
@@ -52,6 +52,7 @@ var require = {
52 52
       exports: "CodeMirror"
53 53
     }
54 54
   },
  55
+  packages: ['slowparse-errors'],
55 56
   paths: {
56 57
     jquery: "jquery.no-conflict",
57 58
     "jquery-tipsy": "jquery.tipsy",
12  js/slowparse-errors.js
... ...
@@ -1,12 +0,0 @@
1  
-"use strict";
2  
-
3  
-define([
4  
-  'jquery-slowparse',
5  
-  'text!slowparse/spec/errors.base.html',
6  
-  'text!slowparse/spec/errors.forbidjs.html'
7  
-], function($, base, forbidjs) {
8  
-  [base, forbidjs].forEach(function(html) {
9  
-    var div = $('<div></div>').html(html);
10  
-    $.errorTemplates = $.errorTemplates.add($(".error-msg", div));
11  
-  });
12  
-});
14  js/slowparse-errors/html-to-i18n-bundle.js
... ...
@@ -0,0 +1,14 @@
  1
+define(function() {
  2
+  return function htmlToI18nBundle(html) {
  3
+    var result = {};
  4
+    var div = document.createElement('div');
  5
+
  6
+    div.innerHTML = html;
  7
+    [].slice.call(div.querySelectorAll('.error-msg')).forEach(function(el) {
  8
+      var name = el.className.split(' ').slice(-1)[0];
  9
+      result[name] = el.innerHTML;
  10
+    });
  11
+
  12
+    return result;
  13
+  };
  14
+});
17  js/slowparse-errors/main.js
... ...
@@ -0,0 +1,17 @@
  1
+"use strict";
  2
+
  3
+define([
  4
+  'jquery-slowparse',
  5
+  'i18n!./nls/base',
  6
+  'i18n!./nls/forbidjs'
  7
+], function($, base, forbidjs) {
  8
+  function addI18nBundleToErrorTemplates(bundle) {
  9
+    Object.keys(bundle).forEach(function(key) {
  10
+      var div = $('<div></div>').html(bundle[key])
  11
+        .addClass("error-msg").addClass(key);
  12
+      $.errorTemplates = $.errorTemplates.add(div);
  13
+    });
  14
+  }
  15
+  
  16
+  [base, forbidjs].forEach(addI18nBundleToErrorTemplates);
  17
+});
6  js/slowparse-errors/nls/base.js
... ...
@@ -0,0 +1,6 @@
  1
+define([
  2
+  '../html-to-i18n-bundle',
  3
+  'text!slowparse/spec/errors.base.html'
  4
+], function(htmlToI18nBundle, base) {
  5
+  return {root: htmlToI18nBundle(base)};
  6
+});
6  js/slowparse-errors/nls/forbidjs.js
... ...
@@ -0,0 +1,6 @@
  1
+define([
  2
+  '../html-to-i18n-bundle',
  3
+  'text!slowparse/spec/errors.forbidjs.html'
  4
+], function(htmlToI18nBundle, forbidjs) {
  5
+  return {root: htmlToI18nBundle(forbidjs)};
  6
+});

0 notes on commit 6183f65

Please sign in to comment.
Something went wrong with that request. Please try again.