Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
wip: ember 1.13 support
Browse files Browse the repository at this point in the history
Starting work on support for Ember 1.13. Glimmer breaks the old
helper and adds a new `Ember.Helper` with more of the power we
need.

As of this commit, the beta build is still breaking because there's
something wrong with the helper registration.
  • Loading branch information
jamesarosen committed Jun 8, 2015
1 parent feef4e4 commit f8f768f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 28 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ env:
matrix:
fast_finish: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary

before_install:
Expand Down
40 changes: 15 additions & 25 deletions addon/helper.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
import Ember from "ember";
import Stream from "./stream";
import { readHash } from "./stream";

// @public
export default function t(params, hash, options, env) {
const i18n = env.data.view.container.lookup('service:i18n');
const i18nKey = params[0];
var Helper = null;

var out = new Stream(function() {
return i18n.t(i18nKey, readHash(hash));
});
if (Ember.Helper) {
Helper = Ember.Helper.extend({
i18n: Ember.inject.service(),
_locale: Ember.computed.readOnly('i18n.locale'),

// observe any hash arguments that are streams:
Ember.keys(hash).forEach(function(key) {
const value = hash[key];
compute: function(params) {
const [ key, interpolations ] = params;
const i18n = this.get('i18n');
return i18n.t(key, interpolations);
},

if (value && value.isStream) {
value.subscribe(out.notify, out);
}
_recomputeOnLocaleChange: Ember.observer('_locale', function() {
this.recompute();
})
});

// observe the locale:
i18n.localeStream.subscribe(out.notify, out);

// if the i18n key itself is dynamic, observe it:
if (i18nKey.isStream) {
i18nKey.subscribe(out.notify, out);
}

return out;
}

export default Helper;
38 changes: 38 additions & 0 deletions addon/legacy-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Ember from "ember";
import Stream from "./stream";
import { readHash } from "./stream";

var helper = null;

if (Ember.Helper == null) {
// @public
helper = function tHelper(params, hash, options, env) {
const i18n = env.data.view.container.lookup('service:i18n');
const i18nKey = params[0];

var out = new Stream(function() {
return i18n.t(i18nKey, readHash(hash));
});

// observe any hash arguments that are streams:
Ember.keys(hash).forEach(function(key) {
const value = hash[key];

if (value && value.isStream) {
value.subscribe(out.notify, out);
}
});

// observe the locale:
i18n.localeStream.subscribe(out.notify, out);

// if the i18n key itself is dynamic, observe it:
if (i18nKey.isStream) {
i18nKey.subscribe(out.notify, out);
}

return out;
};
}

export default helper;
12 changes: 10 additions & 2 deletions app/instance-initializers/ember-i18n.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Ember from "ember";
import helper from "ember-i18n/helper";
import legacyHelper from "ember-i18n/legacy-helper";
import Helper from "ember-i18n/helper";
import ENV from '../config/environment';

export default {
Expand All @@ -13,7 +14,14 @@ export default {
}
instance.container.lookup('service:i18n').set('locale', defaultLocale);

Ember.HTMLBars._registerHelper('t', helper);
if (legacyHelper != null) {
Ember.HTMLBars._registerHelper('t', legacyHelper);
}

if (Helper != null) {
instance.registry.register('helper:t', Helper);
}

instance.registry.injection('component', 'i18n', 'service:i18n');
instance.registry.injection('controller', 'i18n', 'service:i18n');
instance.registry.injection('route', 'i18n', 'service:i18n');
Expand Down

0 comments on commit f8f768f

Please sign in to comment.