diff --git a/addon/utils/t.js b/addon/utils/t.js
index ac2904f..6c4d201 100644
--- a/addon/utils/t.js
+++ b/addon/utils/t.js
@@ -13,6 +13,8 @@ function T(attributes) {
var service = this.container.lookupFactory('service:i18n');
var result;
var locale;
+ var application = this.container.lookup('application:main');
+ var htmlLocales = application.htmlLocales ? true : false;
if (!Ember.isArray(values)) {
values = Array.prototype.slice.call(arguments, 1);
@@ -31,7 +33,21 @@ function T(attributes) {
Ember.assert('Missing translation for key "' + path + '".', result);
Ember.assert('Translation for key "' + path + '" is not a string.', Ember.typeOf(result) === 'string');
- return service.fmt(result, readArray(values));
+ var t = readArray(values);
+ if( htmlLocales === true ) {
+ t = t.map(function(value) {
+ return Ember.Handlebars.Utils.escapeExpression(value);
+ });
+ }
+
+ result = service.fmt(result, readArray(t));
+
+ if( htmlLocales !== true ) {
+ return result;
+ }
+ else {
+ return Ember.String.htmlSafe( result );
+ }
};
}
diff --git a/tests/unit/utils/t-test.js b/tests/unit/utils/t-test.js
index 4040d30..63bbacc 100644
--- a/tests/unit/utils/t-test.js
+++ b/tests/unit/utils/t-test.js
@@ -235,3 +235,27 @@ test('can override the format handler', function(assert) {
assert.equal(t('foo'), 'barbiz');
});
+
+test('escapes html as default', function(assert) {
+ application.defaultLocale = 'en';
+
+ assert.equal(typeof t('foo'), 'string');
+
+ application.htmlLocales = false;
+
+ assert.equal(typeof t('foo'), 'string');
+});
+
+test('allow html in locales', function(assert) {
+ application.defaultLocale = 'en';
+ application.htmlLocales = true;
+
+ assert.equal(typeof t('foo'), 'object');
+});
+
+test('escape interpolation values if htmlLocales are enabled', function(assert) {
+ application.defaultLocale = 'en';
+ application.htmlLocales = true;
+
+ assert.equal(t('name', 'foo', 'bar').toString(), '<s>foo</s> <u>bar</u>');
+});