From 2df32d7c7af706f8b62a37bd031634ac6d5441d0 Mon Sep 17 00:00:00 2001 From: Christoph Reiter <reiter.christoph@gmail.com> Date: Thu, 1 Jul 2021 17:00:01 +0200 Subject: [PATCH] matomo: one i18next instance per element --- packages/matomo/src/dbp-matomo-demo.js | 16 +++++++++++----- packages/matomo/src/i18n.js | 6 ++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/matomo/src/dbp-matomo-demo.js b/packages/matomo/src/dbp-matomo-demo.js index bf07bd0f..cad9ec43 100644 --- a/packages/matomo/src/dbp-matomo-demo.js +++ b/packages/matomo/src/dbp-matomo-demo.js @@ -1,4 +1,4 @@ -import {i18n} from './i18n.js'; +import {createInstance} from './i18n.js'; import {css, html} from 'lit-element'; import {ScopedElementsMixin} from '@open-wc/scoped-elements'; import {AuthKeycloak, LoginButton} from '@dbp-toolkit/auth'; @@ -12,7 +12,8 @@ export class MatomoDemo extends ScopedElementsMixin(DBPLitElement) { constructor() { super(); - this.lang = 'de'; + this._i18n = createInstance(); + this.lang = this._i18n.language; this.entryPointUrl = ''; this.matomoUrl = ''; this.matomoSiteId = -1; @@ -38,9 +39,14 @@ export class MatomoDemo extends ScopedElementsMixin(DBPLitElement) { }; } - connectedCallback() { - super.connectedCallback(); - i18n.changeLanguage(this.lang); + update(changedProperties) { + changedProperties.forEach((oldValue, propName) => { + if (propName === "lang") { + this._i18n.changeLanguage(this.lang); + } + }); + + super.update(changedProperties); } track(action, message) { diff --git a/packages/matomo/src/i18n.js b/packages/matomo/src/i18n.js index 498d9f03..975c1993 100644 --- a/packages/matomo/src/i18n.js +++ b/packages/matomo/src/i18n.js @@ -1,6 +1,8 @@ -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 -- GitLab