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
Ember 1.13 and 2.0 support #227
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,33 +1,23 @@ | ||
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() { | ||
const value = i18nKey.isStream ? i18nKey.value() : i18nKey; | ||
return value === undefined ? '' : i18n.t(value, 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); | ||
} | ||
}); | ||
if (Ember.Helper) { | ||
Helper = Ember.Helper.extend({ | ||
i18n: Ember.inject.service(), | ||
|
||
// observe the locale: | ||
i18n.localeStream.subscribe(out.notify, out); | ||
_locale: Ember.computed.readOnly('i18n.locale'), | ||
|
||
// if the i18n key itself is dynamic, observe it: | ||
if (i18nKey.isStream) { | ||
i18nKey.subscribe(out.notify, out); | ||
} | ||
compute: function(params, interpolations) { | ||
const key = params[0]; | ||
const i18n = this.get('i18n'); | ||
return i18n.t(key, interpolations); | ||
}, | ||
|
||
return out; | ||
_recomputeOnLocaleChange: Ember.observer('_locale', function() { | ||
this.recompute(); | ||
}) | ||
}); | ||
} | ||
|
||
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,39 @@ | ||
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() { | ||
const value = i18nKey.isStream ? i18nKey.value() : i18nKey; | ||
return value === undefined ? '' : i18n.t(value, 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
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
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
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 was deleted.
Oops, something went wrong.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despite this, I get a "helper t not found" error message whenever I try to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. Robert is going to land emberjs/rfcs#58 into 1.13 which will give you
{{t
without any explicit registration step.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. I was basing this off of https://github.com/emberjs/ember.js/pull/11278/files#diff-5d4704d516d9bedb9605e499dc0a88d8R122
I guess once dashless-autolookup lands I'll want a single
app/helpers/t.js
that exports eitherlegacyHelper
orHelper
, depending on the presence ofEmber.Helper
. That'll be easy :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirm.