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

notification: one i18next instance per element

parent 79ded395
No related branches found
No related tags found
1 merge request!67Create a new i18next instance for every web component
import {i18n} from './i18n';
import {createInstance} from './i18n';
import {send as notify} from '@dbp-toolkit/common/notification';
import {css, html, LitElement} from 'lit-element';
import {ScopedElementsMixin} from '@open-wc/scoped-elements';
......@@ -9,7 +9,8 @@ import * as commonStyles from "@dbp-toolkit/common/styles";
export class NotificationDemo extends ScopedElementsMixin(LitElement) {
constructor() {
super();
this.lang = 'de';
this._i18n = createInstance();
this.lang = this._i18n.language;
}
static get scopedElements() {
......@@ -24,13 +25,15 @@ export class NotificationDemo extends ScopedElementsMixin(LitElement) {
};
}
connectedCallback() {
super.connectedCallback();
i18n.changeLanguage(this.lang);
update(changedProperties) {
changedProperties.forEach((oldValue, propName) => {
if (propName === "lang") {
this._i18n.changeLanguage(this.lang);
}
});
this.updateComplete.then(()=>{
});
}
super.update(changedProperties);
}
static get styles() {
// language=css
......@@ -42,6 +45,8 @@ export class NotificationDemo extends ScopedElementsMixin(LitElement) {
}
render() {
const i18n = this._i18n;
return html`
<section class="section">
<div class="container">
......
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 en from './i18n/en/translation.json';
export const i18n = createInstance({en: en, de: de}, 'de', 'en');
\ No newline at end of file
export function createInstance() {
return _createInstance({en: en, de: de}, 'de', 'en');
}
\ No newline at end of file
import {i18n} from './i18n';
import {createInstance} from './i18n';
import {createUUID} from './utils';
import {css, html} from 'lit-element';
import DBPLitElement from '@dbp-toolkit/common/dbp-lit-element';
......@@ -10,7 +10,8 @@ import * as commonStyles from '@dbp-toolkit/common/styles';
export class Notification extends DBPLitElement {
constructor() {
super();
this.lang = 'de';
this._i18n = createInstance();
this.lang = this._i18n.language;
}
/**
......@@ -25,7 +26,6 @@ export class Notification extends DBPLitElement {
connectedCallback() {
super.connectedCallback();
i18n.changeLanguage(this.lang);
const that = this;
window.addEventListener("dbp-notification-send", (e) => {
......@@ -63,9 +63,6 @@ export class Notification extends DBPLitElement {
// mark the event as handled
e.preventDefault();
});
this.updateComplete.then(()=>{
});
}
removeMessageId(messageElementId) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment