From 7aaf2fcb65ce0626845af22ff92ab90d0c47666e Mon Sep 17 00:00:00 2001
From: Robin Ward <robin.ward@gmail.com>
Date: Thu, 11 Dec 2014 13:59:42 -0500
Subject: [PATCH] Fix broken qunit tests in 1.9.0

---
 .../discourse/helpers/bound-i18n.js.es6       |  4 ++
 .../discourse/helpers/count-i18n.js.es6       | 17 ++++++
 .../javascripts/discourse/helpers/i18n.js.es6 |  5 ++
 .../discourse/helpers/i18n_helpers.js         | 56 -------------------
 .../initializers/default-i18n.js.es6          | 27 +++++++++
 app/assets/javascripts/main_include.js        |  1 -
 test/javascripts/test_helper.js               |  1 -
 7 files changed, 53 insertions(+), 58 deletions(-)
 create mode 100644 app/assets/javascripts/discourse/helpers/bound-i18n.js.es6
 create mode 100644 app/assets/javascripts/discourse/helpers/count-i18n.js.es6
 create mode 100644 app/assets/javascripts/discourse/helpers/i18n.js.es6
 delete mode 100644 app/assets/javascripts/discourse/helpers/i18n_helpers.js
 create mode 100644 app/assets/javascripts/discourse/initializers/default-i18n.js.es6

diff --git a/app/assets/javascripts/discourse/helpers/bound-i18n.js.es6 b/app/assets/javascripts/discourse/helpers/bound-i18n.js.es6
new file mode 100644
index 000000000..8ce28a510
--- /dev/null
+++ b/app/assets/javascripts/discourse/helpers/bound-i18n.js.es6
@@ -0,0 +1,4 @@
+Ember.Handlebars.registerBoundHelper("boundI18n", function(property, options) {
+  return new Handlebars.SafeString(I18n.t(property, options.hash));
+});
+
diff --git a/app/assets/javascripts/discourse/helpers/count-i18n.js.es6 b/app/assets/javascripts/discourse/helpers/count-i18n.js.es6
new file mode 100644
index 000000000..85fb9bc46
--- /dev/null
+++ b/app/assets/javascripts/discourse/helpers/count-i18n.js.es6
@@ -0,0 +1,17 @@
+/**
+  Set up an i18n binding that will update as a count changes, complete with pluralization.
+
+  @method countI18n
+  @for Handlebars
+**/
+Ember.Handlebars.registerHelper('countI18n', function(key, options) {
+  var view = Discourse.View.extend(Discourse.StringBuffer, {
+    tagName: 'span',
+    rerenderTriggers: ['count', 'suffix'],
+
+    renderString: function(buffer) {
+      buffer.push(I18n.t(key + (this.get('suffix') || ''), { count: this.get('count') }));
+    }
+  });
+  return Ember.Handlebars.helpers.view.call(this, view, options);
+});
diff --git a/app/assets/javascripts/discourse/helpers/i18n.js.es6 b/app/assets/javascripts/discourse/helpers/i18n.js.es6
new file mode 100644
index 000000000..b19eae3b5
--- /dev/null
+++ b/app/assets/javascripts/discourse/helpers/i18n.js.es6
@@ -0,0 +1,5 @@
+import registerUnbound from 'discourse/helpers/register-unbound';
+
+registerUnbound('i18n', function(key, params) {
+  return I18n.t(key, params);
+});
diff --git a/app/assets/javascripts/discourse/helpers/i18n_helpers.js b/app/assets/javascripts/discourse/helpers/i18n_helpers.js
deleted file mode 100644
index 99ea0a3aa..000000000
--- a/app/assets/javascripts/discourse/helpers/i18n_helpers.js
+++ /dev/null
@@ -1,56 +0,0 @@
-// TODO: Remove me when ES6ified
-var registerUnbound = require('discourse/helpers/register-unbound', null, null, true).default;
-
-/**
- We always prefix with "js." to select exactly what we want passed
- through to the front end.
-**/
-var oldI18nlookup = I18n.lookup;
-I18n.lookup = function(scope, options) {
-  return oldI18nlookup.apply(this, ["js." + scope, options]);
-};
-
-/**
- Default format for storage units
-**/
-var oldI18ntoHumanSize = I18n.toHumanSize;
-I18n.toHumanSize = function(number, options) {
-  options = options || {};
-  options.format = I18n.t("number.human.storage_units.format");
-  return oldI18ntoHumanSize.apply(this, [number, options]);
-};
-
-registerUnbound('i18n', function(key, params) {
-  return I18n.t(key, params);
-});
-
-/**
- Bound version of i18n helper.
- **/
-Ember.Handlebars.registerBoundHelper("boundI18n", function(property, options) {
-  return new Handlebars.SafeString(I18n.t(property, options.hash));
-});
-
-/**
-  Set up an i18n binding that will update as a count changes, complete with pluralization.
-
-  @method countI18n
-  @for Handlebars
-**/
-Ember.Handlebars.registerHelper('countI18n', function(key, options) {
-  var view = Discourse.View.extend(Discourse.StringBuffer, {
-    tagName: 'span',
-    rerenderTriggers: ['count', 'suffix'],
-
-    renderString: function(buffer) {
-      buffer.push(I18n.t(key + (this.get('suffix') || ''), { count: this.get('count') }));
-    }
-  });
-  return Ember.Handlebars.helpers.view.call(this, view, options);
-});
-
-if (Ember.EXTEND_PROTOTYPES) {
-  String.prototype.i18n = function(options) {
-    return I18n.t(String(this), options);
-  };
-}
diff --git a/app/assets/javascripts/discourse/initializers/default-i18n.js.es6 b/app/assets/javascripts/discourse/initializers/default-i18n.js.es6
new file mode 100644
index 000000000..e6480bdf1
--- /dev/null
+++ b/app/assets/javascripts/discourse/initializers/default-i18n.js.es6
@@ -0,0 +1,27 @@
+export default {
+  name: 'default-i18n',
+
+  initialize: function() {
+    // We always prefix with "js." to select exactly what we want passed
+    // through to the front end.
+    var oldI18nlookup = I18n.lookup;
+    I18n.lookup = function(scope, options) {
+      return oldI18nlookup.apply(this, ["js." + scope, options]);
+    };
+
+    // Default format for storage units
+    var oldI18ntoHumanSize = I18n.toHumanSize;
+    I18n.toHumanSize = function(number, options) {
+      options = options || {};
+      options.format = I18n.t("number.human.storage_units.format");
+      return oldI18ntoHumanSize.apply(this, [number, options]);
+    };
+
+    if (Ember.EXTEND_PROTOTYPES) {
+      String.prototype.i18n = function(options) {
+        return I18n.t(String(this), options);
+      };
+    }
+
+  }
+};
diff --git a/app/assets/javascripts/main_include.js b/app/assets/javascripts/main_include.js
index 8e1d9d8c3..3ab744c1b 100644
--- a/app/assets/javascripts/main_include.js
+++ b/app/assets/javascripts/main_include.js
@@ -12,7 +12,6 @@
 // Stuff we need to load first
 //= require ./discourse/lib/ember_compat_handlebars
 //= require ./discourse/helpers/register-unbound
-//= require ./discourse/helpers/i18n_helpers
 //= require ./discourse/lib/computed
 //= require ./discourse/mixins/scrolling
 //= require_tree ./discourse/mixins
diff --git a/test/javascripts/test_helper.js b/test/javascripts/test_helper.js
index 863d76e45..a9bd9b664 100644
--- a/test/javascripts/test_helper.js
+++ b/test/javascripts/test_helper.js
@@ -20,7 +20,6 @@
 //= require pretender
 
 //= require ../../app/assets/javascripts/locales/i18n
-//= require ../../app/assets/javascripts/discourse/helpers/i18n_helpers
 //= require ../../app/assets/javascripts/locales/en
 
 // Pagedown customizations