add i18n for console logs

This commit is contained in:
ari melody 2025-07-13 20:44:54 +01:00
parent b170a532f6
commit 7752585488
Signed by: ari
GPG key ID: CF99829C92678188
14 changed files with 77 additions and 31 deletions

View file

@ -19,7 +19,7 @@ export default function init(lang) {
i18n.lang = language;
i18n.lang_code = lang;
i18n.string = function(/* @type string */ key) {
i18n.string = function(/* @type string */ key, ...args) {
const tokens = key.split('.');
let i = 0;
@ -32,10 +32,20 @@ export default function init(lang) {
return key;
}
if (typeof res === 'string' || res instanceof String)
return res;
break;
i++;
token = tokens[i];
}
i = 1;
while (true) {
if (args.length < i || !res.includes('%' + i))
break;
res = res.replaceAll('%' + i, args[i - 1]);
i++;
}
return res;
}
i18n.stringArray = function(/* @type string */ key) {
const tokens = key.split('.');