@goenhance/strapi-plugins-translate 1.0.8 → 1.1.0
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.
package/dist/server/index.js
CHANGED
|
@@ -46,7 +46,7 @@ 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,
|
|
49
|
+
async function sendTaskStartNotification(contentType, sourceLocale, targetLocales, entries) {
|
|
50
50
|
try {
|
|
51
51
|
const elements = [];
|
|
52
52
|
elements.push({
|
|
@@ -57,7 +57,7 @@ async function sendTaskStartNotification(contentType, sourceLocale, targetLocale
|
|
|
57
57
|
text: {
|
|
58
58
|
tag: "lark_md",
|
|
59
59
|
content: `**总条目数**
|
|
60
|
-
<font color='blue'>${
|
|
60
|
+
<font color='blue'>${entries.length}</font>`
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
{
|
|
@@ -78,7 +78,7 @@ async function sendTaskStartNotification(contentType, sourceLocale, targetLocale
|
|
|
78
78
|
text: {
|
|
79
79
|
tag: "lark_md",
|
|
80
80
|
content: `**预计翻译数**
|
|
81
|
-
<font color='blue'>${
|
|
81
|
+
<font color='blue'>${entries.length * targetLocales.length}</font>`
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
]
|
|
@@ -123,6 +123,26 @@ ${targetLocales.join(", ")}`
|
|
|
123
123
|
elements.push({
|
|
124
124
|
tag: "hr"
|
|
125
125
|
});
|
|
126
|
+
elements.push({
|
|
127
|
+
tag: "div",
|
|
128
|
+
text: {
|
|
129
|
+
tag: "lark_md",
|
|
130
|
+
content: "📋 **待翻译条目**"
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
entries.forEach((entry, index) => {
|
|
134
|
+
elements.push({
|
|
135
|
+
tag: "div",
|
|
136
|
+
text: {
|
|
137
|
+
tag: "lark_md",
|
|
138
|
+
content: `${index + 1}. **${entry.title}**
|
|
139
|
+
<font color='grey'>ID: ${entry.documentId}</font>`
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
elements.push({
|
|
144
|
+
tag: "hr"
|
|
145
|
+
});
|
|
126
146
|
elements.push({
|
|
127
147
|
tag: "div",
|
|
128
148
|
text: {
|
|
@@ -416,12 +436,17 @@ async function executeBatchTranslation(strapi2, contentType, entries, sourceLoca
|
|
|
416
436
|
delete translatedData.localizations;
|
|
417
437
|
delete translatedData.createdBy;
|
|
418
438
|
delete translatedData.updatedBy;
|
|
419
|
-
await strapi2.documents(contentType).update({
|
|
439
|
+
const updatedDoc = await strapi2.documents(contentType).update({
|
|
420
440
|
documentId: entryId,
|
|
421
441
|
locale: targetLocale,
|
|
422
|
-
data: translatedData
|
|
423
|
-
status: publish ? "published" : "draft"
|
|
442
|
+
data: translatedData
|
|
424
443
|
});
|
|
444
|
+
if (publish && updatedDoc) {
|
|
445
|
+
await strapi2.documents(contentType).publish({
|
|
446
|
+
documentId: entryId,
|
|
447
|
+
locale: targetLocale
|
|
448
|
+
});
|
|
449
|
+
}
|
|
425
450
|
return {
|
|
426
451
|
documentId: entryId,
|
|
427
452
|
locale: targetLocale,
|
|
@@ -726,14 +751,55 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
|
|
|
726
751
|
message: "翻译任务已排队。完成后,您将收到飞书通知。"
|
|
727
752
|
}
|
|
728
753
|
};
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
754
|
+
setImmediate(async () => {
|
|
755
|
+
try {
|
|
756
|
+
const contentTypeDisplayName = contentTypeSchema.info?.displayName || contentType;
|
|
757
|
+
const mainField = contentTypeSchema.info?.mainField || Object.keys(contentTypeSchema.attributes).find(
|
|
758
|
+
(key) => contentTypeSchema.attributes[key].type === "string" && ["title", "name", "label"].includes(key.toLowerCase())
|
|
759
|
+
) || "id";
|
|
760
|
+
const entryInfoPromises = entries.map(async (entryId) => {
|
|
761
|
+
try {
|
|
762
|
+
const entry = await strapi2.documents(contentType).findOne({
|
|
763
|
+
documentId: entryId,
|
|
764
|
+
locale: sourceLocale
|
|
765
|
+
});
|
|
766
|
+
if (!entry) {
|
|
767
|
+
return {
|
|
768
|
+
documentId: entryId,
|
|
769
|
+
title: entryId
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
const getDisplayValue = (value) => {
|
|
773
|
+
if (value === null || value === void 0) return "";
|
|
774
|
+
if (typeof value === "string" || typeof value === "number") return String(value);
|
|
775
|
+
if (typeof value === "object") {
|
|
776
|
+
return value.title || value.name || value.label || value.id || JSON.stringify(value);
|
|
777
|
+
}
|
|
778
|
+
return String(value);
|
|
779
|
+
};
|
|
780
|
+
const title = getDisplayValue(entry[mainField]) || getDisplayValue(entry.id) || entryId;
|
|
781
|
+
return {
|
|
782
|
+
documentId: entryId,
|
|
783
|
+
title
|
|
784
|
+
};
|
|
785
|
+
} catch (error) {
|
|
786
|
+
console.error(`Failed to fetch entry ${entryId}:`, error);
|
|
787
|
+
return {
|
|
788
|
+
documentId: entryId,
|
|
789
|
+
title: entryId
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
const entryInfoList = await Promise.all(entryInfoPromises);
|
|
794
|
+
await sendTaskStartNotification(
|
|
795
|
+
contentTypeDisplayName,
|
|
796
|
+
sourceLocale,
|
|
797
|
+
targetLocales,
|
|
798
|
+
entryInfoList
|
|
799
|
+
);
|
|
800
|
+
} catch (error) {
|
|
801
|
+
console.error("Failed to send task start notification:", error);
|
|
802
|
+
}
|
|
737
803
|
});
|
|
738
804
|
setImmediate(() => {
|
|
739
805
|
executeBatchTranslation(
|
|
@@ -782,12 +848,17 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
|
|
|
782
848
|
delete translatedData.localizations;
|
|
783
849
|
delete translatedData.createdBy;
|
|
784
850
|
delete translatedData.updatedBy;
|
|
785
|
-
await strapi2.documents(contentType).update({
|
|
851
|
+
const updatedDoc = await strapi2.documents(contentType).update({
|
|
786
852
|
documentId: entryId,
|
|
787
853
|
locale: targetLocale,
|
|
788
|
-
data: translatedData
|
|
789
|
-
status: publish ? "published" : "draft"
|
|
854
|
+
data: translatedData
|
|
790
855
|
});
|
|
856
|
+
if (publish && updatedDoc) {
|
|
857
|
+
await strapi2.documents(contentType).publish({
|
|
858
|
+
documentId: entryId,
|
|
859
|
+
locale: targetLocale
|
|
860
|
+
});
|
|
861
|
+
}
|
|
791
862
|
return {
|
|
792
863
|
documentId: entryId,
|
|
793
864
|
locale: targetLocale,
|
package/dist/server/index.mjs
CHANGED
|
@@ -45,7 +45,7 @@ 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,
|
|
48
|
+
async function sendTaskStartNotification(contentType, sourceLocale, targetLocales, entries) {
|
|
49
49
|
try {
|
|
50
50
|
const elements = [];
|
|
51
51
|
elements.push({
|
|
@@ -56,7 +56,7 @@ async function sendTaskStartNotification(contentType, sourceLocale, targetLocale
|
|
|
56
56
|
text: {
|
|
57
57
|
tag: "lark_md",
|
|
58
58
|
content: `**总条目数**
|
|
59
|
-
<font color='blue'>${
|
|
59
|
+
<font color='blue'>${entries.length}</font>`
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
{
|
|
@@ -77,7 +77,7 @@ async function sendTaskStartNotification(contentType, sourceLocale, targetLocale
|
|
|
77
77
|
text: {
|
|
78
78
|
tag: "lark_md",
|
|
79
79
|
content: `**预计翻译数**
|
|
80
|
-
<font color='blue'>${
|
|
80
|
+
<font color='blue'>${entries.length * targetLocales.length}</font>`
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
]
|
|
@@ -122,6 +122,26 @@ ${targetLocales.join(", ")}`
|
|
|
122
122
|
elements.push({
|
|
123
123
|
tag: "hr"
|
|
124
124
|
});
|
|
125
|
+
elements.push({
|
|
126
|
+
tag: "div",
|
|
127
|
+
text: {
|
|
128
|
+
tag: "lark_md",
|
|
129
|
+
content: "📋 **待翻译条目**"
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
entries.forEach((entry, index) => {
|
|
133
|
+
elements.push({
|
|
134
|
+
tag: "div",
|
|
135
|
+
text: {
|
|
136
|
+
tag: "lark_md",
|
|
137
|
+
content: `${index + 1}. **${entry.title}**
|
|
138
|
+
<font color='grey'>ID: ${entry.documentId}</font>`
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
elements.push({
|
|
143
|
+
tag: "hr"
|
|
144
|
+
});
|
|
125
145
|
elements.push({
|
|
126
146
|
tag: "div",
|
|
127
147
|
text: {
|
|
@@ -415,12 +435,17 @@ async function executeBatchTranslation(strapi2, contentType, entries, sourceLoca
|
|
|
415
435
|
delete translatedData.localizations;
|
|
416
436
|
delete translatedData.createdBy;
|
|
417
437
|
delete translatedData.updatedBy;
|
|
418
|
-
await strapi2.documents(contentType).update({
|
|
438
|
+
const updatedDoc = await strapi2.documents(contentType).update({
|
|
419
439
|
documentId: entryId,
|
|
420
440
|
locale: targetLocale,
|
|
421
|
-
data: translatedData
|
|
422
|
-
status: publish ? "published" : "draft"
|
|
441
|
+
data: translatedData
|
|
423
442
|
});
|
|
443
|
+
if (publish && updatedDoc) {
|
|
444
|
+
await strapi2.documents(contentType).publish({
|
|
445
|
+
documentId: entryId,
|
|
446
|
+
locale: targetLocale
|
|
447
|
+
});
|
|
448
|
+
}
|
|
424
449
|
return {
|
|
425
450
|
documentId: entryId,
|
|
426
451
|
locale: targetLocale,
|
|
@@ -725,14 +750,55 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
|
|
|
725
750
|
message: "翻译任务已排队。完成后,您将收到飞书通知。"
|
|
726
751
|
}
|
|
727
752
|
};
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
753
|
+
setImmediate(async () => {
|
|
754
|
+
try {
|
|
755
|
+
const contentTypeDisplayName = contentTypeSchema.info?.displayName || contentType;
|
|
756
|
+
const mainField = contentTypeSchema.info?.mainField || Object.keys(contentTypeSchema.attributes).find(
|
|
757
|
+
(key) => contentTypeSchema.attributes[key].type === "string" && ["title", "name", "label"].includes(key.toLowerCase())
|
|
758
|
+
) || "id";
|
|
759
|
+
const entryInfoPromises = entries.map(async (entryId) => {
|
|
760
|
+
try {
|
|
761
|
+
const entry = await strapi2.documents(contentType).findOne({
|
|
762
|
+
documentId: entryId,
|
|
763
|
+
locale: sourceLocale
|
|
764
|
+
});
|
|
765
|
+
if (!entry) {
|
|
766
|
+
return {
|
|
767
|
+
documentId: entryId,
|
|
768
|
+
title: entryId
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
const getDisplayValue = (value) => {
|
|
772
|
+
if (value === null || value === void 0) return "";
|
|
773
|
+
if (typeof value === "string" || typeof value === "number") return String(value);
|
|
774
|
+
if (typeof value === "object") {
|
|
775
|
+
return value.title || value.name || value.label || value.id || JSON.stringify(value);
|
|
776
|
+
}
|
|
777
|
+
return String(value);
|
|
778
|
+
};
|
|
779
|
+
const title = getDisplayValue(entry[mainField]) || getDisplayValue(entry.id) || entryId;
|
|
780
|
+
return {
|
|
781
|
+
documentId: entryId,
|
|
782
|
+
title
|
|
783
|
+
};
|
|
784
|
+
} catch (error) {
|
|
785
|
+
console.error(`Failed to fetch entry ${entryId}:`, error);
|
|
786
|
+
return {
|
|
787
|
+
documentId: entryId,
|
|
788
|
+
title: entryId
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
const entryInfoList = await Promise.all(entryInfoPromises);
|
|
793
|
+
await sendTaskStartNotification(
|
|
794
|
+
contentTypeDisplayName,
|
|
795
|
+
sourceLocale,
|
|
796
|
+
targetLocales,
|
|
797
|
+
entryInfoList
|
|
798
|
+
);
|
|
799
|
+
} catch (error) {
|
|
800
|
+
console.error("Failed to send task start notification:", error);
|
|
801
|
+
}
|
|
736
802
|
});
|
|
737
803
|
setImmediate(() => {
|
|
738
804
|
executeBatchTranslation(
|
|
@@ -781,12 +847,17 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
|
|
|
781
847
|
delete translatedData.localizations;
|
|
782
848
|
delete translatedData.createdBy;
|
|
783
849
|
delete translatedData.updatedBy;
|
|
784
|
-
await strapi2.documents(contentType).update({
|
|
850
|
+
const updatedDoc = await strapi2.documents(contentType).update({
|
|
785
851
|
documentId: entryId,
|
|
786
852
|
locale: targetLocale,
|
|
787
|
-
data: translatedData
|
|
788
|
-
status: publish ? "published" : "draft"
|
|
853
|
+
data: translatedData
|
|
789
854
|
});
|
|
855
|
+
if (publish && updatedDoc) {
|
|
856
|
+
await strapi2.documents(contentType).publish({
|
|
857
|
+
documentId: entryId,
|
|
858
|
+
locale: targetLocale
|
|
859
|
+
});
|
|
860
|
+
}
|
|
790
861
|
return {
|
|
791
862
|
documentId: entryId,
|
|
792
863
|
locale: targetLocale,
|
|
@@ -12,10 +12,14 @@ interface TranslationResultDetail {
|
|
|
12
12
|
message?: string;
|
|
13
13
|
entryTitle?: string;
|
|
14
14
|
}
|
|
15
|
+
interface EntryInfo {
|
|
16
|
+
documentId: string;
|
|
17
|
+
title: string;
|
|
18
|
+
}
|
|
15
19
|
/**
|
|
16
20
|
* Send notification when translation task is submitted
|
|
17
21
|
*/
|
|
18
|
-
export declare function sendTaskStartNotification(contentType: string, sourceLocale: string, targetLocales: string[],
|
|
22
|
+
export declare function sendTaskStartNotification(contentType: string, sourceLocale: string, targetLocales: string[], entries: EntryInfo[]): Promise<void>;
|
|
19
23
|
/**
|
|
20
24
|
* Send batch translation result notification to Feishu with table format
|
|
21
25
|
*/
|
package/package.json
CHANGED