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 {send as notify} from '@dbp-toolkit/common/notification';
import {css, html, LitElement} from 'lit-element'; import {css, html, LitElement} from 'lit-element';
import {ScopedElementsMixin} from '@open-wc/scoped-elements'; import {ScopedElementsMixin} from '@open-wc/scoped-elements';
...@@ -9,7 +9,8 @@ import * as commonStyles from "@dbp-toolkit/common/styles"; ...@@ -9,7 +9,8 @@ import * as commonStyles from "@dbp-toolkit/common/styles";
export class NotificationDemo extends ScopedElementsMixin(LitElement) { export class NotificationDemo extends ScopedElementsMixin(LitElement) {
constructor() { constructor() {
super(); super();
this.lang = 'de'; this._i18n = createInstance();
this.lang = this._i18n.language;
} }
static get scopedElements() { static get scopedElements() {
...@@ -24,12 +25,14 @@ export class NotificationDemo extends ScopedElementsMixin(LitElement) { ...@@ -24,12 +25,14 @@ export class NotificationDemo extends ScopedElementsMixin(LitElement) {
}; };
} }
connectedCallback() { update(changedProperties) {
super.connectedCallback(); changedProperties.forEach((oldValue, propName) => {
i18n.changeLanguage(this.lang); if (propName === "lang") {
this._i18n.changeLanguage(this.lang);
this.updateComplete.then(()=>{ }
}); });
super.update(changedProperties);
} }
static get styles() { static get styles() {
...@@ -42,6 +45,8 @@ export class NotificationDemo extends ScopedElementsMixin(LitElement) { ...@@ -42,6 +45,8 @@ export class NotificationDemo extends ScopedElementsMixin(LitElement) {
} }
render() { render() {
const i18n = this._i18n;
return html` return html`
<section class="section"> <section class="section">
<div class="container"> <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 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 {i18n} from './i18n'; import {createInstance} from './i18n';
import {createUUID} from './utils'; import {createUUID} from './utils';
import {css, html} from 'lit-element'; import {css, html} from 'lit-element';
import DBPLitElement from '@dbp-toolkit/common/dbp-lit-element'; import DBPLitElement from '@dbp-toolkit/common/dbp-lit-element';
...@@ -10,7 +10,8 @@ import * as commonStyles from '@dbp-toolkit/common/styles'; ...@@ -10,7 +10,8 @@ import * as commonStyles from '@dbp-toolkit/common/styles';
export class Notification extends DBPLitElement { export class Notification extends DBPLitElement {
constructor() { constructor() {
super(); super();
this.lang = 'de'; this._i18n = createInstance();
this.lang = this._i18n.language;
} }
/** /**
...@@ -25,7 +26,6 @@ export class Notification extends DBPLitElement { ...@@ -25,7 +26,6 @@ export class Notification extends DBPLitElement {
connectedCallback() { connectedCallback() {
super.connectedCallback(); super.connectedCallback();
i18n.changeLanguage(this.lang);
const that = this; const that = this;
window.addEventListener("dbp-notification-send", (e) => { window.addEventListener("dbp-notification-send", (e) => {
...@@ -63,9 +63,6 @@ export class Notification extends DBPLitElement { ...@@ -63,9 +63,6 @@ export class Notification extends DBPLitElement {
// mark the event as handled // mark the event as handled
e.preventDefault(); e.preventDefault();
}); });
this.updateComplete.then(()=>{
});
} }
removeMessageId(messageElementId) { removeMessageId(messageElementId) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment