Skip to content

Commit 50d9451

Browse files
committed
more reliable text replacing using jsdom
1 parent 97f026e commit 50d9451

File tree

3 files changed

+406
-10
lines changed

3 files changed

+406
-10
lines changed

bin/scriptimate.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const svgDim = require('svg-dimensions');
88
const YAML = require('yaml');
99
const crypto = require('crypto');
1010
const os = require('os');
11+
const jsdom = require("jsdom");
12+
const { JSDOM } = jsdom;
1113

1214
let uniq;
1315

@@ -43,8 +45,6 @@ parser.add_argument('-ijq', '--intermediateJpegQuality', { help: 'JPEG quality 0
4345
parser.add_argument('-nc', '--nocache', { help: "Don't use screenshots cache (but still generate it), for scriptimate develeopmnt", default: false });
4446

4547

46-
47-
4848
const proc_args = parser.parse_args();
4949

5050
const FPS = +proc_args.fps;
@@ -325,12 +325,13 @@ const addPart = async (lang, filename, left, top, opacity, scale, toBoxHole, das
325325
});
326326
if (lang !== 'default') {
327327
const strings = translationsDict[lang];
328-
Object.keys(strings).forEach((tr) => {
329-
withUniquifiedIDs = withUniquifiedIDs.replace(new RegExp(`>(.+?)${tr}(.+?)<`, 'g'), (_, v1, v2) => {
330-
return `>${v1}${strings[tr]}${v2}<`;
331-
});
332-
// withUniquifiedIDs = withUniquifiedIDs.replaceAll(tr, strings[tr]);
333-
});
328+
const dom = new JSDOM(withUniquifiedIDs);
329+
for ( let e of dom.window.document.querySelectorAll("tspan") ) {
330+
for (let tr of Object.keys(strings)) {
331+
e.innerHTML = e.innerHTML.replaceAll(tr, strings[tr]);
332+
};
333+
}
334+
withUniquifiedIDs = dom.window.document.querySelector('html').innerHTML;
334335
}
335336
parts[filename] = {
336337
type: 'part',

0 commit comments

Comments
 (0)