Update kick.js

This commit is contained in:
Yaode_owo 2024-10-18 15:04:45 -04:00
parent a534bed88e
commit 063291c3e2

46
kick.js
View file

@ -88,23 +88,53 @@ function kickparser(component) {
if (comp.translate) {
let translateString = lang[comp.translate] || comp.translate;
let DefaultTranslateString = lang[comp.translate] || comp.translate;
let DefaultMsg = false;
if (comp.with) {
const withArgs = comp.with.map(arg => kickparserText(arg));
const withArgs = comp.with.map(arg => extractText(arg));
let usedReplacements = 0;
translateString = translateString.replace(/%s/g, () => {
if (usedReplacements < withArgs.length) {
return withArgs[usedReplacements++];
translateString = translateString.replace(/%s/g, (match, offset, string) => {
if (offset > 0 && string[offset - 1] === '%') {
return 's';
}
if (usedReplacements < withArgs.length) {
const formattedArg = withArgs[usedReplacements];
if (translateString.length + formattedArg.length > 2048) return 'Translate Crash';
usedReplacements++;
return formattedArg;
}
DefaultMsg = true;
return "%s";
});
withArgs.forEach((arg, index) => {
const regex = new RegExp(`%${index + 1}\\$s`, 'g');
translateString = translateString.replace(regex, arg);
translateString = translateString.replace(/%(\d+)\$s/g, (match, index, stringindex, string) => {
const argIndex = parseInt(index) - 1;
if (argIndex >= withArgs.length) {
DefaultMsg = true;
return match;
}
if (stringindex > 0 && string[stringindex - 1] === '%') {
return match;
}
const formattedArg = withArgs[argIndex];
if (translateString.length + formattedArg.length > 2048) return 'Translate Crash';
return formattedArg;
});
}
text += translateString;
if (DefaultMsg) {
text += DefaultTranslateString;
} else {
text += translateString;
}
}