@goenhance/strapi-plugins-translate 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,138 @@ const config = {
46
46
  };
47
47
  const contentTypes = {};
48
48
  const FEISHU_WEBHOOK_URL = "https://open.feishu.cn/open-apis/bot/v2/hook/e165567d-3fa7-48a1-bf96-a41cbed2c924";
49
+ async function sendTaskStartNotification(contentType, sourceLocale, targetLocales, entryCount) {
50
+ try {
51
+ const elements = [];
52
+ elements.push({
53
+ tag: "div",
54
+ fields: [
55
+ {
56
+ is_short: true,
57
+ text: {
58
+ tag: "lark_md",
59
+ content: `**总条目数**
60
+ <font color='blue'>${entryCount}</font>`
61
+ }
62
+ },
63
+ {
64
+ is_short: true,
65
+ text: {
66
+ tag: "lark_md",
67
+ content: `**目标语言数**
68
+ <font color='blue'>${targetLocales.length}</font>`
69
+ }
70
+ }
71
+ ]
72
+ });
73
+ elements.push({
74
+ tag: "div",
75
+ fields: [
76
+ {
77
+ is_short: true,
78
+ text: {
79
+ tag: "lark_md",
80
+ content: `**预计翻译数**
81
+ <font color='blue'>${entryCount * targetLocales.length}</font>`
82
+ }
83
+ },
84
+ {
85
+ is_short: true,
86
+ text: {
87
+ tag: "lark_md",
88
+ content: `**任务状态**
89
+ <font color='green'>处理中...</font>`
90
+ }
91
+ }
92
+ ]
93
+ });
94
+ elements.push({
95
+ tag: "hr"
96
+ });
97
+ elements.push({
98
+ tag: "div",
99
+ fields: [
100
+ {
101
+ is_short: true,
102
+ text: {
103
+ tag: "lark_md",
104
+ content: `**内容类型**
105
+ ${contentType}`
106
+ }
107
+ },
108
+ {
109
+ is_short: true,
110
+ text: {
111
+ tag: "lark_md",
112
+ content: `**源语言**
113
+ ${sourceLocale}`
114
+ }
115
+ }
116
+ ]
117
+ });
118
+ elements.push({
119
+ tag: "div",
120
+ fields: [
121
+ {
122
+ is_short: false,
123
+ text: {
124
+ tag: "lark_md",
125
+ content: `**目标语言**
126
+ ${targetLocales.join(", ")}`
127
+ }
128
+ }
129
+ ]
130
+ });
131
+ elements.push({
132
+ tag: "hr"
133
+ });
134
+ elements.push({
135
+ tag: "div",
136
+ text: {
137
+ tag: "lark_md",
138
+ content: "💡 **提示**\n任务正在后台处理中,您可以离开此页面。完成后将收到结果通知。"
139
+ }
140
+ });
141
+ elements.push({
142
+ tag: "div",
143
+ text: {
144
+ tag: "lark_md",
145
+ content: `⏰ **提交时间**
146
+ ${(/* @__PURE__ */ new Date()).toLocaleString("zh-CN", {
147
+ timeZone: "Asia/Shanghai"
148
+ })}`
149
+ }
150
+ });
151
+ const message = {
152
+ msg_type: "interactive",
153
+ card: {
154
+ header: {
155
+ title: {
156
+ tag: "plain_text",
157
+ content: "🚀 翻译任务已提交"
158
+ },
159
+ template: "blue"
160
+ },
161
+ elements
162
+ }
163
+ };
164
+ const response = await fetch(FEISHU_WEBHOOK_URL, {
165
+ method: "POST",
166
+ headers: {
167
+ "Content-Type": "application/json"
168
+ },
169
+ body: JSON.stringify(message)
170
+ });
171
+ const result = await response.json();
172
+ if (result.code !== 0) {
173
+ console.error("Feishu task start notification failed:", result);
174
+ } else {
175
+ console.log("Feishu task start notification sent successfully");
176
+ }
177
+ } catch (error) {
178
+ console.error("Error sending Feishu task start notification:", error);
179
+ }
180
+ }
49
181
  async function sendBatchTranslationNotification(contentType, sourceLocale, targetLocales, results) {
50
182
  const successResults = results.filter((r) => r.success);
51
183
  const failureResults = results.filter((r) => !r.success);
@@ -55,7 +187,7 @@ async function sendBatchTranslationNotification(contentType, sourceLocale, targe
55
187
  results.forEach((result) => {
56
188
  if (!entriesByDocId.has(result.documentId)) {
57
189
  entriesByDocId.set(result.documentId, {
58
- title: result.entryTitle || result.documentId,
190
+ title: `[${result?.entryTitle}]-[${result.documentId}]`,
59
191
  successes: [],
60
192
  failures: []
61
193
  });
@@ -602,6 +734,15 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
602
734
  message: "翻译任务已排队。完成后,您将收到飞书通知。"
603
735
  }
604
736
  };
737
+ const contentTypeDisplayName = contentTypeSchema.info?.displayName || contentType;
738
+ sendTaskStartNotification(
739
+ contentTypeDisplayName,
740
+ sourceLocale,
741
+ targetLocales,
742
+ entries.length
743
+ ).catch((error) => {
744
+ console.error("Failed to send task start notification:", error);
745
+ });
605
746
  setImmediate(() => {
606
747
  executeBatchTranslation(
607
748
  strapi2,
@@ -45,6 +45,138 @@ const config = {
45
45
  };
46
46
  const contentTypes = {};
47
47
  const FEISHU_WEBHOOK_URL = "https://open.feishu.cn/open-apis/bot/v2/hook/e165567d-3fa7-48a1-bf96-a41cbed2c924";
48
+ async function sendTaskStartNotification(contentType, sourceLocale, targetLocales, entryCount) {
49
+ try {
50
+ const elements = [];
51
+ elements.push({
52
+ tag: "div",
53
+ fields: [
54
+ {
55
+ is_short: true,
56
+ text: {
57
+ tag: "lark_md",
58
+ content: `**总条目数**
59
+ <font color='blue'>${entryCount}</font>`
60
+ }
61
+ },
62
+ {
63
+ is_short: true,
64
+ text: {
65
+ tag: "lark_md",
66
+ content: `**目标语言数**
67
+ <font color='blue'>${targetLocales.length}</font>`
68
+ }
69
+ }
70
+ ]
71
+ });
72
+ elements.push({
73
+ tag: "div",
74
+ fields: [
75
+ {
76
+ is_short: true,
77
+ text: {
78
+ tag: "lark_md",
79
+ content: `**预计翻译数**
80
+ <font color='blue'>${entryCount * targetLocales.length}</font>`
81
+ }
82
+ },
83
+ {
84
+ is_short: true,
85
+ text: {
86
+ tag: "lark_md",
87
+ content: `**任务状态**
88
+ <font color='green'>处理中...</font>`
89
+ }
90
+ }
91
+ ]
92
+ });
93
+ elements.push({
94
+ tag: "hr"
95
+ });
96
+ elements.push({
97
+ tag: "div",
98
+ fields: [
99
+ {
100
+ is_short: true,
101
+ text: {
102
+ tag: "lark_md",
103
+ content: `**内容类型**
104
+ ${contentType}`
105
+ }
106
+ },
107
+ {
108
+ is_short: true,
109
+ text: {
110
+ tag: "lark_md",
111
+ content: `**源语言**
112
+ ${sourceLocale}`
113
+ }
114
+ }
115
+ ]
116
+ });
117
+ elements.push({
118
+ tag: "div",
119
+ fields: [
120
+ {
121
+ is_short: false,
122
+ text: {
123
+ tag: "lark_md",
124
+ content: `**目标语言**
125
+ ${targetLocales.join(", ")}`
126
+ }
127
+ }
128
+ ]
129
+ });
130
+ elements.push({
131
+ tag: "hr"
132
+ });
133
+ elements.push({
134
+ tag: "div",
135
+ text: {
136
+ tag: "lark_md",
137
+ content: "💡 **提示**\n任务正在后台处理中,您可以离开此页面。完成后将收到结果通知。"
138
+ }
139
+ });
140
+ elements.push({
141
+ tag: "div",
142
+ text: {
143
+ tag: "lark_md",
144
+ content: `⏰ **提交时间**
145
+ ${(/* @__PURE__ */ new Date()).toLocaleString("zh-CN", {
146
+ timeZone: "Asia/Shanghai"
147
+ })}`
148
+ }
149
+ });
150
+ const message = {
151
+ msg_type: "interactive",
152
+ card: {
153
+ header: {
154
+ title: {
155
+ tag: "plain_text",
156
+ content: "🚀 翻译任务已提交"
157
+ },
158
+ template: "blue"
159
+ },
160
+ elements
161
+ }
162
+ };
163
+ const response = await fetch(FEISHU_WEBHOOK_URL, {
164
+ method: "POST",
165
+ headers: {
166
+ "Content-Type": "application/json"
167
+ },
168
+ body: JSON.stringify(message)
169
+ });
170
+ const result = await response.json();
171
+ if (result.code !== 0) {
172
+ console.error("Feishu task start notification failed:", result);
173
+ } else {
174
+ console.log("Feishu task start notification sent successfully");
175
+ }
176
+ } catch (error) {
177
+ console.error("Error sending Feishu task start notification:", error);
178
+ }
179
+ }
48
180
  async function sendBatchTranslationNotification(contentType, sourceLocale, targetLocales, results) {
49
181
  const successResults = results.filter((r) => r.success);
50
182
  const failureResults = results.filter((r) => !r.success);
@@ -54,7 +186,7 @@ async function sendBatchTranslationNotification(contentType, sourceLocale, targe
54
186
  results.forEach((result) => {
55
187
  if (!entriesByDocId.has(result.documentId)) {
56
188
  entriesByDocId.set(result.documentId, {
57
- title: result.entryTitle || result.documentId,
189
+ title: `[${result?.entryTitle}]-[${result.documentId}]`,
58
190
  successes: [],
59
191
  failures: []
60
192
  });
@@ -601,6 +733,15 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
601
733
  message: "翻译任务已排队。完成后,您将收到飞书通知。"
602
734
  }
603
735
  };
736
+ const contentTypeDisplayName = contentTypeSchema.info?.displayName || contentType;
737
+ sendTaskStartNotification(
738
+ contentTypeDisplayName,
739
+ sourceLocale,
740
+ targetLocales,
741
+ entries.length
742
+ ).catch((error) => {
743
+ console.error("Failed to send task start notification:", error);
744
+ });
604
745
  setImmediate(() => {
605
746
  executeBatchTranslation(
606
747
  strapi2,
@@ -12,6 +12,10 @@ interface TranslationResultDetail {
12
12
  message?: string;
13
13
  entryTitle?: string;
14
14
  }
15
+ /**
16
+ * Send notification when translation task is submitted
17
+ */
18
+ export declare function sendTaskStartNotification(contentType: string, sourceLocale: string, targetLocales: string[], entryCount: number): Promise<void>;
15
19
  /**
16
20
  * Send batch translation result notification to Feishu with table format
17
21
  */
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.5",
2
+ "version": "1.0.7",
3
3
  "keywords": [
4
4
  "strapi",
5
5
  "plugin",