This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
feef4e4
commit f8f768f
Showing
4 changed files
with
63 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters