Skip to content

Instantly share code, notes, and snippets.

@fabjan
Created June 26, 2023 13:28
Show Gist options
  • Save fabjan/dce35b21bd417179b59232d977c74887 to your computer and use it in GitHub Desktop.
Save fabjan/dce35b21bd417179b59232d977c74887 to your computer and use it in GitHub Desktop.
one-off script for presenting opengoal translation changes in a readable, navigable HTML format
#! /usr/bin/env -S deno run --allow-read --allow-run
// This script is used to generate a diff between the local version
// translation and the master version of the subtitles, together with
// the english version.
//
// It can be used to generate an html file for easier review of changes
// with a screen reader.
//
// Usage: dumpdiff.js <game> <locale>
//
// Example: dumpdiff.js jak1 sv-SE > diff.html
//
// For each section (cutscenes, hints, speakers), the script will output
// a heading, followed by a list of all changes. Unchanged subsections
// (e.g. a cutscene) will not be shown.
const game = Deno.args[0];
const locale = Deno.args[1];
if (!game || !locale) {
console.log("Usage: dumpdiff.js <game> <locale>");
Deno.exit(1);
}
const locFile = `game/assets/${game}/subtitle/subtitle_lines_${locale}.json`;
const engFile = `game/assets/${game}/subtitle/subtitle_lines_en-US.json`;
const afterJSON = await Deno.readTextFile(locFile);
const englishJSON = await Deno.readTextFile(engFile);
const beforeJSON = await Deno.run({cmd: ["git", "show", `master:${locFile}`], stdout: "piped"}).output();
const before = JSON.parse(new TextDecoder().decode(beforeJSON));
const after = JSON.parse(afterJSON);
const english = JSON.parse(englishJSON);
const sections = [
"cutscenes",
"hints",
"speakers",
];
function showSection(file, section, key) {
if (section == "speakers") {
console.log(`<p>${file[section][key]}</p>`);
return;
}
for (const line of file[section][key]) {
console.log(`<p>${line}</p>`);
}
}
console.log("<html>");
console.log("<head>");
console.log("<meta charset=\"utf-8\">");
console.log("</head>");
console.log("<body>");
for (const section of sections) {
console.log(`<h1>${section}</h1>`);
const numSubSections = Object.keys(before[section]).length;
let subsection = 0;
for (const key in before[section]) {
if (JSON.stringify(before[section][key]) != JSON.stringify(after[section][key])) {
subsection++;
const linecount = before[section][key];
console.log(`<h2>${key}, dialogue ${subsection} of ${numSubSections}, ${linecount.length} lines</h2>`);
console.log(`<h3>before</h3>`);
showSection(before, section, key);
console.log(`<h3>after</h3>`);
showSection(after, section, key);
console.log(`<h3>english</h3>`);
showSection(english, section, key);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment