|
|
@ -1,67 +1,20 @@
|
|
|
|
/* global bootbox */
|
|
|
|
/* global bootbox */
|
|
|
|
|
|
|
|
|
|
|
|
require(['translator'], function (shim) {
|
|
|
|
require(['translator'], function (shim) {
|
|
|
|
"use strict";
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
function descendantTextNodes(node) {
|
|
|
|
|
|
|
|
var textNodes = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function helper(node) {
|
|
|
|
|
|
|
|
if (node.nodeType === 3) {
|
|
|
|
|
|
|
|
textNodes.push(node);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
for (var i = 0, c = node.childNodes, l = c.length; i < l; i += 1) {
|
|
|
|
|
|
|
|
helper(c[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
helper(node);
|
|
|
|
|
|
|
|
return textNodes;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var translator = shim.Translator.create();
|
|
|
|
var translator = shim.Translator.create();
|
|
|
|
var dialog = bootbox.dialog;
|
|
|
|
var dialog = bootbox.dialog;
|
|
|
|
var attrsToTranslate = ['placeholder', 'title', 'value'];
|
|
|
|
var attrsToTranslate = ['placeholder', 'title', 'value'];
|
|
|
|
bootbox.dialog = function (options) {
|
|
|
|
bootbox.dialog = function (options) {
|
|
|
|
var show, $elem, nodes, text, attrNodes, attrText;
|
|
|
|
var show = options.show !== false;
|
|
|
|
|
|
|
|
|
|
|
|
show = options.show !== false;
|
|
|
|
|
|
|
|
options.show = false;
|
|
|
|
options.show = false;
|
|
|
|
|
|
|
|
|
|
|
|
$elem = dialog.call(bootbox, options);
|
|
|
|
var $elem = dialog.call(bootbox, options);
|
|
|
|
|
|
|
|
var element = $elem[0];
|
|
|
|
if (/\[\[.+\]\]/.test($elem[0].outerHTML)) {
|
|
|
|
|
|
|
|
nodes = descendantTextNodes($elem[0]);
|
|
|
|
|
|
|
|
text = nodes.map(function (node) {
|
|
|
|
|
|
|
|
return node.nodeValue;
|
|
|
|
|
|
|
|
}).join(' || ');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attrNodes = attrsToTranslate.reduce(function (prev, attr) {
|
|
|
|
|
|
|
|
return prev.concat(nodes.map.call($elem.find('[' + attr + '*="[["]'), function (el) {
|
|
|
|
|
|
|
|
return [attr, el];
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
attrText = attrNodes.map(function (node) {
|
|
|
|
|
|
|
|
return node[1].getAttribute(node[0]);
|
|
|
|
|
|
|
|
}).join(' || ');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Promise.all([
|
|
|
|
if (/\[\[.+\]\]/.test(element.outerHTML)) {
|
|
|
|
translator.translate(text),
|
|
|
|
translator.translateInPlace(element, attrsToTranslate).then(function () {
|
|
|
|
translator.translate(attrText),
|
|
|
|
|
|
|
|
]).then(function (ref) {
|
|
|
|
|
|
|
|
var translated = ref[0];
|
|
|
|
|
|
|
|
var translatedAttrs = ref[1];
|
|
|
|
|
|
|
|
if (translated) {
|
|
|
|
|
|
|
|
translated.split(' || ').forEach(function (html, i) {
|
|
|
|
|
|
|
|
$(nodes[i]).replaceWith(html);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (translatedAttrs) {
|
|
|
|
|
|
|
|
translatedAttrs.split(' || ').forEach(function (text, i) {
|
|
|
|
|
|
|
|
attrNodes[i][1].setAttribute(attrNodes[i][0], text);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show) {
|
|
|
|
if (show) {
|
|
|
|
$elem.modal('show');
|
|
|
|
$elem.modal('show');
|
|
|
|
}
|
|
|
|
}
|
|
|
|