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

51 lines
2.0 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.tree.default_schema',
'sidebar.object_group.tables',
'sidebar.object_group.views',
'sidebar.object_group.materialized_views',
'sidebar.object_group.routines',
'sidebar.object_group.triggers',
'sidebar.object_group.events',
];
describe('Sidebar object group i18n', () => {
it('localizes database object group titles and default schema fallback', () => {
[
"const schemaTitle = bucket.schemaName || '默认模式'",
"buildObjectGroup(schemaNodeKey, 'tables', '表'",
"buildObjectGroup(schemaNodeKey, 'views', '视图'",
"buildObjectGroup(schemaNodeKey, 'materializedViews', '物化视图'",
"buildObjectGroup(schemaNodeKey, 'routines', '函数'",
"buildObjectGroup(schemaNodeKey, 'triggers', '触发器'",
"buildObjectGroup(schemaNodeKey, 'events', '事件'",
"buildObjectGroup(key as string, 'tables', '表'",
"buildObjectGroup(key as string, 'views', '视图'",
"buildObjectGroup(key as string, 'materializedViews', '物化视图'",
"buildObjectGroup(key as string, 'routines', '函数'",
"buildObjectGroup(key as string, 'triggers', '触发器'",
"buildObjectGroup(key as string, 'events', '事件'",
].forEach((snippet) => {
expect(source).not.toContain(snippet);
});
requiredKeys.forEach((key) => {
expect(source).toContain(`t('${key}'`);
});
});
it('keeps database object group keys available in every locale', () => {
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();
});
});
});
});