strolch-wc-localize-behavior/strolch-wc-localize-behavio...

35 lines
1.3 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) {
if (!resources[language])
return this.__computeLocalizeOld(this.fallbackLanguage, resources, formats).bind(this);
return this.__computeLocalizeOld(language, resources, formats).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>