@goenhance/strapi-plugins-translate 1.0.6 → 1.0.8

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,130 @@ 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
+ });
86
+ elements.push({
87
+ tag: "hr"
88
+ });
89
+ elements.push({
90
+ tag: "div",
91
+ fields: [
92
+ {
93
+ is_short: true,
94
+ text: {
95
+ tag: "lark_md",
96
+ content: `**内容类型**
97
+ ${contentType}`
98
+ }
99
+ },
100
+ {
101
+ is_short: true,
102
+ text: {
103
+ tag: "lark_md",
104
+ content: `**源语言**
105
+ ${sourceLocale}`
106
+ }
107
+ }
108
+ ]
109
+ });
110
+ elements.push({
111
+ tag: "div",
112
+ fields: [
113
+ {
114
+ is_short: false,
115
+ text: {
116
+ tag: "lark_md",
117
+ content: `**目标语言**
118
+ ${targetLocales.join(", ")}`
119
+ }
120
+ }
121
+ ]
122
+ });
123
+ elements.push({
124
+ tag: "hr"
125
+ });
126
+ elements.push({
127
+ tag: "div",
128
+ text: {
129
+ tag: "lark_md",
130
+ content: "💡 **提示**\n任务正在后台处理中, 完成后将收到结果通知。"
131
+ }
132
+ });
133
+ elements.push({
134
+ tag: "div",
135
+ text: {
136
+ tag: "lark_md",
137
+ content: `⏰ **提交时间**
138
+ ${(/* @__PURE__ */ new Date()).toLocaleString("zh-CN", {
139
+ timeZone: "Asia/Shanghai"
140
+ })}`
141
+ }
142
+ });
143
+ const message = {
144
+ msg_type: "interactive",
145
+ card: {
146
+ header: {
147
+ title: {
148
+ tag: "plain_text",
149
+ content: "🚀 翻译任务已提交"
150
+ },
151
+ template: "blue"
152
+ },
153
+ elements
154
+ }
155
+ };
156
+ const response = await fetch(FEISHU_WEBHOOK_URL, {
157
+ method: "POST",
158
+ headers: {
159
+ "Content-Type": "application/json"
160
+ },
161
+ body: JSON.stringify(message)
162
+ });
163
+ const result = await response.json();
164
+ if (result.code !== 0) {
165
+ console.error("Feishu task start notification failed:", result);
166
+ } else {
167
+ console.log("Feishu task start notification sent successfully");
168
+ }
169
+ } catch (error) {
170
+ console.error("Error sending Feishu task start notification:", error);
171
+ }
172
+ }
49
173
  async function sendBatchTranslationNotification(contentType, sourceLocale, targetLocales, results) {
50
174
  const successResults = results.filter((r) => r.success);
51
175
  const failureResults = results.filter((r) => !r.success);
@@ -602,6 +726,15 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
602
726
  message: "翻译任务已排队。完成后,您将收到飞书通知。"
603
727
  }
604
728
  };
729
+ const contentTypeDisplayName = contentTypeSchema.info?.displayName || contentType;
730
+ sendTaskStartNotification(
731
+ contentTypeDisplayName,
732
+ sourceLocale,
733
+ targetLocales,
734
+ entries.length
735
+ ).catch((error) => {
736
+ console.error("Failed to send task start notification:", error);
737
+ });
605
738
  setImmediate(() => {
606
739
  executeBatchTranslation(
607
740
  strapi2,
@@ -45,6 +45,130 @@ 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
+ });
85
+ elements.push({
86
+ tag: "hr"
87
+ });
88
+ elements.push({
89
+ tag: "div",
90
+ fields: [
91
+ {
92
+ is_short: true,
93
+ text: {
94
+ tag: "lark_md",
95
+ content: `**内容类型**
96
+ ${contentType}`
97
+ }
98
+ },
99
+ {
100
+ is_short: true,
101
+ text: {
102
+ tag: "lark_md",
103
+ content: `**源语言**
104
+ ${sourceLocale}`
105
+ }
106
+ }
107
+ ]
108
+ });
109
+ elements.push({
110
+ tag: "div",
111
+ fields: [
112
+ {
113
+ is_short: false,
114
+ text: {
115
+ tag: "lark_md",
116
+ content: `**目标语言**
117
+ ${targetLocales.join(", ")}`
118
+ }
119
+ }
120
+ ]
121
+ });
122
+ elements.push({
123
+ tag: "hr"
124
+ });
125
+ elements.push({
126
+ tag: "div",
127
+ text: {
128
+ tag: "lark_md",
129
+ content: "💡 **提示**\n任务正在后台处理中, 完成后将收到结果通知。"
130
+ }
131
+ });
132
+ elements.push({
133
+ tag: "div",
134
+ text: {
135
+ tag: "lark_md",
136
+ content: `⏰ **提交时间**
137
+ ${(/* @__PURE__ */ new Date()).toLocaleString("zh-CN", {
138
+ timeZone: "Asia/Shanghai"
139
+ })}`
140
+ }
141
+ });
142
+ const message = {
143
+ msg_type: "interactive",
144
+ card: {
145
+ header: {
146
+ title: {
147
+ tag: "plain_text",
148
+ content: "🚀 翻译任务已提交"
149
+ },
150
+ template: "blue"
151
+ },
152
+ elements
153
+ }
154
+ };
155
+ const response = await fetch(FEISHU_WEBHOOK_URL, {
156
+ method: "POST",
157
+ headers: {
158
+ "Content-Type": "application/json"
159
+ },
160
+ body: JSON.stringify(message)
161
+ });
162
+ const result = await response.json();
163
+ if (result.code !== 0) {
164
+ console.error("Feishu task start notification failed:", result);
165
+ } else {
166
+ console.log("Feishu task start notification sent successfully");
167
+ }
168
+ } catch (error) {
169
+ console.error("Error sending Feishu task start notification:", error);
170
+ }
171
+ }
48
172
  async function sendBatchTranslationNotification(contentType, sourceLocale, targetLocales, results) {
49
173
  const successResults = results.filter((r) => r.success);
50
174
  const failureResults = results.filter((r) => !r.success);
@@ -601,6 +725,15 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
601
725
  message: "翻译任务已排队。完成后,您将收到飞书通知。"
602
726
  }
603
727
  };
728
+ const contentTypeDisplayName = contentTypeSchema.info?.displayName || contentType;
729
+ sendTaskStartNotification(
730
+ contentTypeDisplayName,
731
+ sourceLocale,
732
+ targetLocales,
733
+ entries.length
734
+ ).catch((error) => {
735
+ console.error("Failed to send task start notification:", error);
736
+ });
604
737
  setImmediate(() => {
605
738
  executeBatchTranslation(
606
739
  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.6",
2
+ "version": "1.0.8",
3
3
  "keywords": [
4
4
  "strapi",
5
5
  "plugin",