Last active
December 16, 2018 04:43
-
-
Save PROPHESSOR/dc355267380ac74e0828652d011382f5 to your computer and use it in GitHub Desktop.
Doom 3 GUI text deparser (translation patch applier)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Doom 3 GUI text deparser (translation patch applier) | |
* | |
* Copyright (c) PROPHESSOR 05.12.2018 | |
* MIT License | |
* | |
*/ | |
const fs = require('fs'); | |
const EXPORT_DIR = 'export'; | |
function deparse(json, filename) { | |
let gui = fs.readFileSync(filename, 'utf8'); | |
for(const string of json) { | |
// [0] - filename, [1] - input string, [2] - array { [0] - translation, [1] - translator, [2] - rating, [3] - comment}, [3] - checkers | |
string[2].sort((a, b) => (b[2] || 0) - (a[2] || 0)); | |
const bestTranslation = string[2][0][0]; | |
gui = gui.replace(`"${string[1]}"`, `"${bestTranslation}"`); | |
} | |
fs.writeFileSync(`${EXPORT_DIR}/${filename}`, gui.replace(/я/g, '`').replace(/ё/g, 'е').replace(/Ё/g, 'Е'), 'utf8'); | |
} | |
const filelist = [ | |
// Put here pathes to .gui files | |
// NOTE: Translated .gui.json files must be in same folder | |
] | |
function main() { | |
for(const filename of filelist) { | |
deparse(require(`./${filename}.json`), filename); | |
console.log(filename, 'OK'); | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment