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)
This commit is contained in:
Steelskin3 2018-02-23 11:51:59 +01:00 committed by GitHub
parent 20823bfc87
commit 0388f5787a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -126,6 +126,9 @@ var Translator = (function() {
// variables: {timeToWait: "2 hours", work: "painting"} // variables: {timeToWait: "2 hours", work: "painting"}
// to: "Please wait for 2 hours before continuing with painting." // to: "Please wait for 2 hours before continuing with painting."
function createStringFromTemplate(template, variables) { function createStringFromTemplate(template, variables) {
if(Object.prototype.toString.call(template) !== '[object String]') {
return template;
}
if(variables.fallback && !template.match(new RegExp("\{.+\}"))) { if(variables.fallback && !template.match(new RegExp("\{.+\}"))) {
template = variables.fallback; template = variables.fallback;
} }