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

knowledge-base-web-page-element-view: one i18next instance per element

parent e233cd55
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 {css, html} from 'lit-element'; import {css, html} from 'lit-element';
import {ScopedElementsMixin} from '@open-wc/scoped-elements'; import {ScopedElementsMixin} from '@open-wc/scoped-elements';
import {AuthKeycloak, LoginButton} from '@dbp-toolkit/auth'; import {AuthKeycloak, LoginButton} from '@dbp-toolkit/auth';
...@@ -10,7 +10,8 @@ import DBPLitElement from "@dbp-toolkit/common/dbp-lit-element"; ...@@ -10,7 +10,8 @@ import DBPLitElement from "@dbp-toolkit/common/dbp-lit-element";
export class KnowledgeBaseWebPageElementViewDemo extends ScopedElementsMixin(DBPLitElement) { export class KnowledgeBaseWebPageElementViewDemo extends ScopedElementsMixin(DBPLitElement) {
constructor() { constructor() {
super(); super();
this.lang = 'de'; this._i18n = createInstance();
this.lang = this._i18n.language;
this.entryPointUrl = ''; this.entryPointUrl = '';
this.noAuth = false; this.noAuth = false;
} }
...@@ -35,7 +36,7 @@ export class KnowledgeBaseWebPageElementViewDemo extends ScopedElementsMixin(DBP ...@@ -35,7 +36,7 @@ export class KnowledgeBaseWebPageElementViewDemo extends ScopedElementsMixin(DBP
update(changedProperties) { update(changedProperties) {
changedProperties.forEach((oldValue, propName) => { changedProperties.forEach((oldValue, propName) => {
if (propName === "lang") { if (propName === "lang") {
i18n.changeLanguage(this.lang); this._i18n.changeLanguage(this.lang);
} }
}); });
......
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 {html} from 'lit-element'; import {html} from 'lit-element';
import {ScopedElementsMixin} from '@open-wc/scoped-elements'; import {ScopedElementsMixin} from '@open-wc/scoped-elements';
import {MiniSpinner} from '@dbp-toolkit/common'; import {MiniSpinner} from '@dbp-toolkit/common';
...@@ -12,7 +12,8 @@ import {AdapterLitElement} from "@dbp-toolkit/provider/src/adapter-lit-element"; ...@@ -12,7 +12,8 @@ import {AdapterLitElement} from "@dbp-toolkit/provider/src/adapter-lit-element";
export class KnowledgeBaseWebPageElementView extends ScopedElementsMixin(AdapterLitElement) { export class KnowledgeBaseWebPageElementView extends ScopedElementsMixin(AdapterLitElement) {
constructor() { constructor() {
super(); super();
this.lang = 'de'; this._i18n = createInstance();
this.lang = this._i18n.language;
this.value = ''; this.value = '';
this.html = ''; this.html = '';
this.entryPointUrl = ''; this.entryPointUrl = '';
...@@ -56,6 +57,8 @@ export class KnowledgeBaseWebPageElementView extends ScopedElementsMixin(Adapter ...@@ -56,6 +57,8 @@ export class KnowledgeBaseWebPageElementView extends ScopedElementsMixin(Adapter
* Loads the data from the web page element * Loads the data from the web page element
*/ */
loadWebPageElement() { loadWebPageElement() {
const i18n = this._i18n;
if (this.auth.token === undefined || this.auth.token === "") { if (this.auth.token === undefined || this.auth.token === "") {
return; return;
} }
...@@ -107,7 +110,7 @@ export class KnowledgeBaseWebPageElementView extends ScopedElementsMixin(Adapter ...@@ -107,7 +110,7 @@ export class KnowledgeBaseWebPageElementView extends ScopedElementsMixin(Adapter
update(changedProperties) { update(changedProperties) {
changedProperties.forEach((oldValue, propName) => { changedProperties.forEach((oldValue, propName) => {
if (propName === "lang") { if (propName === "lang") {
i18n.changeLanguage(this.lang); this._i18n.changeLanguage(this.lang);
} }
switch(propName) { switch(propName) {
......
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