1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +01:00

Added parameters to parseTranslation

This commit is contained in:
kkapsner 2020-01-25 00:42:16 +01:00
parent b48ad91dfe
commit 01b63b356c

View File

@ -27,7 +27,7 @@
return id; return id;
}; };
scope.parseTranslation = function parseTranslation(message){ scope.parseTranslation = function parseTranslation(message, parameters = {}){
const container = document.createDocumentFragment(); const container = document.createDocumentFragment();
message.split(/(\{[^}]+\})/).forEach(function(part){ message.split(/(\{[^}]+\})/).forEach(function(part){
@ -50,6 +50,19 @@
container.appendChild(link); container.appendChild(link);
break; break;
} }
default:
if (parameters[args[0]]){
const parameter = parameters[args[0]];
if ((typeof parameter) === "function"){
container.appendChild(parameter(args.slice(1).join(":")));
}
else {
container.appendChild(document.createTextNode(parameter));
}
}
else {
container.appendChild(document.createTextNode(part));
}
} }
} }
else { else {