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

person-profile: one i18next instance per element

parent d0c86a05
No related branches found
No related tags found
1 merge request!67Create a new i18next instance for every web component
import {AuthKeycloak, LoginButton} from '@dbp-toolkit/auth'; import {AuthKeycloak, LoginButton} from '@dbp-toolkit/auth';
import {i18n} from './i18n.js'; import {createInstance} from './i18n.js';
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 DBPLitElement from '@dbp-toolkit/common/dbp-lit-element'; import DBPLitElement from '@dbp-toolkit/common/dbp-lit-element';
...@@ -12,7 +12,8 @@ import {PersonSelect} from '@dbp-toolkit/person-select'; ...@@ -12,7 +12,8 @@ import {PersonSelect} from '@dbp-toolkit/person-select';
export class PersonProfileDemo extends ScopedElementsMixin(DBPLitElement) { export class PersonProfileDemo extends ScopedElementsMixin(DBPLitElement) {
constructor() { constructor() {
super(); super();
this.lang = 'de'; this._i18n = createInstance();
this.lang = this._i18n.language;
this.entryPointUrl = ''; this.entryPointUrl = '';
this.person = ''; this.person = '';
this.selectedPerson = ''; this.selectedPerson = '';
...@@ -42,6 +43,10 @@ export class PersonProfileDemo extends ScopedElementsMixin(DBPLitElement) { ...@@ -42,6 +43,10 @@ export class PersonProfileDemo extends ScopedElementsMixin(DBPLitElement) {
} }
update(changedProperties) { update(changedProperties) {
if (changedProperties.has("lang")) {
this._i18n.changeLanguage(this.lang);
}
changedProperties.forEach((oldValue, propName) => { changedProperties.forEach((oldValue, propName) => {
switch (propName) { switch (propName) {
case 'auth': case 'auth':
...@@ -61,7 +66,6 @@ export class PersonProfileDemo extends ScopedElementsMixin(DBPLitElement) { ...@@ -61,7 +66,6 @@ export class PersonProfileDemo extends ScopedElementsMixin(DBPLitElement) {
connectedCallback() { connectedCallback() {
super.connectedCallback(); super.connectedCallback();
i18n.changeLanguage(this.lang);
const that = this; const that = this;
this.updateComplete.then(()=>{ this.updateComplete.then(()=>{
......
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 JSONLD from '@dbp-toolkit/common/jsonld'; import JSONLD from '@dbp-toolkit/common/jsonld';
import {css, html} from 'lit-element'; import {css, html} from 'lit-element';
import {i18n} from './i18n.js'; import {createInstance} from './i18n.js';
import DBPLitElement from '@dbp-toolkit/common/dbp-lit-element'; import DBPLitElement from '@dbp-toolkit/common/dbp-lit-element';
import * as commonStyles from '@dbp-toolkit/common/styles'; import * as commonStyles from '@dbp-toolkit/common/styles';
...@@ -10,7 +10,8 @@ export class PersonProfile extends DBPLitElement { ...@@ -10,7 +10,8 @@ export class PersonProfile extends DBPLitElement {
constructor() { constructor() {
super(); super();
this.lang = 'de'; this._i18n = createInstance();
this.lang = this._i18n.language;
this.entryPointUrl = ''; this.entryPointUrl = '';
this.jsonld = null; this.jsonld = null;
this.value = ''; this.value = '';
...@@ -29,18 +30,11 @@ export class PersonProfile extends DBPLitElement { ...@@ -29,18 +30,11 @@ export class PersonProfile extends DBPLitElement {
}; };
} }
connectedCallback() {
super.connectedCallback();
this.updateComplete.then(()=>{
});
}
update(changedProperties) { update(changedProperties) {
changedProperties.forEach((oldValue, propName) => { changedProperties.forEach((oldValue, propName) => {
switch (propName) { switch (propName) {
case "lang": case "lang":
i18n.changeLanguage(this.lang); this._i18n.changeLanguage(this.lang);
break; break;
case "entryPointUrl": { case "entryPointUrl": {
const that = this; const that = this;
...@@ -83,6 +77,7 @@ export class PersonProfile extends DBPLitElement { ...@@ -83,6 +77,7 @@ export class PersonProfile extends DBPLitElement {
} }
render() { render() {
const i18n = this._i18n;
let role = i18n.t('person-profile.unknown'); let role = i18n.t('person-profile.unknown');
if (this.person !== null && this.person.roles !== undefined) { if (this.person !== null && this.person.roles !== undefined) {
// roles are only defined for self-disclosure // roles are only defined for self-disclosure
......
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