Removing jQuery altogether

This commit is contained in:
2026-04-25 19:07:51 +02:00
parent 40565849c5
commit ff4bc26381
12 changed files with 906 additions and 963 deletions
+31
View File
@@ -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;
}
}