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

Enable namespaces for Translation component

parent a104587c
No related branches found
No related tags found
No related merge requests found
......@@ -7,25 +7,27 @@ export function createInstance() {
return _createInstance({en: en, de: de}, 'de', 'en');
}
export async function createInstanceAsync(langFile) {
export async function createInstanceAsync(langFile, namespace) {
if (namespace == undefined)
namespace = 'translation'
// check if a path to language files is given
if(langFile) {
// request german lang file asynchronously
let result = await
fetch(langFile + 'de/translation.json', {
fetch(langFile + 'de/' + namespace +'.json', {
headers: {'Content-Type': 'application/json'},
});
const dynDe = await result.json();
// request english lang file asynchronously
result = await
fetch(langFile + 'en/translation.json', {
fetch(langFile + 'en/' + namespace + '.json', {
headers: {'Content-Type': 'application/json'},
});
const dynEn = await result.json();
return _createInstance({en: dynEn, de: dynDe}, 'de', 'en');
return _createInstance({en: dynEn, de: dynDe}, 'de', 'en', namespace);
}
return _createInstance({en: en, de: de}, 'de', 'en');
return _createInstance({en: en, de: de}, 'de', 'en', namespace);
}
......@@ -11,6 +11,7 @@ export class Translation extends DBPLitElement {
this.lang = '';
this.langFiles = '';
this.interpolation = '';
this.namespace = '';
}
static get properties() {
......@@ -21,6 +22,7 @@ export class Translation extends DBPLitElement {
langFiles: {type: String, attribute: 'lang-files'},
interpolation: {type: Object, attribute: 'var'},
unsafe: {type: Boolean, attribute: 'unsafe'},
namespace: {type: String, attribute: 'ns'},
};
}
......@@ -35,7 +37,11 @@ export class Translation extends DBPLitElement {
connectedCallback() {
super.connectedCallback();
this._i18n = createInstanceAsync(this.langFiles);
if (this.namespace == '')
this._i18n = createInstanceAsync(this.langFiles);
else {
this._i18n = createInstanceAsync(this.langFiles, this.namespace);
}
}
update(changedProperties) {
......
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