Skip to content

Commit

Permalink
chore(all): prepare release 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Jun 21, 2018
1 parent 666cfba commit 336b8c3
Show file tree
Hide file tree
Showing 10 changed files with 540 additions and 481 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aurelia-i18n",
"version": "2.2.0",
"version": "2.3.0",
"description": "A plugin that provides i18n support.",
"keywords": [
"aurelia",
Expand Down
141 changes: 74 additions & 67 deletions dist/amd/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
}
}
}
};
Expand Down
159 changes: 83 additions & 76 deletions dist/aurelia-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
}
}
}
}
Expand Down
Loading

0 comments on commit 336b8c3

Please sign in to comment.