修复多国语言问题

This commit is contained in:
tianmo committed 2026-09-11 22:36:34 +08:00
1 parent f0694431e3
commit fdac18c9cf
4 files changed
+48 -9

No files matched your search

@@ -955,10 +955,10 @@
const maxMarkers = 200;
const step = Math.max(1, Math.ceil(sorted.length / maxMarkers));
for (let i = 0; i < sorted.length; i += step) {
const t = sorted[i];
const keyframeTime = sorted[i];
const span = document.createElement('span');
span.style.left = (duration > 0 ? (t / duration) * 100 : 0) + '%';
span.title = t('viewer.keyframeTitle', { time: formatSeconds(t), frame: frameOf(t) });
span.style.left = (duration > 0 ? (keyframeTime / duration) * 100 : 0) + '%';
span.title = t('viewer.keyframeTitle', { time: formatSeconds(keyframeTime), frame: frameOf(keyframeTime) });
span.setAttribute('aria-label', span.title);
keyframesEl.appendChild(span);
}
@@ -955,10 +955,10 @@
const maxMarkers = 200;
const step = Math.max(1, Math.ceil(sorted.length / maxMarkers));
for (let i = 0; i < sorted.length; i += step) {
const t = sorted[i];
const keyframeTime = sorted[i];
const span = document.createElement('span');
span.style.left = (duration > 0 ? (t / duration) * 100 : 0) + '%';
span.title = t('viewer.keyframeTitle', { time: formatSeconds(t), frame: frameOf(t) });
span.style.left = (duration > 0 ? (keyframeTime / duration) * 100 : 0) + '%';
span.title = t('viewer.keyframeTitle', { time: formatSeconds(keyframeTime), frame: frameOf(keyframeTime) });
span.setAttribute('aria-label', span.title);
keyframesEl.appendChild(span);
}
+39
View File
@@ -0,0 +1,39 @@
'use strict';
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
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');
const script = html.match(/<script>([\s\S]*?)<\/script>/)[1];
new vm.Script(script);
const i18n = script.slice(script.indexOf('\tconst I18N_LANGUAGES'), script.indexOf('\tapplyStaticI18n();'));
const markers = script.slice(script.indexOf('\tfunction renderKeyframeMarkers('), script.indexOf('\tfunction seekTo('));
const manifest = JSON.parse(fs.readFileSync(path.join(root, 'manifest.json'), 'utf8'));
for (const lang of manifest.languages) {
const table = JSON.parse(fs.readFileSync(path.join(root, '_locales', lang + '.json'), 'utf8'));
for (const match of html.matchAll(/(?:\bt\(['"]|data-i18n(?:-title|-aria-label)?=")([^'"]+)/g)) {
assert.equal(typeof match[1].split('.').reduce((obj, key) => obj && obj[key], table), 'string', `${root}/${lang}: ${match[1]}`);
}
const children = [];
const context = vm.createContext({
require, path, fs, __dirname: path.resolve(root, 'viewer'), lang, log() {},
document: { documentElement: {}, createElement: () => ({ style: {}, setAttribute(key, value) { this[key] = value; } }) },
keyframesEl: { innerHTML: '', appendChild: el => children.push(el) },
isStaticAnimation: false, duration: 2,
collectKeyframeTimes: () => [0, 1, 2, 3],
formatSeconds: value => `${value}s`, frameOf: value => value * 30
});
vm.runInContext(i18n + '\n' + markers + '\nrenderKeyframeMarkers({});', context);
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'));
assert.equal(children[1]['aria-label'], children[1].title);
children.length = 0;
context.isStaticAnimation = true;
vm.runInContext('renderKeyframeMarkers({});', context);
assert.equal(children[0].title, table.viewer.staticPoseTitle);
}
}
console.log('PASS: source and both releases; eight languages; animated/static keyframe labels and translation keys');
+3 -3
View File
@@ -955,10 +955,10 @@
const maxMarkers = 200;
const step = Math.max(1, Math.ceil(sorted.length / maxMarkers));
for (let i = 0; i < sorted.length; i += step) {
const t = sorted[i];
const keyframeTime = sorted[i];
const span = document.createElement('span');
span.style.left = (duration > 0 ? (t / duration) * 100 : 0) + '%';
span.title = t('viewer.keyframeTitle', { time: formatSeconds(t), frame: frameOf(t) });
span.style.left = (duration > 0 ? (keyframeTime / duration) * 100 : 0) + '%';
span.title = t('viewer.keyframeTitle', { time: formatSeconds(keyframeTime), frame: frameOf(keyframeTime) });
span.setAttribute('aria-label', span.title);
keyframesEl.appendChild(span);
}