Removing jQuery altogether
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
export default class Lang {
|
||||
|
||||
constructor({ translations = {}, prefix = '' } = {}) {
|
||||
this.translations = translations;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
lang(key = '', params = []) {
|
||||
if(key === '') return '';
|
||||
|
||||
const normalizedParams = Array.isArray(params) ? params : [params];
|
||||
|
||||
if(Object.prototype.hasOwnProperty.call(this.translations, key)) {
|
||||
let text = this.translations[key];
|
||||
normalizedParams.forEach((param, index) => {
|
||||
text = text.replace('$' + index, param);
|
||||
});
|
||||
return text;
|
||||
}
|
||||
|
||||
console.warn('Missing translation:', key);
|
||||
return key;
|
||||
}
|
||||
|
||||
parse(message = '') {
|
||||
if(this.prefix && typeof message === 'string' && message.startsWith(this.prefix)) {
|
||||
return this.lang(message.slice(this.prefix.length));
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user