ember-i18n
Advanced tools
Comparing version 4.4.0 to 4.5.0
import Ember from "ember"; | ||
export default Ember.Helper.extend({ | ||
i18n: Ember.inject.service(), | ||
const { get, inject, Helper, Object: EmberObject, observer } = Ember; | ||
compute: function(params, interpolations) { | ||
const key = params[0]; | ||
const i18n = this.get('i18n'); | ||
return i18n.t(key, interpolations); | ||
function mergedContext(objectContext, hashContext) { | ||
return EmberObject.extend({ | ||
unknownProperty(key) { | ||
const fromHash = get(hashContext, key); | ||
return fromHash === undefined ? get(objectContext, key) : fromHash; | ||
} | ||
}).create(); | ||
} | ||
export default Helper.extend({ | ||
i18n: inject.service(), | ||
compute([key, contextObject = {}, ...rest], interpolations) { | ||
const mergedInterpolations = mergedContext(contextObject, interpolations); | ||
const i18n = get(this, 'i18n'); | ||
return i18n.t(key, mergedInterpolations); | ||
}, | ||
_recomputeOnLocaleChange: Ember.observer('i18n.locale', function() { | ||
_recomputeOnLocaleChange: observer('i18n.locale', function() { | ||
this.recompute(); | ||
}) | ||
}); |
import Stream from "./stream"; | ||
import { readHash } from "./stream"; | ||
import Ember from 'ember'; | ||
export default function tHelper(params, hash, options, env) { | ||
const assign = Ember.assign || Ember.merge; | ||
export default function tHelper([i18nKey, contextObject = { value: () => {} }], 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)); | ||
const contextObjectValue = contextObject.value(); | ||
const mergedHash = {}; | ||
assign(mergedHash, contextObjectValue); | ||
assign(mergedHash, hash); | ||
return value === undefined ? '' : i18n.t(value, readHash(mergedHash)); | ||
}); | ||
@@ -18,2 +28,6 @@ | ||
if (contextObject && contextObject.isStream) { | ||
contextObject.subscribe(out.notify, out); | ||
} | ||
// observe any hash arguments that are streams: | ||
@@ -20,0 +34,0 @@ Object.keys(hash).forEach(function(key) { |
@@ -0,1 +1,6 @@ | ||
## 4.5.0 | ||
* `{{t}}` helper supports a context object as a second ordered argument; | ||
named (hash) arguments override context object ones when interpolating | ||
## 4.4.0 | ||
@@ -2,0 +7,0 @@ |
{ | ||
"name": "ember-i18n", | ||
"version": "4.4.0", | ||
"version": "4.5.0", | ||
"description": "Internationalization for Ember", | ||
@@ -5,0 +5,0 @@ "directories": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37007
693