How to apply conditional text updates with JavaScript?

Mechuraki

Chieftain
Joined
Apr 27, 2025
Messages
8
I'm working on a translation mod that currently updates text using the .modinfo file like this:
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.
  1. Is there a standard way to conditionally update text through JavaScript in a mod?
  2. Can a .modinfo file include conditional logic based on a variable, or is JavaScript the best way to handle this?
I’m relatively new to modding and would appreciate any guidance or examples. Thanks!
 
I do not believe ther is anyway to change the localization database once you are loaded into the game. I suspect you could before starting a game, using whats called a GameConfiguration setting. I would note this would also not change the values on the frontend before starting a game. You can set a ConfigurationValueMatches in the Modinfo to load different loc files, like presumably different korean translations. Heres an example:
XML:
<ActionCriteria>
        <Criteria id="ramping-difficulty">
            <ConfigurationValueMatches>
                <ConfigurationId>RampingDifficulty</ConfigurationId>
                <Group>Game</Group>
                <Value>1</Value>
            </ConfigurationValueMatches>
    </Criteria>
</ActionCriteria>
<ActionGroups>
<ActionGroup id="slothoth-ramping-difficulty-parameters" scope="shell" criteria="always">
    <Properties>
       <LoadOrder>50</LoadOrder>
    </Properties>
    <Actions>
       <UpdateDatabase>
          <Item>config/parameters.sql</Item>
       </UpdateDatabase>
    </Actions>
</ActionGroup>
</ActionGroups>

And in that config/parameters.sql
SQL:
INSERT INTO Parameters (ParameterID, Name, Description, Domain, Hash, Array, DefaultValue, ConfigurationGroup, ConfigurationKey, GroupID, SortIndex) VALUES
('RampingDifficulty', 'LOC_ADVANCED_OPTIONS_RAMPING_DIFFICULTY', 'LOC_RAMPING_DIFFICULTY_DESC', 'bool', 0, 0, 1, 'Game', 'RampingDifficulty', 'AdvancedOptions', 2080);

That unfortunate example wont show in in the advanced settings of game, as that panel sucks. But underlying it, you could probably add it as an options in another menu? I know its relatively easy to actually change the values in JS:
GameSetup.setGameParameterValue('RampingDifficulty', value.value);
 
Back
Top Bottom