mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-11-01 21:26:08 +08:00
fix(webui): idLabel 识别预编译的 i18n 消息
构建时 unplugin-vue-i18n 把 i18n/*.json 的文案编译成消息函数, idLabel 只认字符串,扩展点、权限与重命名方式在应用里一直显示原始 id。
This commit is contained in:
@@ -1,10 +1,23 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { idLabel } from '../id-label';
|
||||
import en from '@/i18n/en.json';
|
||||
import zhCN from '@/i18n/zh-CN.json';
|
||||
|
||||
const t = (key: string) => `t:${key}`;
|
||||
|
||||
// 应用里 @intlify/unplugin-vue-i18n 把 i18n/*.json 的文案预编译成消息函数,
|
||||
// 这里同样把叶子换成函数,按生产环境的形态测试
|
||||
vi.mock('@/i18n/en.json', async (importOriginal) => {
|
||||
const compile = (node: unknown): unknown =>
|
||||
typeof node === 'string'
|
||||
? () => node
|
||||
: Object.fromEntries(
|
||||
Object.entries(node as object).map(([k, v]) => [k, compile(v)])
|
||||
);
|
||||
const { default: source } = await importOriginal<{ default: object }>();
|
||||
return { default: compile(source) };
|
||||
});
|
||||
|
||||
describe('idLabel', () => {
|
||||
it.each([
|
||||
['config.plugins_set.point_labels', 'downloader', 'downloader'],
|
||||
|
||||
@@ -17,5 +17,6 @@ export function idLabel(
|
||||
(node, part) => (node as Record<string, unknown> | undefined)?.[part],
|
||||
en
|
||||
);
|
||||
return typeof found === 'string' ? t(key) : id;
|
||||
// 构建时 i18n 插件把文案预编译成消息函数,测试里则是原始字符串
|
||||
return typeof found === 'string' || typeof found === 'function' ? t(key) : id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user