forked from teuchezh/dynamic-weather-card
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirective.ts
More file actions
28 lines (23 loc) · 721 Bytes
/
Copy pathdirective.ts
File metadata and controls
28 lines (23 loc) · 721 Bytes
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
import { directive } from 'lit/directive.js';
import { AsyncDirective } from 'lit/async-directive.js';
import { i18n } from './index';
class TDirective extends AsyncDirective {
private _key: string = '';
private _onLangChange: (() => void) | null = null;
render(key: string): string {
this._key = key;
return i18n.t(key);
}
override reconnected(): void {
this._onLangChange = () => {
this.setValue(i18n.t(this._key));
};
window.addEventListener('language-changed', this._onLangChange);
}
override disconnected(): void {
if (this._onLangChange) {
window.removeEventListener('language-changed', this._onLangChange);
}
}
}
export const t = directive(TDirective);