fix translate fallback

This commit is contained in:
Yaode_owo 2024-10-30 22:08:48 -04:00
parent 8d091e9127
commit e4c8ae6ce6

View file

@ -1,7 +1,7 @@
// Don't change this or you gay. // Don't change this or you gay.
// Version: 1.0 // Version: 1.1
const lang = require("./en_us.json"); // translate message const lang = require("../util/en_us.json"); // translate message
function uuidFromIntArray (arr) { function uuidFromIntArray (arr) {
const buf = Buffer.alloc(16) const buf = Buffer.alloc(16)
@ -283,12 +283,13 @@ function parseMinecraftMessage(component) {
} }
if (comp.translate) { if (comp.translate) {
if (comp.fallback && !lang[comp.translate]) return text += formatfunction(comp, comp.fallback);
let translateString = lang[comp.translate] || comp.translate; let translateString = lang[comp.translate] || comp.translate;
let DefaultTranslateString = lang[comp.translate] || comp.translate; let DefaultTranslateString = lang[comp.translate] || comp.translate;
let DefaultMsg = false; let DefaultMsg = false;
let fallbackMsg = false;
if (comp.fallback && !lang[comp.translate]) fallbackMsg = true;
if (comp.with) { if (comp.with && !fallbackMsg) {
const withArgs = comp.with.map(arg => extractText(arg)); const withArgs = comp.with.map(arg => extractText(arg));
let usedReplacements = 0; let usedReplacements = 0;
translateString = translateString.replace(/thing__placeholder__/g, 'default_thing__placeholder__'); translateString = translateString.replace(/thing__placeholder__/g, 'default_thing__placeholder__');
@ -334,6 +335,8 @@ function parseMinecraftMessage(component) {
if (DefaultMsg) { if (DefaultMsg) {
text += formatfunction(comp, DefaultTranslateString); text += formatfunction(comp, DefaultTranslateString);
} else if (fallbackMsg) {
text += formatfunction(comp, comp.fallback);
} else { } else {
text += formatfunction(comp, translateString); text += formatfunction(comp, translateString);
} }
@ -346,9 +349,7 @@ function parseMinecraftMessage(component) {
}); });
} }
text = parseMinecraftColor(comp.color) + parseMinecraftFormat(comp) + text + ansiFormatCodes['reset']; return parseMinecraftColor(comp.color) + parseMinecraftFormat(comp) + text + ansiFormatCodes['reset'];
return text;
} }
return extractText(component) + ansiFormatCodes['reset']; return extractText(component) + ansiFormatCodes['reset'];
@ -372,12 +373,13 @@ function parseMinecraftMessageNoColor(component) {
} }
if (comp.translate) { if (comp.translate) {
if (comp.fallback && !lang[comp.translate]) return text += comp.fallback;
let translateString = lang[comp.translate] || comp.translate; let translateString = lang[comp.translate] || comp.translate;
let DefaultTranslateString = lang[comp.translate] || comp.translate; let DefaultTranslateString = lang[comp.translate] || comp.translate;
let DefaultMsg = false; let DefaultMsg = false;
let fallbackMsg = false;
if (comp.fallback && !lang[comp.translate]) fallbackMsg = true;
if (comp.with) { if (comp.with && !fallbackMsg) {
const withArgs = comp.with.map(arg => extractText(arg)); const withArgs = comp.with.map(arg => extractText(arg));
let usedReplacements = 0; let usedReplacements = 0;
@ -424,6 +426,8 @@ function parseMinecraftMessageNoColor(component) {
if (DefaultMsg) { if (DefaultMsg) {
text += DefaultTranslateString; text += DefaultTranslateString;
} else if (fallbackMsg) {
text += comp.fallback;
} else { } else {
text += translateString; text += translateString;
} }