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

checkin-place-select: port to one i18next instance per component instance

parent 8b653471
No related branches found
No related tags found
No related merge requests found
Pipeline #45037 failed
...@@ -6,6 +6,7 @@ module.exports = { ...@@ -6,6 +6,7 @@ module.exports = {
options: { options: {
debug: false, debug: false,
removeUnusedKeys: true, removeUnusedKeys: true,
func: {list: ['i18n.t', '_i18n.t']},
lngs: ['en','de'], lngs: ['en','de'],
resource: { resource: {
loadPath: 'src/i18n/{{lng}}/{{ns}}.json', loadPath: 'src/i18n/{{lng}}/{{ns}}.json',
......
...@@ -4,7 +4,7 @@ import select2LangEn from './i18n/en/select2'; ...@@ -4,7 +4,7 @@ import select2LangEn from './i18n/en/select2';
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 {ScopedElementsMixin} from '@open-wc/scoped-elements'; import {ScopedElementsMixin} from '@open-wc/scoped-elements';
import {i18n} from './i18n.js'; import {createInstance} from './i18n.js';
import {Icon} from '@dbp-toolkit/common'; import {Icon} from '@dbp-toolkit/common';
import * as commonUtils from '@dbp-toolkit/common/utils'; import * as commonUtils from '@dbp-toolkit/common/utils';
import * as commonStyles from '@dbp-toolkit/common/styles'; import * as commonStyles from '@dbp-toolkit/common/styles';
...@@ -41,6 +41,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) { ...@@ -41,6 +41,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) {
this.reloadButtonTitle = ''; this.reloadButtonTitle = '';
this.showCapacity = false; this.showCapacity = false;
this.auth = {}; this.auth = {};
this._i18n = createInstance();
this._onDocumentClicked = this._onDocumentClicked.bind(this); this._onDocumentClicked = this._onDocumentClicked.bind(this);
} }
...@@ -159,7 +160,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) { ...@@ -159,7 +160,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) {
width: '100%', width: '100%',
language: this.lang === "de" ? select2LangDe() : select2LangEn(), language: this.lang === "de" ? select2LangDe() : select2LangEn(),
minimumInputLength: 2, minimumInputLength: 2,
placeholder: i18n.t('check-in-place-select.placeholder'), placeholder: this._i18n.t('check-in-place-select.placeholder'),
dropdownParent: this.$('#check-in-place-select-dropdown'), dropdownParent: this.$('#check-in-place-select-dropdown'),
ajax: { ajax: {
delay: 500, delay: 500,
...@@ -291,7 +292,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) { ...@@ -291,7 +292,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) {
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);
if (this.select2IsInitialized()) { if (this.select2IsInitialized()) {
// no other way to set an other language at runtime did work // no other way to set an other language at runtime did work
...@@ -377,6 +378,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) { ...@@ -377,6 +378,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(AdapterLitElement) {
render() { render() {
const select2CSS = commonUtils.getAssetURL(select2CSSPath); const select2CSS = commonUtils.getAssetURL(select2CSSPath);
const i18n = this._i18n;
return html` return html`
<link rel="stylesheet" href="${select2CSS}"> <link rel="stylesheet" href="${select2CSS}">
<style> <style>
......
import {i18n} 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 {CheckInPlaceSelect} from './check-in-place-select.js'; import {CheckInPlaceSelect} from './check-in-place-select.js';
...@@ -34,10 +33,6 @@ export class CheckInPlaceSelectDemo extends ScopedElementsMixin(DBPLitElement) { ...@@ -34,10 +33,6 @@ export class CheckInPlaceSelectDemo extends ScopedElementsMixin(DBPLitElement) {
connectedCallback() { connectedCallback() {
super.connectedCallback(); super.connectedCallback();
i18n.changeLanguage(this.lang);
this.updateComplete.then(()=>{
});
} }
static get styles() { static get styles() {
......
import {createInstance} from '@dbp-toolkit/common/i18next.js'; import {createInstance as _createInstance, setOverrides} 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');
}
export {setOverrides};
\ No newline at end of file
{ {
"check-in-place-select": { "check-in-place-select": {
"placeholder": "Z.B. \"P1\", \"Rechbauerstraße\", \"PZ2EG048\"", "placeholder": "Z.B. \"P1\", \"Rechbauerstraße\", \"PZ2EG048\"",
"error-summary": "Ein Fehler ist aufgetreten",
"login-required": "Anmeldung erforderlich" "login-required": "Anmeldung erforderlich"
} }
} }
{ {
"check-in-place-select": { "check-in-place-select": {
"placeholder": "E.g. \"P1\", \"Rechbauerstraße\", \"PZ2EG048\"", "placeholder": "E.g. \"P1\", \"Rechbauerstraße\", \"PZ2EG048\"",
"error-summary": "An error occurred",
"login-required": "Login required" "login-required": "Login required"
} }
} }
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