[Minor] modified localize() method to log errors, not throw

This commit is contained in:
Robert von Burg 2023-04-21 10:06:03 +02:00
parent 1dbad36d1f
commit 73fa021047
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
2 changed files with 18 additions and 3 deletions

View File

@ -1,7 +1,7 @@
{
"name": "strolch-wc-localize-behavior",
"description": "Strolch Polymer Localization Behavior extension",
"version": "1.1.15",
"version": "1.1.16",
"authors": [
"Franz Nieschalk",
"Robert von Burg"

View File

@ -13,9 +13,24 @@
created: function () {
this.__computeLocalizeOld = this.__computeLocalize;
this.__computeLocalize = function (language, resources, formats) {
var localizeFunc;
if (!resources[language])
return this.__computeLocalizeOld(this.fallbackLanguage, resources, formats).bind(this);
return this.__computeLocalizeOld(language, resources, formats).bind(this);
localizeFunc = this.__computeLocalizeOld(this.fallbackLanguage, resources, formats).bind(this);
localizeFunc = this.__computeLocalizeOld(language, resources, formats).bind(this);
return function () {
var key = arguments[0];
if (!key || !resources || !language || !resources[language])
return;
try {
return localizeFunc.apply(this, arguments);
} catch (e) {
console.log("Failed to translate key " + key);
console.log(e);
return key;
}
}.bind(this);
}.bind(this);
},
attached: function () {