forked from miztroh-zz/wysiwyg-e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwysiwyg-localize.js
67 lines (60 loc) · 1.27 KB
/
wysiwyg-localize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
export class WysiwygLocalize extends PolymerElement {
static get template() {
return html`
<slot></slot>
`;
}
static get properties() {
return {
//
// A string of the key to look up from resources object
//
stringKey: {
type: String,
notify: true
},
//
// An object with key-value pairs per language, per word
//
resources: {
type: Object,
notify: true
},
//
// Used to localize the stringKey
//
language: {
type: String,
notify: true
},
//
// A computed string localized based on stringKey, resources, and language
//
localized: {
type: String,
value: '',
computed: '_computeLocalized(stringKey, resources, language)',
observer: '_localizedChanged',
notify: true
}
};
}
ready() {
super.ready();
setTimeout(
function () {
this._localizedChanged();
}.bind(this),
100
);
}
_computeLocalized (stringKey, resources, language) {
if (resources && resources[language] && resources[language][stringKey]) return resources[language][stringKey];
return '';
}
_localizedChanged() {
this.textContent = this.localized;
}
}
customElements.define('wysiwyg-localize', WysiwygLocalize);