From 0388f5787abc04564141b67bf444421f5bd450a8 Mon Sep 17 00:00:00 2001 From: Steelskin3 Date: Fri, 23 Feb 2018 11:51:59 +0100 Subject: [PATCH 1/2] 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; } From 08c0d39b2380d672f652b9f36003a2adb7995d9a Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Sun, 25 Mar 2018 14:55:42 +0200 Subject: [PATCH 2/2] Update translator.js --- js/translator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/translator.js b/js/translator.js index b1e90ab2..56850fc7 100644 --- a/js/translator.js +++ b/js/translator.js @@ -126,7 +126,7 @@ 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]') { + if(Object.prototype.toString.call(template) !== "[object String]") { return template; } if(variables.fallback && !template.match(new RegExp("\{.+\}"))) {