-
Notifications
You must be signed in to change notification settings - Fork 0
/
localize-mixin.js
39 lines (31 loc) · 1.04 KB
/
localize-mixin.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
import i18next from './init';
import { addResource, initializeStrings } from './language';
let _i18nextInitialized = false;
export const localizeMixin = Base => class localizeMixinElement extends Base {
_shouldRender(props, changedProps, old) {
return changedProps && changedProps.active
? props.active && _i18nextInitialized
: _i18nextInitialized;
}
connectedCallback() {
const ns = this.localName;
if (!_i18nextInitialized) {
i18next.on('initialized', (options) => {
_i18nextInitialized = true;
this.requestRender();
});
}
i18next.on('languageChanged', (lang) => {
addResource(lang, ns, this.constructor.strings);
this.requestRender();
});
if (super.connectedCallback) {
super.connectedCallback();
}
initializeStrings(ns, this.constructor.strings);
}
disconnectedCallback() {
// ToDo: Remove resources
}
};
export default localizeMixin;