🐛 fix(i18n): 合并 dev 后补齐只读保护多语言

This commit is contained in:
tianqijiuyun-latiao
2026-06-23 17:05:35 +08:00
parent 839fdd7d66
commit 09ae3d74c4
45 changed files with 31438 additions and 29485 deletions

View File

@@ -1,4 +1,4 @@
import { describe, expect, it } from 'vitest';
import { afterEach, describe, expect, it } from 'vitest';
import {
buildBatchDatabaseExportWorkbenchTab,
@@ -8,8 +8,13 @@ import {
buildTableExportTab,
DEFAULT_TABLE_EXPORT_SCOPE_OPTION,
} from './tableExportTab';
import { setCurrentLanguage } from '../i18n';
describe('tableExportTab', () => {
afterEach(() => {
setCurrentLanguage('en-US');
});
it('builds a stable history key for persisted export records', () => {
expect(buildTableExportHistoryKey(' conn-1 ', ' app ', ' public.orders ')).toBe('conn-1::app::public.orders');
});
@@ -29,6 +34,7 @@ describe('tableExportTab', () => {
});
it('builds a stable table export tab with normalized defaults', () => {
setCurrentLanguage('zh-CN');
const tab = buildTableExportTab({
connectionId: 'conn-1',
dbName: 'app',
@@ -39,7 +45,7 @@ describe('tableExportTab', () => {
expect(tab.type).toBe('table-export');
expect(tab.title).toBe('导出 public.orders');
expect(tab.exportWorkbenchMode).toBe('single');
expect(tab.tableExportScopeOptions).toEqual([DEFAULT_TABLE_EXPORT_SCOPE_OPTION]);
expect(tab.tableExportScopeOptions).toEqual([{ ...DEFAULT_TABLE_EXPORT_SCOPE_OPTION }]);
expect(tab.tableExportInitialScope).toBe('all');
expect(tab.tableExportQueryByScope).toBeUndefined();
expect(tab.tableExportRowCountByScope).toBeUndefined();
@@ -80,6 +86,7 @@ describe('tableExportTab', () => {
});
it('builds batch table export workbench tabs with stable ids', () => {
setCurrentLanguage('zh-CN');
const tab = buildBatchTableExportWorkbenchTab({
connectionId: 'conn-1',
dbName: 'SYS',
@@ -93,6 +100,7 @@ describe('tableExportTab', () => {
});
it('builds batch database export workbench tabs with stable ids', () => {
setCurrentLanguage('zh-CN');
const tab = buildBatchDatabaseExportWorkbenchTab({
connectionId: 'conn-1',
});
@@ -102,4 +110,15 @@ describe('tableExportTab', () => {
expect(tab.title).toBe('批量导出库');
expect(tab.exportWorkbenchMode).toBe('batch-databases');
});
it('uses the current language for batch workbench fallback titles', () => {
setCurrentLanguage('en-US');
expect(buildBatchTableExportWorkbenchTab({
connectionId: 'conn-1',
}).title).toBe('Batch export objects');
expect(buildBatchDatabaseExportWorkbenchTab({
connectionId: 'conn-1',
}).title).toBe('Batch export databases');
});
});

View File

@@ -1,9 +1,14 @@
import type { TabData, TableExportScope, TableExportScopeOption } from '../types';
import { t } from '../i18n';
export const DEFAULT_TABLE_EXPORT_SCOPE_OPTION: TableExportScopeOption = {
value: 'all',
label: '全表数据',
description: '后台重新查询整张表并导出全部数据。',
get label() {
return t('data_export.workbench.scope.all.label');
},
get description() {
return t('data_export.workbench.scope.all.description');
},
};
export const buildTableExportHistoryKey = (
@@ -129,10 +134,11 @@ export const buildTableExportTab = (input: BuildTableExportTabInput): TabData =>
const tableName = String(input.tableName || '').trim();
const scopeOptions = normalizeScopeOptions(input.scopeOptions);
const initialScope = resolveInitialScope(scopeOptions, input.initialScope);
const objectLabel = tableName || '未命名对象';
const objectLabel = tableName || t('data_export.progress.value.target_fallback');
return {
id: `table-export-${connectionId}-${dbName}-${tableName}`,
title: String(input.title || `导出 ${objectLabel}`).trim() || `导出 ${objectLabel}`,
title: String(input.title || t('data_export.workbench.task.export_target', { name: objectLabel })).trim()
|| t('data_export.workbench.task.export_target', { name: objectLabel }),
type: 'table-export',
exportWorkbenchMode: 'single',
connectionId,
@@ -157,7 +163,7 @@ export const buildBatchTableExportWorkbenchTab = (
const scopeSuffix = dbName || 'all';
return {
id: `table-export-batch-tables-${connectionId || 'none'}-${scopeSuffix}`,
title: String(input.title || '批量导出对象').trim() || '批量导出对象',
title: String(input.title || t('sidebar.tab.batch_export_objects')).trim() || t('sidebar.tab.batch_export_objects'),
type: 'table-export',
exportWorkbenchMode: 'batch-tables',
connectionId,
@@ -172,7 +178,7 @@ export const buildBatchDatabaseExportWorkbenchTab = (
const connectionId = String(input.connectionId || '').trim();
return {
id: `table-export-batch-databases-${connectionId || 'none'}`,
title: String(input.title || '批量导出库').trim() || '批量导出库',
title: String(input.title || t('sidebar.tab.batch_export_databases')).trim() || t('sidebar.tab.batch_export_databases'),
type: 'table-export',
exportWorkbenchMode: 'batch-databases',
connectionId,