Skip to content
Snippets Groups Projects
Commit d9a92748 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Script that can load additional ctrl/text.*.ini (or .json) text override files

e.g. as a logon script "?replace_text es" would replace strings from
ctrl/text.es.ini (for Spanish translations)

This is not really to be used to load ctrl/text.ini since that is support is
built in (in load_cfg.c) and not necessary to be done in JS.
parent 11418c07
Branches
Tags
1 merge request!455Update branch with changes from master
// Performs text.dat string replacements from ctrl/text.*.ini and/or ctrl/text.*.json
// one or more replacement files must be passed on the command-line in the form:
// ctrl/text.<arg>.ini or ctrl/text.<arg>.json
/*** example text.json:
{
"On": "En",
"Off": "Apagado",
"Yes": "Si",
"None": "Nada",
"All": "Todo",
"Only": "Solamente",
"Unlimited": "ilimitado",
"Scanning": "Escaneo",
"Done": "Hecho",
}
******************************************/
/*** example text.ini (quotes are optional, CP437 encoded):
On: Auf
Off: Aus
Yes: Ja
None: Nichts
All: Alle
Only: Nur
Unlimited: unbergrenzt
Scanning: Abtastung
Done: Fertig
******************************************/
const text = require('text.js', 'TOTAL_TEXT');
"use strict";
function replace_text(fname) {
const ext = file_getext(fname).toLowerCase();
if(ext != ".ini" && ext != ".json") {
if(file_exists(fname + ".ini"))
return replace_text(fname + ".ini")
if(file_exists(fname + ".json"))
return replace_text(fname + ".json");
throw new Error("Filename does not exist: " + fname);
}
const file = new File(fname);
if(!file.open('r'))
throw new Error("Error " + file.error + " opening " + file.name);
var obj;
if(ext == ".ini")
obj = file.iniGetObject();
else if(ext == ".json")
obj = JSON.parse(file.readAll().join("\n"));
file.close();
for(var i in obj) {
if(!bbs.replace_text(text[i], obj[i]))
throw new Error(format('Failed to replace string (%s = %s)', i, text[i]));
}
return true;
}
for(var i in argv)
replace_text(system.ctrl_dir + "text." + argv[i]);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment