Skip to content
Snippets Groups Projects
Commit f5f2ebc0 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

typescript-example: one i18next instance per element

parent 83c59262
No related branches found
No related tags found
1 merge request!67Create a new i18next instance for every web component
import {createInstance} from '@dbp-toolkit/common/i18next.js'; import {createInstance as _createInstance} from '@dbp-toolkit/common/i18next.js';
import de from './i18n/de/translation.json'; import de from './i18n/de/translation.json';
import en from './i18n/en/translation.json'; import en from './i18n/en/translation.json';
export const i18n = createInstance({en: en, de: de}, 'de', 'en'); export function createInstance() {
\ No newline at end of file return _createInstance({en: en, de: de}, 'de', 'en');
}
\ No newline at end of file
import {html,LitElement,property} from 'lit-element'; import {html,LitElement} from 'lit-element';
import {i18n} from './i18n'; import {createInstance} from './i18n';
export class TypeScriptExample extends LitElement { export class TypeScriptExample extends LitElement {
...@@ -8,20 +8,20 @@ export class TypeScriptExample extends LitElement { ...@@ -8,20 +8,20 @@ export class TypeScriptExample extends LitElement {
constructor() { constructor() {
super(); super();
this._i18n = i18n.cloneInstance(); this._i18n = createInstance();
this.lang = this._i18n.language;
} }
@property({type: String}) static get properties() {
lang = ''; return {
lang: {type: String}
};
}
update(changedProperties) { update(changedProperties) {
changedProperties.forEach((oldValue, propName) => { if (changedProperties.has("lang")) {
switch (propName) { this._i18n.changeLanguage(this.lang);
case "lang": }
this._i18n.changeLanguage(this.lang);
break;
}
});
super.update(changedProperties); super.update(changedProperties);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment