语言路径修复
This commit is contained in:
1 parent
2beb78e255
commit
f0f292d2d8
4 files changed
+14
-4
No files matched your search
@@ -323,7 +323,9 @@
|
|||||||
|
|
||||||
function readLocaleFile(code) {
|
function readLocaleFile(code) {
|
||||||
try {
|
try {
|
||||||
const file = path.join(__dirname, '..', '_locales', code + '.json');
|
// Eagle 页面中的 __dirname 不一定等于 viewer 目录,使用实际模块路径定位。
|
||||||
|
const pluginRoot = path.dirname(path.dirname(require.resolve('../js/spine-utils.js')));
|
||||||
|
const file = path.join(pluginRoot, '_locales', code + '.json');
|
||||||
const data = JSON.parse(fs.readFileSync(file, 'utf8'));
|
const data = JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||||
return (data && typeof data === 'object') ? data : {};
|
return (data && typeof data === 'object') ? data : {};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -323,7 +323,9 @@
|
|||||||
|
|
||||||
function readLocaleFile(code) {
|
function readLocaleFile(code) {
|
||||||
try {
|
try {
|
||||||
const file = path.join(__dirname, '..', '_locales', code + '.json');
|
// Eagle 页面中的 __dirname 不一定等于 viewer 目录,使用实际模块路径定位。
|
||||||
|
const pluginRoot = path.dirname(path.dirname(require.resolve('../js/spine-utils.js')));
|
||||||
|
const file = path.join(pluginRoot, '_locales', code + '.json');
|
||||||
const data = JSON.parse(fs.readFileSync(file, 'utf8'));
|
const data = JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||||
return (data && typeof data === 'object') ? data : {};
|
return (data && typeof data === 'object') ? data : {};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ const assert = require('node:assert/strict');
|
|||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const vm = require('node:vm');
|
const vm = require('node:vm');
|
||||||
|
const { createRequire } = require('node:module');
|
||||||
const roots = ['.', 'release/MAC_arm64_SpineViewer', 'release/WIN_x64_SpineViewer'];
|
const roots = ['.', 'release/MAC_arm64_SpineViewer', 'release/WIN_x64_SpineViewer'];
|
||||||
for (const root of roots) {
|
for (const root of roots) {
|
||||||
const html = fs.readFileSync(path.join(root, 'viewer/spine.html'), 'utf8');
|
const html = fs.readFileSync(path.join(root, 'viewer/spine.html'), 'utf8');
|
||||||
@@ -18,7 +19,9 @@ for (const root of roots) {
|
|||||||
}
|
}
|
||||||
const children = [];
|
const children = [];
|
||||||
const context = vm.createContext({
|
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; } }) },
|
document: { documentElement: {}, createElement: () => ({ style: {}, setAttribute(key, value) { this[key] = value; } }) },
|
||||||
keyframesEl: { innerHTML: '', appendChild: el => children.push(el) },
|
keyframesEl: { innerHTML: '', appendChild: el => children.push(el) },
|
||||||
isStaticAnimation: false, duration: 2,
|
isStaticAnimation: false, duration: 2,
|
||||||
@@ -26,6 +29,7 @@ for (const root of roots) {
|
|||||||
formatSeconds: value => `${value}s`, frameOf: value => value * 30
|
formatSeconds: value => `${value}s`, frameOf: value => value * 30
|
||||||
});
|
});
|
||||||
vm.runInContext(i18n + '\n' + markers + '\nrenderKeyframeMarkers({});', context);
|
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.length, 3);
|
||||||
assert.equal(children[1].style.left, '50%');
|
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].title, table.viewer.keyframeTitle.replace('{time}', '1s').replace('{frame}', '30'));
|
||||||
|
|||||||
+3
-1
@@ -323,7 +323,9 @@
|
|||||||
|
|
||||||
function readLocaleFile(code) {
|
function readLocaleFile(code) {
|
||||||
try {
|
try {
|
||||||
const file = path.join(__dirname, '..', '_locales', code + '.json');
|
// Eagle 页面中的 __dirname 不一定等于 viewer 目录,使用实际模块路径定位。
|
||||||
|
const pluginRoot = path.dirname(path.dirname(require.resolve('../js/spine-utils.js')));
|
||||||
|
const file = path.join(pluginRoot, '_locales', code + '.json');
|
||||||
const data = JSON.parse(fs.readFileSync(file, 'utf8'));
|
const data = JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||||
return (data && typeof data === 'object') ? data : {};
|
return (data && typeof data === 'object') ? data : {};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in new issue
Block a user