Compare commits
7 Commits
Author | SHA1 | Date |
---|---|---|
Robert von Burg | c0d5d6003a | |
Robert von Burg | c9e1da2494 | |
Robert von Burg | 73fa021047 | |
Robert von Burg | 1dbad36d1f | |
Robert von Burg | 4d1fa139fb | |
Robert von Burg | 0bb3a22fa3 | |
Robert von Burg | ee8ed5505a |
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "strolch-wc-localize-behavior",
|
||||
"description": "Strolch Polymer Localization Behavior extension",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.18",
|
||||
"authors": [
|
||||
"Franz Nieschalk",
|
||||
"Robert von Burg"
|
||||
|
@ -20,7 +20,7 @@
|
|||
"homepage": "https://github.com/strolch-li/strolch-wc-localize-behavior",
|
||||
"ignore": [],
|
||||
"dependencies": {
|
||||
"strolchjs": "strolch-li/strolchjs#^0.4.3",
|
||||
"strolchjs": "strolch-li/strolchjs#^0.5.3",
|
||||
|
||||
"app-localize-behavior": "PolymerElements/app-localize-behavior#^1.0.2"
|
||||
}
|
||||
|
|
|
@ -4,18 +4,46 @@
|
|||
|
||||
// custom behaviour accessing the configuration above
|
||||
StrolchLocalizeBehaviorImpl = {
|
||||
attached: function () {
|
||||
var locale = Strolch.getUserLocale();
|
||||
//console.log("Initializing for '" + this.localName + "' for locale " + locale + " and path " + this.localesPath);
|
||||
properties: {
|
||||
fallbackLanguage: {
|
||||
type: String,
|
||||
value: "en"
|
||||
}
|
||||
},
|
||||
created: function () {
|
||||
this.__computeLocalizeOld = this.__computeLocalize;
|
||||
this.__computeLocalize = function (language, resources, formats) {
|
||||
var localizeFunc;
|
||||
if (!resources[language])
|
||||
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)
|
||||
return;
|
||||
if (!resources || !language || !resources[language])
|
||||
return key;
|
||||
|
||||
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 () {
|
||||
// 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
|
||||
|
|
Loading…
Reference in New Issue