From 0388f5787abc04564141b67bf444421f5bd450a8 Mon Sep 17 00:00:00 2001 From: Steelskin3 Date: Fri, 23 Feb 2018 11:51:59 +0100 Subject: [PATCH] Fix exception on translation of objects Sometimes, the content of translations[module.name][key] is not a string but an entire object. It cause a crash on template.replace(...) of createStringFromTemplate(...). It is currently the case of MMM-Voice-Control and the previous commit have broked this module (10 month ago... I am surprised to be the first founded it) --- js/translator.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/js/translator.js b/js/translator.js index b82a739e..b1e90ab2 100644 --- a/js/translator.js +++ b/js/translator.js @@ -126,6 +126,9 @@ var Translator = (function() { // variables: {timeToWait: "2 hours", work: "painting"} // to: "Please wait for 2 hours before continuing with painting." function createStringFromTemplate(template, variables) { + if(Object.prototype.toString.call(template) !== '[object String]') { + return template; + } if(variables.fallback && !template.match(new RegExp("\{.+\}"))) { template = variables.fallback; }