From 7559a8b41bb4ec4984899fa4f9ab12fb39e55889 Mon Sep 17 00:00:00 2001 From: Manuel Kocher <manuel.kocher@tugraz.at> Date: Mon, 11 Jul 2022 15:55:14 +0200 Subject: [PATCH] Remove local translation overrides since it became redundant, update translation.json files --- packages/common/src/translation.js | 28 ++++--------------- packages/theme-switcher/src/theme-switcher.js | 13 +++------ .../translation-overrides/de/translation.json | 2 +- .../translation-overrides/en/translation.json | 2 +- 4 files changed, 12 insertions(+), 33 deletions(-) diff --git a/packages/common/src/translation.js b/packages/common/src/translation.js index ebf230a7..9e6bb5f8 100644 --- a/packages/common/src/translation.js +++ b/packages/common/src/translation.js @@ -10,7 +10,6 @@ export class Translation extends DBPLitElement { this.key = ''; this.lang = ''; this.interpolation = ''; - this.langDir = ''; this.unsafe = false; } @@ -21,47 +20,32 @@ export class Translation extends DBPLitElement { lang: {type: String}, interpolation: {type: Object, attribute: 'var'}, unsafe: {type: Boolean, attribute: 'unsafe'}, - langDir: {type: String, attribute: 'lang-dir'}, }; } static get styles() { // language=css return [ - commonStyles.getThemeCSS(), commonStyles.getGeneralCSS(), - css` - .hidden { - display: none; - } - .links { - border-bottom: var(--dbp-border); - border-color: var(--dbp-content); - padding: 0; - transition: background-color 0.15s ease 0s, color 0.15s ease 0s; - color: var(--dbp-content); - cursor: pointer; - text-decoration: none; - } - `, + commonStyles.getLinkCss(), ]; } connectedCallback() { - super.connectedCallback(); + // init objects with empty string as value for key const de = {}; const en = {}; de[this.key] = ""; en[this.key] = ""; - // create i18n instance with given translations + // create i18n instance with empty translations as default this._i18n = createInstanceGivenResources(en, de); - if (this.langDir) { - setOverridesByGlobalCache(this._i18n, this); - } + // supercall after default i18n init to override translations only + // if a override with this tagname is given + super.connectedCallback(); } update(changedProperties) { diff --git a/packages/theme-switcher/src/theme-switcher.js b/packages/theme-switcher/src/theme-switcher.js index fc2dd982..4d7374e9 100644 --- a/packages/theme-switcher/src/theme-switcher.js +++ b/packages/theme-switcher/src/theme-switcher.js @@ -1,4 +1,4 @@ -import {createInstance, setOverridesByGlobalCache} from './i18n.js'; +import {createInstance} from './i18n.js'; import {html, css} from 'lit'; import {ScopedElementsMixin} from '@open-wc/scoped-elements'; import {AdapterLitElement, Icon} from '@dbp-toolkit/common'; @@ -15,7 +15,6 @@ export class ThemeSwitcher extends ScopedElementsMixin(AdapterLitElement) { this.boundCloseAdditionalMenuHandler = this.hideModeMenu.bind(this); this.detectBrowserDarkMode = false; this.darkModeClass = 'dark-theme'; - this.langDir = ''; this.dropdownRight = false; } @@ -26,7 +25,6 @@ export class ThemeSwitcher extends ScopedElementsMixin(AdapterLitElement) { themes: {type: Array, attribute: 'themes'}, darkModeThemeOverride: {type: String, attribute: 'dark-mode-theme-override'}, dropdownRight: {type: Boolean, attribute: 'dropdown-right'}, - langDir: {type: String, attribute: 'lang-dir'}, }; } @@ -59,9 +57,6 @@ export class ThemeSwitcher extends ScopedElementsMixin(AdapterLitElement) { this.loadTheme('light-theme'); this.detectInitialMode(); }); - if (this.langDir) { - setOverridesByGlobalCache(this._i18n, this); - } } detectInitialMode() { @@ -225,12 +220,12 @@ export class ThemeSwitcher extends ScopedElementsMixin(AdapterLitElement) { .icon { margin-right: 10px; } - + #theme-menu{ position: relative; } - - + + .ul-right{ right: 0px; }; diff --git a/toolkit-showcase/assets/translation-overrides/de/translation.json b/toolkit-showcase/assets/translation-overrides/de/translation.json index 5a89e9d1..727ad091 100644 --- a/toolkit-showcase/assets/translation-overrides/de/translation.json +++ b/toolkit-showcase/assets/translation-overrides/de/translation.json @@ -1,7 +1,7 @@ { "dbp-translation": { "toolkit-showcase": "Dieser Text wird mithilfe von i18n aus einer benutzerdefinierten Sprachdatei gelesen und ins Englische übersetzt wenn man die Sprache auf Englisch stellt.", - "toolkit-showcase-link": "Es können sogar links mittels <a href=\"{{- link1}}\" class=\"links\">interpolation</a> und escaping dargestellt werden.", + "toolkit-showcase-link": "Es können sogar links mittels <a href=\"{{- link1}}\" class=\"link\">interpolation</a> und escaping dargestellt werden.", "color-mode": "Sollte nicht angezeigt werden. Dieser Text ist nur als test vorhanden.", "intro": "Sollte nicht angezeigt werden. Dieser Text ist nur als test vorhanden." }, diff --git a/toolkit-showcase/assets/translation-overrides/en/translation.json b/toolkit-showcase/assets/translation-overrides/en/translation.json index fa7eaaa9..ac573073 100644 --- a/toolkit-showcase/assets/translation-overrides/en/translation.json +++ b/toolkit-showcase/assets/translation-overrides/en/translation.json @@ -1,7 +1,7 @@ { "dbp-translation": { "toolkit-showcase": "This text will be translated to german using i18n with a user defined language file when the language is changed to german.", - "toolkit-showcase-link": "Furthermore its possible to display links through <a href=\"{{- link1}}\" class=\"links\">interpolation</a> and escaping.", + "toolkit-showcase-link": "Furthermore its possible to display links through <a href=\"{{- link1}}\" class=\"link\">interpolation</a> and escaping.", "color-mode": "This text is not supposed to be displayed. It is only here for testing.", "intro": "This text is not supposed to be displayed. It is only here for testing." }, -- GitLab