diff --git a/VERSION b/VERSION index f0bb29e7..3a3cd8cc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.3.0 +1.3.1 diff --git a/component.json b/component.json index 72ae9a35..6e58e37e 100644 --- a/component.json +++ b/component.json @@ -1,6 +1,6 @@ { "name": "ember-i18n", - "version": "1.3.0", + "version": "1.3.1", "description": "I18n support for Ember.js", "main": [ "dist/ember-i18n-latest.js" ], "dependencies": { diff --git a/dist/ember-i18n-1.3.0.js b/dist/ember-i18n-1.3.1.js similarity index 69% rename from dist/ember-i18n-1.3.0.js rename to dist/ember-i18n-1.3.1.js index 49141053..2f8b7e9f 100644 --- a/dist/ember-i18n-1.3.0.js +++ b/dist/ember-i18n-1.3.1.js @@ -1,9 +1,9 @@ (function() { - var I18n, findTemplate, getPath, isBinding, isTranslatedAttribute, pluralForm; + var I18n, assert, findTemplate, get, isBinding, isTranslatedAttribute, lookupKey, pluralForm; isTranslatedAttribute = /(.+)Translation$/; - getPath = Ember.Handlebars.getPath || Ember.getPath; + get = Ember.Handlebars.get || Ember.Handlebars.getPath || Ember.getPath; if (typeof CLDR !== "undefined" && CLDR !== null) pluralForm = CLDR.pluralForm; @@ -11,10 +11,25 @@ Ember.Logger.warn("CLDR.pluralForm not found. Em.I18n will not support count-based inflection."); } + lookupKey = function(key, hash) { + var firstKey, idx, remainingKeys, result; + result = hash[key]; + idx = key.indexOf('.'); + if (!result && idx !== -1) { + firstKey = key.substr(0, idx); + remainingKeys = key.substr(idx + 1); + hash = hash[firstKey]; + if (hash) result = lookupKey(remainingKeys, hash); + } + return result; + }; + + assert = Ember.assert != null ? Ember.assert : ember_assert; + findTemplate = function(key, setOnMissing) { var result; - ember_assert("You must provide a translation key string, not %@".fmt(key), typeof key === 'string'); - result = I18n.translations[key]; + assert("You must provide a translation key string, not %@".fmt(key), typeof key === 'string'); + result = lookupKey(key, I18n.translations); if (setOnMissing) { if (result == null) { result = I18n.translations[key] = I18n.compile("Missing translation: " + key); @@ -69,37 +84,40 @@ isBinding = /(.+)Binding$/; Handlebars.registerHelper('t', function(key, options) { - var attrs, context, elementID, result, tagName, view; + var attrs, context, data, elementID, result, tagName, view; context = this; attrs = options.hash; - view = options.data.view; + data = options.data; + view = data.view; tagName = attrs.tagName || 'span'; delete attrs.tagName; elementID = "i18n-" + (jQuery.uuid++); Em.keys(attrs).forEach(function(property) { - var bindPath, currentValue, invoker, isBindingMatch, observer, propertyName; + var bindPath, currentValue, invoker, isBindingMatch, normalized, normalizedPath, observer, propertyName, root, _ref; isBindingMatch = property.match(isBinding); if (isBindingMatch) { propertyName = isBindingMatch[1]; bindPath = attrs[property]; - currentValue = getPath(context, bindPath); + currentValue = get(context, bindPath, options); attrs[propertyName] = currentValue; invoker = null; + normalized = Ember.Handlebars.normalizePath(context, bindPath, data); + _ref = [normalized.root, normalized.path], root = _ref[0], normalizedPath = _ref[1]; observer = function() { var elem, newValue; - newValue = getPath(context, bindPath); - elem = view.$("#" + elementID); - if (elem.length === 0) { - Em.removeObserver(context, bindPath, invoker); + if (view.get('state') !== 'inDOM') { + Em.removeObserver(root, normalizedPath, invoker); return; } + newValue = get(context, bindPath, options); + elem = view.$("#" + elementID); attrs[propertyName] = newValue; return elem.html(I18n.t(key, attrs)); }; invoker = function() { return Em.run.once(observer); }; - return Em.addObserver(context, bindPath, invoker); + return Em.addObserver(root, normalizedPath, invoker); } }); result = '<%@ id="%@">%@'.fmt(tagName, elementID, I18n.t(key, attrs), tagName); diff --git a/dist/ember-i18n-latest.js b/dist/ember-i18n-latest.js index 49141053..2f8b7e9f 100644 --- a/dist/ember-i18n-latest.js +++ b/dist/ember-i18n-latest.js @@ -1,9 +1,9 @@ (function() { - var I18n, findTemplate, getPath, isBinding, isTranslatedAttribute, pluralForm; + var I18n, assert, findTemplate, get, isBinding, isTranslatedAttribute, lookupKey, pluralForm; isTranslatedAttribute = /(.+)Translation$/; - getPath = Ember.Handlebars.getPath || Ember.getPath; + get = Ember.Handlebars.get || Ember.Handlebars.getPath || Ember.getPath; if (typeof CLDR !== "undefined" && CLDR !== null) pluralForm = CLDR.pluralForm; @@ -11,10 +11,25 @@ Ember.Logger.warn("CLDR.pluralForm not found. Em.I18n will not support count-based inflection."); } + lookupKey = function(key, hash) { + var firstKey, idx, remainingKeys, result; + result = hash[key]; + idx = key.indexOf('.'); + if (!result && idx !== -1) { + firstKey = key.substr(0, idx); + remainingKeys = key.substr(idx + 1); + hash = hash[firstKey]; + if (hash) result = lookupKey(remainingKeys, hash); + } + return result; + }; + + assert = Ember.assert != null ? Ember.assert : ember_assert; + findTemplate = function(key, setOnMissing) { var result; - ember_assert("You must provide a translation key string, not %@".fmt(key), typeof key === 'string'); - result = I18n.translations[key]; + assert("You must provide a translation key string, not %@".fmt(key), typeof key === 'string'); + result = lookupKey(key, I18n.translations); if (setOnMissing) { if (result == null) { result = I18n.translations[key] = I18n.compile("Missing translation: " + key); @@ -69,37 +84,40 @@ isBinding = /(.+)Binding$/; Handlebars.registerHelper('t', function(key, options) { - var attrs, context, elementID, result, tagName, view; + var attrs, context, data, elementID, result, tagName, view; context = this; attrs = options.hash; - view = options.data.view; + data = options.data; + view = data.view; tagName = attrs.tagName || 'span'; delete attrs.tagName; elementID = "i18n-" + (jQuery.uuid++); Em.keys(attrs).forEach(function(property) { - var bindPath, currentValue, invoker, isBindingMatch, observer, propertyName; + var bindPath, currentValue, invoker, isBindingMatch, normalized, normalizedPath, observer, propertyName, root, _ref; isBindingMatch = property.match(isBinding); if (isBindingMatch) { propertyName = isBindingMatch[1]; bindPath = attrs[property]; - currentValue = getPath(context, bindPath); + currentValue = get(context, bindPath, options); attrs[propertyName] = currentValue; invoker = null; + normalized = Ember.Handlebars.normalizePath(context, bindPath, data); + _ref = [normalized.root, normalized.path], root = _ref[0], normalizedPath = _ref[1]; observer = function() { var elem, newValue; - newValue = getPath(context, bindPath); - elem = view.$("#" + elementID); - if (elem.length === 0) { - Em.removeObserver(context, bindPath, invoker); + if (view.get('state') !== 'inDOM') { + Em.removeObserver(root, normalizedPath, invoker); return; } + newValue = get(context, bindPath, options); + elem = view.$("#" + elementID); attrs[propertyName] = newValue; return elem.html(I18n.t(key, attrs)); }; invoker = function() { return Em.run.once(observer); }; - return Em.addObserver(context, bindPath, invoker); + return Em.addObserver(root, normalizedPath, invoker); } }); result = '<%@ id="%@">%@'.fmt(tagName, elementID, I18n.t(key, attrs), tagName);