Skip to content

Commit 4f413ab

Browse files
committed
feat: enhance export notification with i18n support
1 parent d88b02a commit 4f413ab

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

apps/nestjs-backend/src/features/base/base-export.service.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable sonarjs/no-duplicate-string */
22
import { Readable, PassThrough } from 'stream';
33
import { Injectable, Logger } from '@nestjs/common';
4-
import type { ILinkFieldOptions } from '@teable/core';
4+
import type { ILinkFieldOptions, ILocalization } from '@teable/core';
55
import { FieldType, getRandomString, ViewType, isLinkLookupOptions } from '@teable/core';
66
import type { Field, View, TableMeta, Base } from '@teable/db-main-prisma';
77
import { PrismaService } from '@teable/db-main-prisma';
@@ -92,13 +92,26 @@ export class BaseExportService {
9292
'Content-Disposition': `attachment; filename*=UTF-8''${encodeURIComponent(name)}`,
9393
}
9494
);
95-
const messageString = `${baseName} Export successfully: <a href="${previewUrl}" name="${name}" class="hover:text-blue-500 underline">🗂️ ${name}</a>`;
96-
this.notifyExportResult(baseId, messageString, previewUrl);
95+
const message = {
96+
i18nKey: 'common.email.templates.notify.exportBase.success.message',
97+
context: {
98+
baseName,
99+
previewUrl,
100+
name,
101+
},
102+
};
103+
this.notifyExportResult(baseId, message, previewUrl);
97104
})
98105
.catch(async (e) => {
99106
this.logger.error(`export base zip error: ${e.message}`, e?.stack);
100-
const messageString = `❌ ${baseName} export failed: ${e.message}`;
101-
this.notifyExportResult(baseId, messageString);
107+
const message = {
108+
i18nKey: 'common.email.templates.notify.exportBase.failed.message',
109+
context: {
110+
baseName,
111+
errorMessage: e.message,
112+
},
113+
};
114+
this.notifyExportResult(baseId, message);
102115
});
103116
}
104117

@@ -992,7 +1005,11 @@ export class BaseExportService {
9921005
});
9931006
}
9941007

995-
private async notifyExportResult(baseId: string, message: string, previewUrl?: string) {
1008+
private async notifyExportResult(
1009+
baseId: string,
1010+
message: string | ILocalization,
1011+
previewUrl?: string
1012+
) {
9961013
const userId = this.cls.get('user.id');
9971014
await this.eventEmitterService.emit(Events.BASE_EXPORT_COMPLETE, {
9981015
previewUrl,

apps/nestjs-backend/src/features/notification/notification.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,11 @@ export class NotificationService {
369369
});
370370
}
371371

372-
async sendExportBaseResultNotify(params: { baseId: string; toUserId: string; message: string }) {
372+
async sendExportBaseResultNotify(params: {
373+
baseId: string;
374+
toUserId: string;
375+
message: string | ILocalization;
376+
}) {
373377
const { toUserId, message } = params;
374378
const toUser = await this.userService.getUserById(toUserId);
375379
if (!toUser) {

packages/common-i18n/src/locales/en/common.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,13 @@
757757
}
758758
},
759759
"exportBase": {
760-
"title": "Export Base Notification"
760+
"title": "Export base result notification",
761+
"success": {
762+
"message": "{{baseName}} Export successfully: <a href=\"{{previewUrl}}\" name=\"{{name}}\" class=\"hover:text-blue-500 underline\">🗂️ {{name}}</a>"
763+
},
764+
"failed": {
765+
"message": "❌ {{baseName}} exported failed: {{errorMessage}}"
766+
}
761767
},
762768
"task": {
763769
"ai": {

packages/common-i18n/src/locales/zh/common.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,13 @@
754754
}
755755
},
756756
"exportBase": {
757-
"title": "导出空间通知"
757+
"title": "导出数据库结果通知",
758+
"success": {
759+
"message": "{{baseName}} 导出成功: <a href=\"{{previewUrl}}\" name=\"{{name}}\" class=\"hover:text-blue-500 underline\">🗂️ {{name}}</a>"
760+
},
761+
"failed": {
762+
"message": "❌ {{baseName}} 导出失败: {{errorMessage}}"
763+
}
758764
},
759765
"task": {
760766
"ai": {

0 commit comments

Comments
 (0)