2017-02-20 12:57:39 +01:00
|
|
|
<link rel="import" href="../app-localize-behavior/app-localize-behavior.html">
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
// custom behaviour accessing the configuration above
|
|
|
|
StrolchLocalizeBehaviorImpl = {
|
2021-09-10 08:03:01 +02:00
|
|
|
properties: {
|
|
|
|
fallbackLanguage: {
|
|
|
|
type: String,
|
|
|
|
value: "en"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created: function () {
|
|
|
|
this.__computeLocalizeOld = this.__computeLocalize;
|
|
|
|
this.__computeLocalize = function (language, resources, formats) {
|
2023-04-21 10:06:03 +02:00
|
|
|
var localizeFunc;
|
2021-09-10 08:03:01 +02:00
|
|
|
if (!resources[language])
|
2023-04-21 10:06:03 +02:00
|
|
|
localizeFunc = this.__computeLocalizeOld(this.fallbackLanguage, resources, formats).bind(this);
|
|
|
|
localizeFunc = this.__computeLocalizeOld(language, resources, formats).bind(this);
|
|
|
|
|
|
|
|
return function () {
|
|
|
|
var key = arguments[0];
|
2023-07-04 12:35:05 +02:00
|
|
|
if(!key)
|
2023-07-07 08:06:06 +02:00
|
|
|
return;
|
2023-07-04 12:35:05 +02:00
|
|
|
if (!resources || !language || !resources[language])
|
|
|
|
return key;
|
2023-04-21 10:06:03 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
return localizeFunc.apply(this, arguments);
|
|
|
|
} catch (e) {
|
|
|
|
console.log("Failed to translate key " + key);
|
|
|
|
console.log(e);
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
}.bind(this);
|
2021-09-10 08:03:01 +02:00
|
|
|
}.bind(this);
|
|
|
|
},
|
2017-09-13 15:51:12 +02:00
|
|
|
attached: function () {
|
2017-02-20 12:57:39 +01:00
|
|
|
// load the language resource of the configured language
|
2021-09-10 08:03:01 +02:00
|
|
|
this.language = Strolch.getUserLocale();
|
2017-03-08 16:34:42 +01:00
|
|
|
this.useKeyIfMissing = true;
|
2017-09-13 15:51:12 +02:00
|
|
|
|
|
|
|
if (Strolch.isNotEmptyString(this.localesPath)) {
|
|
|
|
this.loadResources(this.resolveUrl(this.localesPath));
|
|
|
|
}
|
2021-09-10 08:03:01 +02:00
|
|
|
},
|
2017-02-20 12:57:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// inherit the behavior of the standard polymer localization
|
|
|
|
StrolchLocalizeBehavior = [Polymer.AppLocalizeBehavior, StrolchLocalizeBehaviorImpl];
|
2017-03-08 16:31:27 +01:00
|
|
|
</script>
|