Skip to content
Snippets Groups Projects
Commit 088dc52c authored by Kocher, Manuel's avatar Kocher, Manuel
Browse files

Add support of unsafe translation file rendering

parent 55948ae1
No related branches found
No related tags found
No related merge requests found
import {css, html} from 'lit'; import {css, html} from 'lit';
import {until} from 'lit/directives/until.js'; import {until} from 'lit/directives/until.js';
import {unsafeHTML} from 'lit/directives/unsafe-html.js';
import DBPLitElement from '../dbp-lit-element'; import DBPLitElement from '../dbp-lit-element';
import {createInstanceAsync} from './i18n.js'; import {createInstanceAsync} from './i18n.js';
...@@ -19,6 +20,7 @@ export class Translation extends DBPLitElement { ...@@ -19,6 +20,7 @@ export class Translation extends DBPLitElement {
lang: {type: String}, lang: {type: String},
langFiles: {type: String, attribute: 'lang-files'}, langFiles: {type: String, attribute: 'lang-files'},
interpolation: {type: Object, attribute: 'var'}, interpolation: {type: Object, attribute: 'var'},
unsafe: {type: Boolean, attribute: 'unsafe'},
}; };
} }
...@@ -55,10 +57,13 @@ export class Translation extends DBPLitElement { ...@@ -55,10 +57,13 @@ export class Translation extends DBPLitElement {
// save global key in local variable for async use // save global key in local variable for async use
let key = this.key; let key = this.key;
let interpolation = this.interpolation; let interpolation = this.interpolation;
let unsafe = this.unsafe;
// async request to i18n translation // async request to i18n translation
const translation = this._i18n.then(function(response){ const translation = this._i18n.then(function(response){
if (interpolation) if (interpolation && unsafe)
return unsafeHTML(response.t(key, interpolation));
else if (interpolation)
return response.t(key, interpolation); return response.t(key, interpolation);
else else
return response.t(key); return response.t(key);
...@@ -66,7 +71,7 @@ export class Translation extends DBPLitElement { ...@@ -66,7 +71,7 @@ export class Translation extends DBPLitElement {
// load translation text when available, otherwise display "Loading.." // load translation text when available, otherwise display "Loading.."
return html` return html`
${until(translation, html`<span>Loading..</span>`)} ${until(translation, html`Loading..`)}
`; `;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment