25 lines
595 B
JavaScript
25 lines
595 B
JavaScript
export default class Lang {
|
|
|
|
constructor({ translations = {}, prefix = '' } = {}) {
|
|
this.translations = translations;
|
|
this.prefix = prefix;
|
|
}
|
|
|
|
get(sLangId = '', params = []) {
|
|
if(sLangId === '') return '';
|
|
|
|
const normalizedParams = Array.isArray(params) ? params : [params];
|
|
|
|
if(Object.prototype.hasOwnProperty.call(this.translations, sLangId)) {
|
|
let text = this.translations[sLangId];
|
|
normalizedParams.forEach((param, index) => {
|
|
text = text.replace('$' + index, param);
|
|
});
|
|
return text;
|
|
}
|
|
|
|
console.warn('Missing translation:', sLangId);
|
|
return sLangId;
|
|
}
|
|
}
|