From ee8ed5505aac95bf4cc1bbeb84a930bf7439067d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 10 Sep 2021 08:03:01 +0200 Subject: [PATCH] [Fix] Added fallbackLanguage as en --- bower.json | 2 +- strolch-wc-localize-behavior.html | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index dc7c660..af32492 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "strolch-wc-localize-behavior", "description": "Strolch Polymer Localization Behavior extension", - "version": "1.1.11", + "version": "1.1.12", "authors": [ "Franz Nieschalk", "Robert von Burg" diff --git a/strolch-wc-localize-behavior.html b/strolch-wc-localize-behavior.html index 69ddea1..279bfd7 100644 --- a/strolch-wc-localize-behavior.html +++ b/strolch-wc-localize-behavior.html @@ -4,18 +4,29 @@ // custom behaviour accessing the configuration above StrolchLocalizeBehaviorImpl = { + properties: { + fallbackLanguage: { + type: String, + value: "en" + } + }, + created: function () { + this.__computeLocalizeOld = this.__computeLocalize; + this.__computeLocalize = function (language, resources, formats) { + if (!resources[language]) + return this.__computeLocalizeOld(this.fallbackLanguage, resources, formats).bind(this); + return this.__computeLocalizeOld(language, resources, formats).bind(this); + }.bind(this); + }, attached: function () { - var locale = Strolch.getUserLocale(); - //console.log("Initializing for '" + this.localName + "' for locale " + locale + " and path " + this.localesPath); - // load the language resource of the configured language - this.language = locale; + this.language = Strolch.getUserLocale(); this.useKeyIfMissing = true; if (Strolch.isNotEmptyString(this.localesPath)) { this.loadResources(this.resolveUrl(this.localesPath)); } - } + }, }; // inherit the behavior of the standard polymer localization