语言路径修复

This commit is contained in:
tianmo committed 2026-09-11 22:48:12 +08:00
1 parent 2beb78e255
commit f0f292d2d8
4 files changed
+14 -4

No files matched your search

+5 -1
View File
@@ -3,6 +3,7 @@ const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const { createRequire } = require('node:module');
const roots = ['.', 'release/MAC_arm64_SpineViewer', 'release/WIN_x64_SpineViewer'];
for (const root of roots) {
const html = fs.readFileSync(path.join(root, 'viewer/spine.html'), 'utf8');
@@ -18,7 +19,9 @@ for (const root of roots) {
}
const children = [];
const context = vm.createContext({
require, path, fs, __dirname: path.resolve(root, 'viewer'), lang, log() {},
require: createRequire(path.resolve(root, 'viewer/spine.html')), path, fs,
// Simulate Eagle supplying a different directory than the HTML page.
__dirname: path.resolve(root, 'viewer/runtime'), lang, log() {},
document: { documentElement: {}, createElement: () => ({ style: {}, setAttribute(key, value) { this[key] = value; } }) },
keyframesEl: { innerHTML: '', appendChild: el => children.push(el) },
isStaticAnimation: false, duration: 2,
@@ -26,6 +29,7 @@ for (const root of roots) {
formatSeconds: value => `${value}s`, frameOf: value => value * 30
});
vm.runInContext(i18n + '\n' + markers + '\nrenderKeyframeMarkers({});', context);
assert.equal(vm.runInContext("t('viewer.skin')", context), table.viewer.skin);
assert.equal(children.length, 3);
assert.equal(children[1].style.left, '50%');
assert.equal(children[1].title, table.viewer.keyframeTitle.replace('{time}', '1s').replace('{frame}', '30'));