From 336b8c37803b017c7e5b926e38e659323158753f Mon Sep 17 00:00:00 2001 From: EisenbergEffect Date: Wed, 20 Jun 2018 21:36:31 -0700 Subject: [PATCH] chore(all): prepare release 2.3.0 --- bower.json | 2 +- dist/amd/i18n.js | 141 +++++++++++++++++--------------- dist/aurelia-i18n.js | 159 +++++++++++++++++++----------------- dist/commonjs/i18n.js | 141 +++++++++++++++++--------------- dist/es2015/i18n.js | 149 +++++++++++++++++---------------- dist/native-modules/i18n.js | 141 +++++++++++++++++--------------- dist/system/i18n.js | 141 +++++++++++++++++--------------- dist/temp/aurelia-i18n.js | 135 +++++++++++++++--------------- doc/CHANGELOG.md | 10 +++ package.json | 2 +- 10 files changed, 540 insertions(+), 481 deletions(-) diff --git a/bower.json b/bower.json index c4331670..a1828eca 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-i18n", - "version": "2.2.0", + "version": "2.3.0", "description": "A plugin that provides i18n support.", "keywords": [ "aurelia", diff --git a/dist/amd/i18n.js b/dist/amd/i18n.js index 16d20778..442b9667 100644 --- a/dist/amd/i18n.js +++ b/dist/amd/i18n.js @@ -186,7 +186,7 @@ define(['exports', 'aurelia-logging', 'i18next', 'aurelia-pal', 'aurelia-event-a while (i--) { var key = keys[i]; - var re = /\[([a-z\-]*)\]/ig; + var re = /\[([a-z\-, ]*)\]/ig; var m = void 0; var attr = 'text'; @@ -203,80 +203,87 @@ define(['exports', 'aurelia-logging', 'i18next', 'aurelia-pal', 'aurelia-event-a } } - if (!node._textContent) node._textContent = node.textContent; - if (!node._innerHTML) node._innerHTML = node.innerHTML; + var attrs = attr.split(','); + var j = attrs.length; - var attrCC = attr.replace(/-([a-z])/g, function (g) { - return g[1].toUpperCase(); - }); - var reservedNames = ['prepend', 'append', 'text', 'html']; - var i18nLogger = LogManager.getLogger('i18n'); + while (j--) { + attr = attrs[j].trim(); - if (reservedNames.indexOf(attr) > -1 && node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { - i18nLogger.warn('Aurelia I18N reserved attribute name\n\n[' + reservedNames.join(', ') + ']\n\nYour custom element has a bindable named ' + attr + ' which is a reserved word.\n\nIf you\'d like Aurelia I18N to translate your bindable instead, please consider giving it another name.'); - } + if (!node._textContent) node._textContent = node.textContent; + if (!node._innerHTML) node._innerHTML = node.innerHTML; - if (this.i18next.options.skipTranslationOnMissingKey && this.tr(key, params) === key) { - i18nLogger.warn('Couldn\'t find translation for key: ' + key); - return; - } + var attrCC = attr.replace(/-([a-z])/g, function (g) { + return g[1].toUpperCase(); + }); + var reservedNames = ['prepend', 'append', 'text', 'html']; + var i18nLogger = LogManager.getLogger('i18n'); + + if (reservedNames.indexOf(attr) > -1 && node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { + i18nLogger.warn('Aurelia I18N reserved attribute name\n\n [' + reservedNames.join(', ') + ']\n\n Your custom element has a bindable named ' + attr + ' which is a reserved word.\n\n If you\'d like Aurelia I18N to translate your bindable instead, please consider giving it another name.'); + } - switch (attr) { - case 'text': - var newChild = _aureliaPal.DOM.createTextNode(this.tr(key, params)); - if (node._newChild && node._newChild.parentNode === node) { - node.removeChild(node._newChild); - } - - node._newChild = newChild; - while (node.firstChild) { - node.removeChild(node.firstChild); - } - node.appendChild(node._newChild); - break; - case 'prepend': - var prependParser = _aureliaPal.DOM.createElement('div'); - prependParser.innerHTML = this.tr(key, params); - for (var ni = node.childNodes.length - 1; ni >= 0; ni--) { - if (node.childNodes[ni]._prepended) { - node.removeChild(node.childNodes[ni]); + if (this.i18next.options.skipTranslationOnMissingKey && this.tr(key, params) === key) { + i18nLogger.warn('Couldn\'t find translation for key: ' + key); + return; + } + + switch (attr) { + case 'text': + var newChild = _aureliaPal.DOM.createTextNode(this.tr(key, params)); + if (node._newChild && node._newChild.parentNode === node) { + node.removeChild(node._newChild); } - } - for (var pi = prependParser.childNodes.length - 1; pi >= 0; pi--) { - prependParser.childNodes[pi]._prepended = true; - if (node.firstChild) { - node.insertBefore(prependParser.childNodes[pi], node.firstChild); - } else { - node.appendChild(prependParser.childNodes[pi]); + node._newChild = newChild; + while (node.firstChild) { + node.removeChild(node.firstChild); } - } - break; - case 'append': - var appendParser = _aureliaPal.DOM.createElement('div'); - appendParser.innerHTML = this.tr(key, params); - for (var _ni = node.childNodes.length - 1; _ni >= 0; _ni--) { - if (node.childNodes[_ni]._appended) { - node.removeChild(node.childNodes[_ni]); + node.appendChild(node._newChild); + break; + case 'prepend': + var prependParser = _aureliaPal.DOM.createElement('div'); + prependParser.innerHTML = this.tr(key, params); + for (var ni = node.childNodes.length - 1; ni >= 0; ni--) { + if (node.childNodes[ni]._prepended) { + node.removeChild(node.childNodes[ni]); + } } - } - - while (appendParser.firstChild) { - appendParser.firstChild._appended = true; - node.appendChild(appendParser.firstChild); - } - break; - case 'html': - node.innerHTML = this.tr(key, params); - break; - default: - if (node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { - node.au.controller.viewModel[attrCC] = this.tr(key, params); - } else { - node.setAttribute(attr, this.tr(key, params)); - } - - break; + + for (var pi = prependParser.childNodes.length - 1; pi >= 0; pi--) { + prependParser.childNodes[pi]._prepended = true; + if (node.firstChild) { + node.insertBefore(prependParser.childNodes[pi], node.firstChild); + } else { + node.appendChild(prependParser.childNodes[pi]); + } + } + break; + case 'append': + var appendParser = _aureliaPal.DOM.createElement('div'); + appendParser.innerHTML = this.tr(key, params); + for (var _ni = node.childNodes.length - 1; _ni >= 0; _ni--) { + if (node.childNodes[_ni]._appended) { + node.removeChild(node.childNodes[_ni]); + } + } + + while (appendParser.firstChild) { + appendParser.firstChild._appended = true; + node.appendChild(appendParser.firstChild); + } + break; + case 'html': + node.innerHTML = this.tr(key, params); + break; + default: + if (node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { + node.au.controller.viewModel[attrCC] = this.tr(key, params); + } else { + node.setAttribute(attr, this.tr(key, params)); + } + + break; + } } } }; diff --git a/dist/aurelia-i18n.js b/dist/aurelia-i18n.js index 8f10218e..fd71e820 100644 --- a/dist/aurelia-i18n.js +++ b/dist/aurelia-i18n.js @@ -717,7 +717,7 @@ export class I18N { while (i--) { let key = keys[i]; // remove the optional attribute - let re = /\[([a-z\-]*)\]/ig; + let re = /\[([a-z\-, ]*)\]/ig; let m; let attr = 'text'; @@ -735,92 +735,99 @@ export class I18N { } } - if (!node._textContent) node._textContent = node.textContent; - if (!node._innerHTML) node._innerHTML = node.innerHTML; - - // convert to camelCase - const attrCC = attr.replace(/-([a-z])/g, function(g) { return g[1].toUpperCase(); }); - const reservedNames = ['prepend', 'append', 'text', 'html']; - const i18nLogger = LogManager.getLogger('i18n'); - - if (reservedNames.indexOf(attr) > -1 && - node.au && - node.au.controller && - node.au.controller.viewModel && - attrCC in node.au.controller.viewModel) { - i18nLogger.warn(`Aurelia I18N reserved attribute name\n -[${reservedNames.join(', ')}]\n -Your custom element has a bindable named ${attr} which is a reserved word.\n -If you'd like Aurelia I18N to translate your bindable instead, please consider giving it another name.`); - } + let attrs = attr.split(','); + let j = attrs.length; - if (this.i18next.options.skipTranslationOnMissingKey && - this.tr(key, params) === key) { - i18nLogger.warn(`Couldn't find translation for key: ${key}`); - return; - } + while (j--) { + attr = attrs[j].trim(); + + if (!node._textContent) node._textContent = node.textContent; + if (!node._innerHTML) node._innerHTML = node.innerHTML; + + // convert to camelCase + const attrCC = attr.replace(/-([a-z])/g, function(g) { return g[1].toUpperCase(); }); + const reservedNames = ['prepend', 'append', 'text', 'html']; + const i18nLogger = LogManager.getLogger('i18n'); - //handle various attributes - //anything other than text,prepend,append or html will be added as an attribute on the element. - switch (attr) { - case 'text': - let newChild = DOM.createTextNode(this.tr(key, params)); - if (node._newChild && node._newChild.parentNode === node) { - node.removeChild(node._newChild); + if (reservedNames.indexOf(attr) > -1 && + node.au && + node.au.controller && + node.au.controller.viewModel && + attrCC in node.au.controller.viewModel) { + i18nLogger.warn(`Aurelia I18N reserved attribute name\n + [${reservedNames.join(', ')}]\n + Your custom element has a bindable named ${attr} which is a reserved word.\n + If you'd like Aurelia I18N to translate your bindable instead, please consider giving it another name.`); } - node._newChild = newChild; - while (node.firstChild) { - node.removeChild(node.firstChild); + if (this.i18next.options.skipTranslationOnMissingKey && + this.tr(key, params) === key) { + i18nLogger.warn(`Couldn't find translation for key: ${key}`); + return; } - node.appendChild(node._newChild); - break; - case 'prepend': - let prependParser = DOM.createElement('div'); - prependParser.innerHTML = this.tr(key, params); - for (let ni = node.childNodes.length - 1; ni >= 0; ni--) { - if (node.childNodes[ni]._prepended) { - node.removeChild(node.childNodes[ni]); + + //handle various attributes + //anything other than text,prepend,append or html will be added as an attribute on the element. + switch (attr) { + case 'text': + let newChild = DOM.createTextNode(this.tr(key, params)); + if (node._newChild && node._newChild.parentNode === node) { + node.removeChild(node._newChild); } - } - for (let pi = prependParser.childNodes.length - 1; pi >= 0; pi--) { - prependParser.childNodes[pi]._prepended = true; - if (node.firstChild) { - node.insertBefore(prependParser.childNodes[pi], node.firstChild); - } else { - node.appendChild(prependParser.childNodes[pi]); + node._newChild = newChild; + while (node.firstChild) { + node.removeChild(node.firstChild); } - } - break; - case 'append': - let appendParser = DOM.createElement('div'); - appendParser.innerHTML = this.tr(key, params); - for (let ni = node.childNodes.length - 1; ni >= 0; ni--) { - if (node.childNodes[ni]._appended) { - node.removeChild(node.childNodes[ni]); + node.appendChild(node._newChild); + break; + case 'prepend': + let prependParser = DOM.createElement('div'); + prependParser.innerHTML = this.tr(key, params); + for (let ni = node.childNodes.length - 1; ni >= 0; ni--) { + if (node.childNodes[ni]._prepended) { + node.removeChild(node.childNodes[ni]); + } } - } - while (appendParser.firstChild) { - appendParser.firstChild._appended = true; - node.appendChild(appendParser.firstChild); - } - break; - case 'html': - node.innerHTML = this.tr(key, params); - break; - default: //normal html attribute - if (node.au && - node.au.controller && - node.au.controller.viewModel && - attrCC in node.au.controller.viewModel) { - node.au.controller.viewModel[attrCC] = this.tr(key, params); - } else { - node.setAttribute(attr, this.tr(key, params)); - } + for (let pi = prependParser.childNodes.length - 1; pi >= 0; pi--) { + prependParser.childNodes[pi]._prepended = true; + if (node.firstChild) { + node.insertBefore(prependParser.childNodes[pi], node.firstChild); + } else { + node.appendChild(prependParser.childNodes[pi]); + } + } + break; + case 'append': + let appendParser = DOM.createElement('div'); + appendParser.innerHTML = this.tr(key, params); + for (let ni = node.childNodes.length - 1; ni >= 0; ni--) { + if (node.childNodes[ni]._appended) { + node.removeChild(node.childNodes[ni]); + } + } + + while (appendParser.firstChild) { + appendParser.firstChild._appended = true; + node.appendChild(appendParser.firstChild); + } + break; + case 'html': + node.innerHTML = this.tr(key, params); + break; + default: //normal html attribute + if (node.au && + node.au.controller && + node.au.controller.viewModel && + attrCC in node.au.controller.viewModel) { + node.au.controller.viewModel[attrCC] = this.tr(key, params); + } else { + node.setAttribute(attr, this.tr(key, params)); + } - break; + break; + } } } } diff --git a/dist/commonjs/i18n.js b/dist/commonjs/i18n.js index f8c8d9f6..d9961657 100644 --- a/dist/commonjs/i18n.js +++ b/dist/commonjs/i18n.js @@ -176,7 +176,7 @@ var I18N = exports.I18N = (_temp = _class = function () { while (i--) { var key = keys[i]; - var re = /\[([a-z\-]*)\]/ig; + var re = /\[([a-z\-, ]*)\]/ig; var m = void 0; var attr = 'text'; @@ -193,80 +193,87 @@ var I18N = exports.I18N = (_temp = _class = function () { } } - if (!node._textContent) node._textContent = node.textContent; - if (!node._innerHTML) node._innerHTML = node.innerHTML; + var attrs = attr.split(','); + var j = attrs.length; - var attrCC = attr.replace(/-([a-z])/g, function (g) { - return g[1].toUpperCase(); - }); - var reservedNames = ['prepend', 'append', 'text', 'html']; - var i18nLogger = LogManager.getLogger('i18n'); + while (j--) { + attr = attrs[j].trim(); - if (reservedNames.indexOf(attr) > -1 && node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { - i18nLogger.warn('Aurelia I18N reserved attribute name\n\n[' + reservedNames.join(', ') + ']\n\nYour custom element has a bindable named ' + attr + ' which is a reserved word.\n\nIf you\'d like Aurelia I18N to translate your bindable instead, please consider giving it another name.'); - } + if (!node._textContent) node._textContent = node.textContent; + if (!node._innerHTML) node._innerHTML = node.innerHTML; - if (this.i18next.options.skipTranslationOnMissingKey && this.tr(key, params) === key) { - i18nLogger.warn('Couldn\'t find translation for key: ' + key); - return; - } + var attrCC = attr.replace(/-([a-z])/g, function (g) { + return g[1].toUpperCase(); + }); + var reservedNames = ['prepend', 'append', 'text', 'html']; + var i18nLogger = LogManager.getLogger('i18n'); + + if (reservedNames.indexOf(attr) > -1 && node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { + i18nLogger.warn('Aurelia I18N reserved attribute name\n\n [' + reservedNames.join(', ') + ']\n\n Your custom element has a bindable named ' + attr + ' which is a reserved word.\n\n If you\'d like Aurelia I18N to translate your bindable instead, please consider giving it another name.'); + } - switch (attr) { - case 'text': - var newChild = _aureliaPal.DOM.createTextNode(this.tr(key, params)); - if (node._newChild && node._newChild.parentNode === node) { - node.removeChild(node._newChild); - } - - node._newChild = newChild; - while (node.firstChild) { - node.removeChild(node.firstChild); - } - node.appendChild(node._newChild); - break; - case 'prepend': - var prependParser = _aureliaPal.DOM.createElement('div'); - prependParser.innerHTML = this.tr(key, params); - for (var ni = node.childNodes.length - 1; ni >= 0; ni--) { - if (node.childNodes[ni]._prepended) { - node.removeChild(node.childNodes[ni]); + if (this.i18next.options.skipTranslationOnMissingKey && this.tr(key, params) === key) { + i18nLogger.warn('Couldn\'t find translation for key: ' + key); + return; + } + + switch (attr) { + case 'text': + var newChild = _aureliaPal.DOM.createTextNode(this.tr(key, params)); + if (node._newChild && node._newChild.parentNode === node) { + node.removeChild(node._newChild); } - } - for (var pi = prependParser.childNodes.length - 1; pi >= 0; pi--) { - prependParser.childNodes[pi]._prepended = true; - if (node.firstChild) { - node.insertBefore(prependParser.childNodes[pi], node.firstChild); - } else { - node.appendChild(prependParser.childNodes[pi]); + node._newChild = newChild; + while (node.firstChild) { + node.removeChild(node.firstChild); } - } - break; - case 'append': - var appendParser = _aureliaPal.DOM.createElement('div'); - appendParser.innerHTML = this.tr(key, params); - for (var _ni = node.childNodes.length - 1; _ni >= 0; _ni--) { - if (node.childNodes[_ni]._appended) { - node.removeChild(node.childNodes[_ni]); + node.appendChild(node._newChild); + break; + case 'prepend': + var prependParser = _aureliaPal.DOM.createElement('div'); + prependParser.innerHTML = this.tr(key, params); + for (var ni = node.childNodes.length - 1; ni >= 0; ni--) { + if (node.childNodes[ni]._prepended) { + node.removeChild(node.childNodes[ni]); + } } - } - - while (appendParser.firstChild) { - appendParser.firstChild._appended = true; - node.appendChild(appendParser.firstChild); - } - break; - case 'html': - node.innerHTML = this.tr(key, params); - break; - default: - if (node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { - node.au.controller.viewModel[attrCC] = this.tr(key, params); - } else { - node.setAttribute(attr, this.tr(key, params)); - } - - break; + + for (var pi = prependParser.childNodes.length - 1; pi >= 0; pi--) { + prependParser.childNodes[pi]._prepended = true; + if (node.firstChild) { + node.insertBefore(prependParser.childNodes[pi], node.firstChild); + } else { + node.appendChild(prependParser.childNodes[pi]); + } + } + break; + case 'append': + var appendParser = _aureliaPal.DOM.createElement('div'); + appendParser.innerHTML = this.tr(key, params); + for (var _ni = node.childNodes.length - 1; _ni >= 0; _ni--) { + if (node.childNodes[_ni]._appended) { + node.removeChild(node.childNodes[_ni]); + } + } + + while (appendParser.firstChild) { + appendParser.firstChild._appended = true; + node.appendChild(appendParser.firstChild); + } + break; + case 'html': + node.innerHTML = this.tr(key, params); + break; + default: + if (node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { + node.au.controller.viewModel[attrCC] = this.tr(key, params); + } else { + node.setAttribute(attr, this.tr(key, params)); + } + + break; + } } } }; diff --git a/dist/es2015/i18n.js b/dist/es2015/i18n.js index 7172291a..70c9b7dd 100644 --- a/dist/es2015/i18n.js +++ b/dist/es2015/i18n.js @@ -145,7 +145,7 @@ export let I18N = (_temp = _class = class I18N { while (i--) { let key = keys[i]; - let re = /\[([a-z\-]*)\]/ig; + let re = /\[([a-z\-, ]*)\]/ig; let m; let attr = 'text'; @@ -162,83 +162,90 @@ export let I18N = (_temp = _class = class I18N { } } - if (!node._textContent) node._textContent = node.textContent; - if (!node._innerHTML) node._innerHTML = node.innerHTML; + let attrs = attr.split(','); + let j = attrs.length; - const attrCC = attr.replace(/-([a-z])/g, function (g) { - return g[1].toUpperCase(); - }); - const reservedNames = ['prepend', 'append', 'text', 'html']; - const i18nLogger = LogManager.getLogger('i18n'); - - if (reservedNames.indexOf(attr) > -1 && node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { - i18nLogger.warn(`Aurelia I18N reserved attribute name\n -[${reservedNames.join(', ')}]\n -Your custom element has a bindable named ${attr} which is a reserved word.\n -If you'd like Aurelia I18N to translate your bindable instead, please consider giving it another name.`); - } + while (j--) { + attr = attrs[j].trim(); - if (this.i18next.options.skipTranslationOnMissingKey && this.tr(key, params) === key) { - i18nLogger.warn(`Couldn't find translation for key: ${key}`); - return; - } + if (!node._textContent) node._textContent = node.textContent; + if (!node._innerHTML) node._innerHTML = node.innerHTML; - switch (attr) { - case 'text': - let newChild = DOM.createTextNode(this.tr(key, params)); - if (node._newChild && node._newChild.parentNode === node) { - node.removeChild(node._newChild); - } - - node._newChild = newChild; - while (node.firstChild) { - node.removeChild(node.firstChild); - } - node.appendChild(node._newChild); - break; - case 'prepend': - let prependParser = DOM.createElement('div'); - prependParser.innerHTML = this.tr(key, params); - for (let ni = node.childNodes.length - 1; ni >= 0; ni--) { - if (node.childNodes[ni]._prepended) { - node.removeChild(node.childNodes[ni]); + const attrCC = attr.replace(/-([a-z])/g, function (g) { + return g[1].toUpperCase(); + }); + const reservedNames = ['prepend', 'append', 'text', 'html']; + const i18nLogger = LogManager.getLogger('i18n'); + + if (reservedNames.indexOf(attr) > -1 && node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { + i18nLogger.warn(`Aurelia I18N reserved attribute name\n + [${reservedNames.join(', ')}]\n + Your custom element has a bindable named ${attr} which is a reserved word.\n + If you'd like Aurelia I18N to translate your bindable instead, please consider giving it another name.`); + } + + if (this.i18next.options.skipTranslationOnMissingKey && this.tr(key, params) === key) { + i18nLogger.warn(`Couldn't find translation for key: ${key}`); + return; + } + + switch (attr) { + case 'text': + let newChild = DOM.createTextNode(this.tr(key, params)); + if (node._newChild && node._newChild.parentNode === node) { + node.removeChild(node._newChild); } - } - for (let pi = prependParser.childNodes.length - 1; pi >= 0; pi--) { - prependParser.childNodes[pi]._prepended = true; - if (node.firstChild) { - node.insertBefore(prependParser.childNodes[pi], node.firstChild); - } else { - node.appendChild(prependParser.childNodes[pi]); + node._newChild = newChild; + while (node.firstChild) { + node.removeChild(node.firstChild); } - } - break; - case 'append': - let appendParser = DOM.createElement('div'); - appendParser.innerHTML = this.tr(key, params); - for (let ni = node.childNodes.length - 1; ni >= 0; ni--) { - if (node.childNodes[ni]._appended) { - node.removeChild(node.childNodes[ni]); + node.appendChild(node._newChild); + break; + case 'prepend': + let prependParser = DOM.createElement('div'); + prependParser.innerHTML = this.tr(key, params); + for (let ni = node.childNodes.length - 1; ni >= 0; ni--) { + if (node.childNodes[ni]._prepended) { + node.removeChild(node.childNodes[ni]); + } } - } - - while (appendParser.firstChild) { - appendParser.firstChild._appended = true; - node.appendChild(appendParser.firstChild); - } - break; - case 'html': - node.innerHTML = this.tr(key, params); - break; - default: - if (node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { - node.au.controller.viewModel[attrCC] = this.tr(key, params); - } else { - node.setAttribute(attr, this.tr(key, params)); - } - - break; + + for (let pi = prependParser.childNodes.length - 1; pi >= 0; pi--) { + prependParser.childNodes[pi]._prepended = true; + if (node.firstChild) { + node.insertBefore(prependParser.childNodes[pi], node.firstChild); + } else { + node.appendChild(prependParser.childNodes[pi]); + } + } + break; + case 'append': + let appendParser = DOM.createElement('div'); + appendParser.innerHTML = this.tr(key, params); + for (let ni = node.childNodes.length - 1; ni >= 0; ni--) { + if (node.childNodes[ni]._appended) { + node.removeChild(node.childNodes[ni]); + } + } + + while (appendParser.firstChild) { + appendParser.firstChild._appended = true; + node.appendChild(appendParser.firstChild); + } + break; + case 'html': + node.innerHTML = this.tr(key, params); + break; + default: + if (node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { + node.au.controller.viewModel[attrCC] = this.tr(key, params); + } else { + node.setAttribute(attr, this.tr(key, params)); + } + + break; + } } } } diff --git a/dist/native-modules/i18n.js b/dist/native-modules/i18n.js index 0e1482d5..ea86d494 100644 --- a/dist/native-modules/i18n.js +++ b/dist/native-modules/i18n.js @@ -157,7 +157,7 @@ export var I18N = (_temp = _class = function () { while (i--) { var key = keys[i]; - var re = /\[([a-z\-]*)\]/ig; + var re = /\[([a-z\-, ]*)\]/ig; var m = void 0; var attr = 'text'; @@ -174,80 +174,87 @@ export var I18N = (_temp = _class = function () { } } - if (!node._textContent) node._textContent = node.textContent; - if (!node._innerHTML) node._innerHTML = node.innerHTML; + var attrs = attr.split(','); + var j = attrs.length; - var attrCC = attr.replace(/-([a-z])/g, function (g) { - return g[1].toUpperCase(); - }); - var reservedNames = ['prepend', 'append', 'text', 'html']; - var i18nLogger = LogManager.getLogger('i18n'); + while (j--) { + attr = attrs[j].trim(); - if (reservedNames.indexOf(attr) > -1 && node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { - i18nLogger.warn('Aurelia I18N reserved attribute name\n\n[' + reservedNames.join(', ') + ']\n\nYour custom element has a bindable named ' + attr + ' which is a reserved word.\n\nIf you\'d like Aurelia I18N to translate your bindable instead, please consider giving it another name.'); - } + if (!node._textContent) node._textContent = node.textContent; + if (!node._innerHTML) node._innerHTML = node.innerHTML; - if (this.i18next.options.skipTranslationOnMissingKey && this.tr(key, params) === key) { - i18nLogger.warn('Couldn\'t find translation for key: ' + key); - return; - } + var attrCC = attr.replace(/-([a-z])/g, function (g) { + return g[1].toUpperCase(); + }); + var reservedNames = ['prepend', 'append', 'text', 'html']; + var i18nLogger = LogManager.getLogger('i18n'); + + if (reservedNames.indexOf(attr) > -1 && node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { + i18nLogger.warn('Aurelia I18N reserved attribute name\n\n [' + reservedNames.join(', ') + ']\n\n Your custom element has a bindable named ' + attr + ' which is a reserved word.\n\n If you\'d like Aurelia I18N to translate your bindable instead, please consider giving it another name.'); + } - switch (attr) { - case 'text': - var newChild = DOM.createTextNode(this.tr(key, params)); - if (node._newChild && node._newChild.parentNode === node) { - node.removeChild(node._newChild); - } - - node._newChild = newChild; - while (node.firstChild) { - node.removeChild(node.firstChild); - } - node.appendChild(node._newChild); - break; - case 'prepend': - var prependParser = DOM.createElement('div'); - prependParser.innerHTML = this.tr(key, params); - for (var ni = node.childNodes.length - 1; ni >= 0; ni--) { - if (node.childNodes[ni]._prepended) { - node.removeChild(node.childNodes[ni]); + if (this.i18next.options.skipTranslationOnMissingKey && this.tr(key, params) === key) { + i18nLogger.warn('Couldn\'t find translation for key: ' + key); + return; + } + + switch (attr) { + case 'text': + var newChild = DOM.createTextNode(this.tr(key, params)); + if (node._newChild && node._newChild.parentNode === node) { + node.removeChild(node._newChild); } - } - for (var pi = prependParser.childNodes.length - 1; pi >= 0; pi--) { - prependParser.childNodes[pi]._prepended = true; - if (node.firstChild) { - node.insertBefore(prependParser.childNodes[pi], node.firstChild); - } else { - node.appendChild(prependParser.childNodes[pi]); + node._newChild = newChild; + while (node.firstChild) { + node.removeChild(node.firstChild); } - } - break; - case 'append': - var appendParser = DOM.createElement('div'); - appendParser.innerHTML = this.tr(key, params); - for (var _ni = node.childNodes.length - 1; _ni >= 0; _ni--) { - if (node.childNodes[_ni]._appended) { - node.removeChild(node.childNodes[_ni]); + node.appendChild(node._newChild); + break; + case 'prepend': + var prependParser = DOM.createElement('div'); + prependParser.innerHTML = this.tr(key, params); + for (var ni = node.childNodes.length - 1; ni >= 0; ni--) { + if (node.childNodes[ni]._prepended) { + node.removeChild(node.childNodes[ni]); + } } - } - - while (appendParser.firstChild) { - appendParser.firstChild._appended = true; - node.appendChild(appendParser.firstChild); - } - break; - case 'html': - node.innerHTML = this.tr(key, params); - break; - default: - if (node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { - node.au.controller.viewModel[attrCC] = this.tr(key, params); - } else { - node.setAttribute(attr, this.tr(key, params)); - } - - break; + + for (var pi = prependParser.childNodes.length - 1; pi >= 0; pi--) { + prependParser.childNodes[pi]._prepended = true; + if (node.firstChild) { + node.insertBefore(prependParser.childNodes[pi], node.firstChild); + } else { + node.appendChild(prependParser.childNodes[pi]); + } + } + break; + case 'append': + var appendParser = DOM.createElement('div'); + appendParser.innerHTML = this.tr(key, params); + for (var _ni = node.childNodes.length - 1; _ni >= 0; _ni--) { + if (node.childNodes[_ni]._appended) { + node.removeChild(node.childNodes[_ni]); + } + } + + while (appendParser.firstChild) { + appendParser.firstChild._appended = true; + node.appendChild(appendParser.firstChild); + } + break; + case 'html': + node.innerHTML = this.tr(key, params); + break; + default: + if (node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { + node.au.controller.viewModel[attrCC] = this.tr(key, params); + } else { + node.setAttribute(attr, this.tr(key, params)); + } + + break; + } } } }; diff --git a/dist/system/i18n.js b/dist/system/i18n.js index ee7342af..ec1d0768 100644 --- a/dist/system/i18n.js +++ b/dist/system/i18n.js @@ -170,7 +170,7 @@ System.register(['aurelia-logging', 'i18next', 'aurelia-pal', 'aurelia-event-agg while (i--) { var key = keys[i]; - var re = /\[([a-z\-]*)\]/ig; + var re = /\[([a-z\-, ]*)\]/ig; var m = void 0; var attr = 'text'; @@ -187,80 +187,87 @@ System.register(['aurelia-logging', 'i18next', 'aurelia-pal', 'aurelia-event-agg } } - if (!node._textContent) node._textContent = node.textContent; - if (!node._innerHTML) node._innerHTML = node.innerHTML; + var attrs = attr.split(','); + var j = attrs.length; - var attrCC = attr.replace(/-([a-z])/g, function (g) { - return g[1].toUpperCase(); - }); - var reservedNames = ['prepend', 'append', 'text', 'html']; - var i18nLogger = LogManager.getLogger('i18n'); + while (j--) { + attr = attrs[j].trim(); - if (reservedNames.indexOf(attr) > -1 && node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { - i18nLogger.warn('Aurelia I18N reserved attribute name\n\n[' + reservedNames.join(', ') + ']\n\nYour custom element has a bindable named ' + attr + ' which is a reserved word.\n\nIf you\'d like Aurelia I18N to translate your bindable instead, please consider giving it another name.'); - } + if (!node._textContent) node._textContent = node.textContent; + if (!node._innerHTML) node._innerHTML = node.innerHTML; - if (this.i18next.options.skipTranslationOnMissingKey && this.tr(key, params) === key) { - i18nLogger.warn('Couldn\'t find translation for key: ' + key); - return; - } + var attrCC = attr.replace(/-([a-z])/g, function (g) { + return g[1].toUpperCase(); + }); + var reservedNames = ['prepend', 'append', 'text', 'html']; + var i18nLogger = LogManager.getLogger('i18n'); + + if (reservedNames.indexOf(attr) > -1 && node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { + i18nLogger.warn('Aurelia I18N reserved attribute name\n\n [' + reservedNames.join(', ') + ']\n\n Your custom element has a bindable named ' + attr + ' which is a reserved word.\n\n If you\'d like Aurelia I18N to translate your bindable instead, please consider giving it another name.'); + } - switch (attr) { - case 'text': - var newChild = DOM.createTextNode(this.tr(key, params)); - if (node._newChild && node._newChild.parentNode === node) { - node.removeChild(node._newChild); - } - - node._newChild = newChild; - while (node.firstChild) { - node.removeChild(node.firstChild); - } - node.appendChild(node._newChild); - break; - case 'prepend': - var prependParser = DOM.createElement('div'); - prependParser.innerHTML = this.tr(key, params); - for (var ni = node.childNodes.length - 1; ni >= 0; ni--) { - if (node.childNodes[ni]._prepended) { - node.removeChild(node.childNodes[ni]); + if (this.i18next.options.skipTranslationOnMissingKey && this.tr(key, params) === key) { + i18nLogger.warn('Couldn\'t find translation for key: ' + key); + return; + } + + switch (attr) { + case 'text': + var newChild = DOM.createTextNode(this.tr(key, params)); + if (node._newChild && node._newChild.parentNode === node) { + node.removeChild(node._newChild); } - } - for (var pi = prependParser.childNodes.length - 1; pi >= 0; pi--) { - prependParser.childNodes[pi]._prepended = true; - if (node.firstChild) { - node.insertBefore(prependParser.childNodes[pi], node.firstChild); - } else { - node.appendChild(prependParser.childNodes[pi]); + node._newChild = newChild; + while (node.firstChild) { + node.removeChild(node.firstChild); } - } - break; - case 'append': - var appendParser = DOM.createElement('div'); - appendParser.innerHTML = this.tr(key, params); - for (var _ni = node.childNodes.length - 1; _ni >= 0; _ni--) { - if (node.childNodes[_ni]._appended) { - node.removeChild(node.childNodes[_ni]); + node.appendChild(node._newChild); + break; + case 'prepend': + var prependParser = DOM.createElement('div'); + prependParser.innerHTML = this.tr(key, params); + for (var ni = node.childNodes.length - 1; ni >= 0; ni--) { + if (node.childNodes[ni]._prepended) { + node.removeChild(node.childNodes[ni]); + } } - } - - while (appendParser.firstChild) { - appendParser.firstChild._appended = true; - node.appendChild(appendParser.firstChild); - } - break; - case 'html': - node.innerHTML = this.tr(key, params); - break; - default: - if (node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { - node.au.controller.viewModel[attrCC] = this.tr(key, params); - } else { - node.setAttribute(attr, this.tr(key, params)); - } - - break; + + for (var pi = prependParser.childNodes.length - 1; pi >= 0; pi--) { + prependParser.childNodes[pi]._prepended = true; + if (node.firstChild) { + node.insertBefore(prependParser.childNodes[pi], node.firstChild); + } else { + node.appendChild(prependParser.childNodes[pi]); + } + } + break; + case 'append': + var appendParser = DOM.createElement('div'); + appendParser.innerHTML = this.tr(key, params); + for (var _ni = node.childNodes.length - 1; _ni >= 0; _ni--) { + if (node.childNodes[_ni]._appended) { + node.removeChild(node.childNodes[_ni]); + } + } + + while (appendParser.firstChild) { + appendParser.firstChild._appended = true; + node.appendChild(appendParser.firstChild); + } + break; + case 'html': + node.innerHTML = this.tr(key, params); + break; + default: + if (node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { + node.au.controller.viewModel[attrCC] = this.tr(key, params); + } else { + node.setAttribute(attr, this.tr(key, params)); + } + + break; + } } } }; diff --git a/dist/temp/aurelia-i18n.js b/dist/temp/aurelia-i18n.js index c12e7685..4df687cf 100644 --- a/dist/temp/aurelia-i18n.js +++ b/dist/temp/aurelia-i18n.js @@ -731,7 +731,7 @@ var I18N = exports.I18N = (_temp = _class2 = function () { while (i--) { var key = keys[i]; - var re = /\[([a-z\-]*)\]/ig; + var re = /\[([a-z\-, ]*)\]/ig; var m = void 0; var attr = 'text'; @@ -748,80 +748,87 @@ var I18N = exports.I18N = (_temp = _class2 = function () { } } - if (!node._textContent) node._textContent = node.textContent; - if (!node._innerHTML) node._innerHTML = node.innerHTML; + var attrs = attr.split(','); + var j = attrs.length; - var attrCC = attr.replace(/-([a-z])/g, function (g) { - return g[1].toUpperCase(); - }); - var reservedNames = ['prepend', 'append', 'text', 'html']; - var i18nLogger = LogManager.getLogger('i18n'); + while (j--) { + attr = attrs[j].trim(); - if (reservedNames.indexOf(attr) > -1 && node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { - i18nLogger.warn('Aurelia I18N reserved attribute name\n\n[' + reservedNames.join(', ') + ']\n\nYour custom element has a bindable named ' + attr + ' which is a reserved word.\n\nIf you\'d like Aurelia I18N to translate your bindable instead, please consider giving it another name.'); - } + if (!node._textContent) node._textContent = node.textContent; + if (!node._innerHTML) node._innerHTML = node.innerHTML; - if (this.i18next.options.skipTranslationOnMissingKey && this.tr(key, params) === key) { - i18nLogger.warn('Couldn\'t find translation for key: ' + key); - return; - } + var attrCC = attr.replace(/-([a-z])/g, function (g) { + return g[1].toUpperCase(); + }); + var reservedNames = ['prepend', 'append', 'text', 'html']; + var i18nLogger = LogManager.getLogger('i18n'); - switch (attr) { - case 'text': - var newChild = _aureliaPal.DOM.createTextNode(this.tr(key, params)); - if (node._newChild && node._newChild.parentNode === node) { - node.removeChild(node._newChild); - } + if (reservedNames.indexOf(attr) > -1 && node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { + i18nLogger.warn('Aurelia I18N reserved attribute name\n\n [' + reservedNames.join(', ') + ']\n\n Your custom element has a bindable named ' + attr + ' which is a reserved word.\n\n If you\'d like Aurelia I18N to translate your bindable instead, please consider giving it another name.'); + } - node._newChild = newChild; - while (node.firstChild) { - node.removeChild(node.firstChild); - } - node.appendChild(node._newChild); - break; - case 'prepend': - var prependParser = _aureliaPal.DOM.createElement('div'); - prependParser.innerHTML = this.tr(key, params); - for (var ni = node.childNodes.length - 1; ni >= 0; ni--) { - if (node.childNodes[ni]._prepended) { - node.removeChild(node.childNodes[ni]); + if (this.i18next.options.skipTranslationOnMissingKey && this.tr(key, params) === key) { + i18nLogger.warn('Couldn\'t find translation for key: ' + key); + return; + } + + switch (attr) { + case 'text': + var newChild = _aureliaPal.DOM.createTextNode(this.tr(key, params)); + if (node._newChild && node._newChild.parentNode === node) { + node.removeChild(node._newChild); } - } - for (var pi = prependParser.childNodes.length - 1; pi >= 0; pi--) { - prependParser.childNodes[pi]._prepended = true; - if (node.firstChild) { - node.insertBefore(prependParser.childNodes[pi], node.firstChild); - } else { - node.appendChild(prependParser.childNodes[pi]); + node._newChild = newChild; + while (node.firstChild) { + node.removeChild(node.firstChild); } - } - break; - case 'append': - var appendParser = _aureliaPal.DOM.createElement('div'); - appendParser.innerHTML = this.tr(key, params); - for (var _ni = node.childNodes.length - 1; _ni >= 0; _ni--) { - if (node.childNodes[_ni]._appended) { - node.removeChild(node.childNodes[_ni]); + node.appendChild(node._newChild); + break; + case 'prepend': + var prependParser = _aureliaPal.DOM.createElement('div'); + prependParser.innerHTML = this.tr(key, params); + for (var ni = node.childNodes.length - 1; ni >= 0; ni--) { + if (node.childNodes[ni]._prepended) { + node.removeChild(node.childNodes[ni]); + } } - } - while (appendParser.firstChild) { - appendParser.firstChild._appended = true; - node.appendChild(appendParser.firstChild); - } - break; - case 'html': - node.innerHTML = this.tr(key, params); - break; - default: - if (node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { - node.au.controller.viewModel[attrCC] = this.tr(key, params); - } else { - node.setAttribute(attr, this.tr(key, params)); - } + for (var pi = prependParser.childNodes.length - 1; pi >= 0; pi--) { + prependParser.childNodes[pi]._prepended = true; + if (node.firstChild) { + node.insertBefore(prependParser.childNodes[pi], node.firstChild); + } else { + node.appendChild(prependParser.childNodes[pi]); + } + } + break; + case 'append': + var appendParser = _aureliaPal.DOM.createElement('div'); + appendParser.innerHTML = this.tr(key, params); + for (var _ni = node.childNodes.length - 1; _ni >= 0; _ni--) { + if (node.childNodes[_ni]._appended) { + node.removeChild(node.childNodes[_ni]); + } + } + + while (appendParser.firstChild) { + appendParser.firstChild._appended = true; + node.appendChild(appendParser.firstChild); + } + break; + case 'html': + node.innerHTML = this.tr(key, params); + break; + default: + if (node.au && node.au.controller && node.au.controller.viewModel && attrCC in node.au.controller.viewModel) { + node.au.controller.viewModel[attrCC] = this.tr(key, params); + } else { + node.setAttribute(attr, this.tr(key, params)); + } - break; + break; + } } } }; diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 0d4334c3..14118373 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,13 @@ + +# [2.3.0](https://github.com/aurelia/i18n/compare/2.2.0...2.3.0) (2018-06-21) + + +### Features + +* **i18n:** allow multiple attributes with the same key by listing them comma-seperated ([666cfba](https://github.com/aurelia/i18n/commit/666cfba)) + + + # [2.2.0](https://github.com/aurelia/i18n/compare/2.1.2...2.2.0) (2018-05-08) diff --git a/package.json b/package.json index 96175be2..ed49a9eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-i18n", - "version": "2.2.0", + "version": "2.3.0", "description": "A plugin that provides i18n support.", "keywords": [ "aurelia",