Files
MyGoNavi/frontend/src/components/SidebarBatchObjectLoadFeedback.i18n.test.ts
tianqijiuyun-latiao 9364c48ef0 feat(i18n): 完善多模块多语言适配与发版验证
扩展前后端多语言文案与共享词典。增加多模块 i18n 回归测试与 guard。收口外部 SQL 菜单和弹窗多语言文案。
2026-06-17 13:17:33 +08:00

44 lines
1.8 KiB
TypeScript

import { readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
const source = readFileSync(new URL('./Sidebar.tsx', import.meta.url), 'utf8');
const locales = ['zh-CN', 'zh-TW', 'en-US', 'ja-JP', 'de-DE', 'ru-RU'] as const;
const requiredKeys = [
'sidebar.message.load_database_list_failed',
'sidebar.message.load_table_list_failed',
] as const;
const extractBatchObjectLoadBlock = (): string => {
const start = source.indexOf('const loadDatabasesForBatch = async');
const end = source.indexOf('const handleConnectionChange = async', start);
expect(start).toBeGreaterThanOrEqual(0);
expect(end).toBeGreaterThan(start);
return source.slice(start, end);
};
const placeholders = (value: string): string[] => [...value.matchAll(/\{\{(\w+)\}\}/g)]
.map((match) => match[1])
.sort();
describe('Sidebar batch object load feedback i18n', () => {
it('localizes batch database and object list loading failure wrappers', () => {
const block = extractBatchObjectLoadBlock();
expect(block).not.toContain("'获取数据库列表失败: ' + res.message");
expect(block).not.toContain("'获取表列表失败: ' + res.message");
expect(block).toContain("t('sidebar.message.load_database_list_failed'");
expect(block).toContain("t('sidebar.message.load_table_list_failed'");
expect(block).toContain('error: res.message');
});
it('keeps batch object load feedback keys available with stable placeholders', () => {
locales.forEach((locale) => {
const catalog = JSON.parse(readFileSync(new URL(`../../../shared/i18n/${locale}.json`, import.meta.url), 'utf8')) as Record<string, string>;
requiredKeys.forEach((key) => {
expect(catalog[key], `${locale}:${key}`).toBeTruthy();
expect(placeholders(catalog[key])).toEqual(['error']);
});
});
});
});