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

data-table-view: one i18next instance per element

parent e2798914
No related branches found
No related tags found
1 merge request!67Create a new i18next instance for every web component
......@@ -7,7 +7,7 @@ import bttn from 'datatables.net-buttons-dt';
import bttn2 from 'datatables.net-buttons';
import bttnHtml5 from 'datatables.net-buttons/js/buttons.html5.js';
import bttnPrint from 'datatables.net-buttons/js/buttons.print.js';
import {i18n} from './i18n';
import {createInstance} from './i18n';
import {css, html, unsafeCSS} from 'lit-element';
import de from '../assets/datatables/i18n/German';
import en from '../assets/datatables/i18n/English';
......@@ -28,7 +28,8 @@ bttnPrint(window, $);
export class DataTableView extends AdapterLitElement {
constructor() {
super();
this.lang = 'de';
this._i18n = createInstance();
this.lang = this._i18n.language;
// datatable properties
this.table = null;
this.responsive = null;
......@@ -100,6 +101,7 @@ export class DataTableView extends AdapterLitElement {
set_datatable(data, languageChange = false) {
const lang_obj = this.lang === 'de' ? de : en;
const i18n = this._i18n;
if (typeof this.columns === 'undefined' || !this.columns.length) {
if (data.length)
......@@ -229,7 +231,7 @@ export class DataTableView extends AdapterLitElement {
changedProperties.forEach((oldValue, propName) => {
if (propName === "lang") {
i18n.changeLanguage(this.lang).catch(e => { console.log(e);});
this._i18n.changeLanguage(this.lang).catch(e => { console.log(e);});
languageChange = true;
}
});
......
import {AuthKeycloak, LoginButton} from '@dbp-toolkit/auth';
import {DataTableView} from './data-table-view.js';
import {i18n} from './i18n';
import {createInstance} from './i18n';
import {css, html} from 'lit-element';
import {ScopedElementsMixin} from '@open-wc/scoped-elements';
import * as commonUtils from '@dbp-toolkit/common/utils';
......@@ -10,7 +10,8 @@ import DBPLitElement from "@dbp-toolkit/common/dbp-lit-element";
export class DataTableViewDemo extends ScopedElementsMixin(DBPLitElement) {
constructor() {
super();
this.lang = 'de';
this._i18n = createInstance();
this.lang = this._i18n.language;
this.entryPointUrl = '';
this.noAuth = false;
}
......@@ -100,7 +101,7 @@ export class DataTableViewDemo extends ScopedElementsMixin(DBPLitElement) {
update(changedProperties) {
changedProperties.forEach((oldValue, propName) => {
if (propName === "lang") {
i18n.changeLanguage(this.lang);
this._i18n.changeLanguage(this.lang);
}
});
......
import i18next from 'i18next';
import {createInstance as _createInstance} from '@dbp-toolkit/common/i18next.js';
import de from './i18n/de/translation.json';
import en from './i18n/en/translation.json';
const i18n = i18next.createInstance();
i18n.init({
lng: 'de',
fallbackLng: ['de'],
debug: false,
initImmediate: false, // Don't init async
resources: {
en: {translation: en},
de: {translation: de}
},
});
console.assert(i18n.isInitialized);
function dateTimeFormat(date, options) {
return new Intl.DateTimeFormat(i18n.languages, options).format(date);
}
function numberFormat(number, options) {
return new Intl.NumberFormat(i18n.languages, options).format(number);
}
export {i18n, dateTimeFormat, numberFormat};
export function createInstance() {
return _createInstance({en: en, de: de}, 'de', 'en');
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment