I'm working on a translation mod that currently updates text using the .modinfo file like this:
Now, I want to implement mod settings to conditionally update certain text entries (a single .xml file) based on a setting value. Specifically, I aim to transfer the update text logic to JavaScript to check whether a variable is set to true before applying changes.
Here’s what I have so far:
However, I'm not sure if this is the right approach.
Code:
<UpdateText>
<Item locale="ko_KR">l10n/NAMECHANGE.xml</Item>
...
</UpdateText>
Now, I want to implement mod settings to conditionally update certain text entries (a single .xml file) based on a setting value. Specifically, I aim to transfer the update text logic to JavaScript to check whether a variable is set to true before applying changes.
Here’s what I have so far:
Code:
import MKGAOptions from '/make-korean-great-again/ui/options/make-korean-great-again-options.js';
// MKGAOptions.enableNameChange is the boolean to be checked
function applyNameChangeXML() {
if (!MKGAOptions.enableNameChange) return;
fetch('/make-korean-great-again/l10n/NAMECHANGE.xml')
.then(res => res.text())
.then(xmlString => {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlString, "application/xml");
const replaces = xmlDoc.getElementsByTagName("Replace");
for (let replace of replaces) {
const tag = replace.getAttribute("Tag");
const newText = replace.getElementsByTagName("Text")[0]?.textContent;
if (tag && newText) {
const el = document.querySelector(`[data-tag="${tag}"]`);
if (el) el.textContent = newText;
}
}
})
.catch(err => console.error("Failed to apply NAMECHANGE.xml", err));
}
document.addEventListener("DOMContentLoaded", applyNameChangeXML);
However, I'm not sure if this is the right approach.
- Is there a standard way to conditionally update text through JavaScript in a mod?
- Can a .modinfo file include conditional logic based on a variable, or is JavaScript the best way to handle this?