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

organization-select: one i18next instance per element

parent 7dffef4c
No related branches found
No related tags found
1 merge request!67Create a new i18next instance for every web component
import {i18n} from './i18n.js';
import {createInstance} from './i18n.js';
import {css, html} from 'lit-element';
import {ScopedElementsMixin} from '@open-wc/scoped-elements';
import {OrganizationSelect} from './organization-select.js';
......@@ -10,7 +10,8 @@ import DBPLitElement from "@dbp-toolkit/common/dbp-lit-element";
export class OrganizationSelectDemo extends ScopedElementsMixin(DBPLitElement) {
constructor() {
super();
this.lang = 'de';
this._i18n = createInstance();
this.lang = this._i18n.language;
this.entryPointUrl = '';
this.noAuth = false;
}
......@@ -32,12 +33,11 @@ export class OrganizationSelectDemo extends ScopedElementsMixin(DBPLitElement) {
};
}
connectedCallback() {
super.connectedCallback();
i18n.changeLanguage(this.lang);
this.updateComplete.then(()=>{
});
update(changedProperties) {
if (changedProperties.has("lang")) {
this._i18n.changeLanguage(this.lang);
}
super.update(changedProperties);
}
static get styles() {
......
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 $ from 'jquery';
import select2 from 'select2';
import select2CSSPath from 'select2/dist/css/select2.min.css';
import {i18n} from './i18n.js';
import {createInstance} from './i18n.js';
import {css, html} from 'lit-element';
import * as commonUtils from '@dbp-toolkit/common/utils';
import * as commonStyles from '@dbp-toolkit/common/styles';
......@@ -16,7 +16,8 @@ export class OrganizationSelect extends AdapterLitElement {
constructor() {
super();
this.auth = {};
this.lang = i18n.language;
this._i18n = createInstance();
this.lang = this._i18n.language;
this.entryPointUrl = '';
this.jsonld = null;
this.organizations = [];
......@@ -93,6 +94,7 @@ export class OrganizationSelect extends AdapterLitElement {
}
async updateSelect2() {
const i18n = this._i18n;
await this.updateComplete;
const $select = this.$('#' + this.selectId);
......@@ -181,7 +183,7 @@ export class OrganizationSelect extends AdapterLitElement {
changedProperties.forEach((oldValue, propName) => {
switch (propName) {
case "lang":
i18n.changeLanguage(this.lang);
this._i18n.changeLanguage(this.lang);
this.updateSelect2();
break;
case "value": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment