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

Commit

Permalink
{{t}} helper warns if key parameter is unquoted
Browse files Browse the repository at this point in the history
The helper currently treats `{{t "some.key"}}` and
`{{t some.key}}` the same -- both use the "some.key" translation.
In the future, we would like to support bound keys like
`{{t user.type}}` or even `{{t "message" "welcome" user.type}}`.

Thus, we emit a warning during a transitionary period.

References:

 * #41
 * #66
 * #113
  • Loading branch information
jamesarosen committed Aug 17, 2014
1 parent f1175cd commit 716c4d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@
var tagName = attrs.tagName;
delete attrs.tagName;

warn("Ember.I18n t helper called with unquoted key: %@. In the future, this will be treated as a bound property, not a string literal.".fmt(key), options.types[0] === 'STRING');

var translationView = TranslationView.create({
context: attrs,
translationKey: key,
Expand Down
13 changes: 13 additions & 0 deletions spec/translateHelperSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ describe('{{t}}', function() {
});
});

it('emits a warning on unquoted keys', function() {
var spy = sinon.spy(Ember.Logger, 'warn');

var view = this.renderTemplate('{{t foo.bar}}');

Ember.run(function() {
expect(spy.callCount).to.equal(1);
expect(spy.lastCall.args[0]).to.match(/unquoted/);
expect(spy.lastCall.args[0]).to.match(/foo\.bar/);
expect(view.$().text()).to.equal('A Foobar');
});
});

it('interpolates values', function() {
var view = this.renderTemplate('{{t "bars.all" count="597"}}');

Expand Down

0 comments on commit 716c4d9

Please sign in to comment.