52 lines
1.9 KiB
HTML
52 lines
1.9 KiB
HTML
<link rel="import" href="../app-localize-behavior/app-localize-behavior.html">
|
|
|
|
<script>
|
|
|
|
// 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) {
|
|
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 = Strolch.getUserLocale();
|
|
this.useKeyIfMissing = true;
|
|
|
|
if (Strolch.isNotEmptyString(this.localesPath)) {
|
|
this.loadResources(this.resolveUrl(this.localesPath));
|
|
}
|
|
},
|
|
};
|
|
|
|
// inherit the behavior of the standard polymer localization
|
|
StrolchLocalizeBehavior = [Polymer.AppLocalizeBehavior, StrolchLocalizeBehaviorImpl];
|
|
</script>
|