@nocobase/plugin-localization 2.1.0-beta.35 → 2.1.0-beta.37
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/externalVersion.js
CHANGED
|
@@ -8,24 +8,24 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "2.1.0-beta.
|
|
11
|
+
"@nocobase/client": "2.1.0-beta.37",
|
|
12
12
|
"antd": "5.24.2",
|
|
13
13
|
"react": "18.2.0",
|
|
14
|
-
"@nocobase/flow-engine": "2.1.0-beta.
|
|
15
|
-
"@nocobase/client-v2": "2.1.0-beta.
|
|
16
|
-
"@nocobase/database": "2.1.0-beta.
|
|
17
|
-
"@nocobase/server": "2.1.0-beta.
|
|
18
|
-
"@nocobase/utils": "2.1.0-beta.
|
|
19
|
-
"@nocobase/plugin-async-task-manager": "2.1.0-beta.
|
|
20
|
-
"@nocobase/cache": "2.1.0-beta.
|
|
21
|
-
"@nocobase/ai": "2.1.0-beta.
|
|
14
|
+
"@nocobase/flow-engine": "2.1.0-beta.37",
|
|
15
|
+
"@nocobase/client-v2": "2.1.0-beta.37",
|
|
16
|
+
"@nocobase/database": "2.1.0-beta.37",
|
|
17
|
+
"@nocobase/server": "2.1.0-beta.37",
|
|
18
|
+
"@nocobase/utils": "2.1.0-beta.37",
|
|
19
|
+
"@nocobase/plugin-async-task-manager": "2.1.0-beta.37",
|
|
20
|
+
"@nocobase/cache": "2.1.0-beta.37",
|
|
21
|
+
"@nocobase/ai": "2.1.0-beta.37",
|
|
22
22
|
"react-i18next": "11.18.6",
|
|
23
23
|
"@formily/react": "2.3.7",
|
|
24
24
|
"lodash": "4.18.1",
|
|
25
25
|
"@ant-design/icons": "5.6.1",
|
|
26
26
|
"@emotion/css": "11.13.0",
|
|
27
|
-
"@nocobase/plugin-ai": "2.1.0-beta.
|
|
27
|
+
"@nocobase/plugin-ai": "2.1.0-beta.37",
|
|
28
28
|
"ahooks": "3.7.8",
|
|
29
|
-
"@nocobase/actions": "2.1.0-beta.
|
|
29
|
+
"@nocobase/actions": "2.1.0-beta.37",
|
|
30
30
|
"@langchain/core": "1.1.24"
|
|
31
31
|
};
|
|
@@ -7,7 +7,15 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { TaskType } from '@nocobase/plugin-async-task-manager';
|
|
10
|
+
import type { LocalizationTextRecord } from '../translation-scope';
|
|
10
11
|
export declare const LOCALIZATION_AI_TRANSLATE_TASK_TYPE = "localization:ai-translate";
|
|
12
|
+
export declare const pickBuiltInResourceReference: (row: LocalizationTextRecord, references: Map<string, Map<string, string>>, locales: ReferenceLocaleConfig) => {
|
|
13
|
+
locale: string;
|
|
14
|
+
translation: string;
|
|
15
|
+
} | {
|
|
16
|
+
locale?: undefined;
|
|
17
|
+
translation?: undefined;
|
|
18
|
+
};
|
|
11
19
|
type ReferenceLocaleConfig = {
|
|
12
20
|
primary?: string;
|
|
13
21
|
fallback?: string;
|
|
@@ -25,6 +33,7 @@ export declare class LocalizationAITranslateTask extends TaskType {
|
|
|
25
33
|
private countTexts;
|
|
26
34
|
private getLocaleReferences;
|
|
27
35
|
private getReferenceMaps;
|
|
36
|
+
private getBuiltInReferenceMaps;
|
|
28
37
|
private pickDbReference;
|
|
29
38
|
private getSystemDefaultLocale;
|
|
30
39
|
private resolveReferenceLocales;
|
|
@@ -27,7 +27,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
27
27
|
var localization_ai_translate_exports = {};
|
|
28
28
|
__export(localization_ai_translate_exports, {
|
|
29
29
|
LOCALIZATION_AI_TRANSLATE_TASK_TYPE: () => LOCALIZATION_AI_TRANSLATE_TASK_TYPE,
|
|
30
|
-
LocalizationAITranslateTask: () => LocalizationAITranslateTask
|
|
30
|
+
LocalizationAITranslateTask: () => LocalizationAITranslateTask,
|
|
31
|
+
pickBuiltInResourceReference: () => pickBuiltInResourceReference
|
|
31
32
|
});
|
|
32
33
|
module.exports = __toCommonJS(localization_ai_translate_exports);
|
|
33
34
|
var import_plugin_async_task_manager = require("@nocobase/plugin-async-task-manager");
|
|
@@ -49,6 +50,16 @@ const getTranslationWorkerCount = () => {
|
|
|
49
50
|
}
|
|
50
51
|
return DEFAULT_TRANSLATION_WORKER_COUNT;
|
|
51
52
|
};
|
|
53
|
+
const pickBuiltInResourceReference = (row, references, locales) => {
|
|
54
|
+
var _a;
|
|
55
|
+
for (const locale of [locales.primary, locales.fallback].filter(isString)) {
|
|
56
|
+
const translation = (_a = references.get(locale)) == null ? void 0 : _a.get(String(row.id));
|
|
57
|
+
if (translation) {
|
|
58
|
+
return { locale, translation };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return {};
|
|
62
|
+
};
|
|
52
63
|
class LocalizationAITranslationError extends Error {
|
|
53
64
|
constructor(message, details) {
|
|
54
65
|
super(message);
|
|
@@ -214,12 +225,41 @@ class LocalizationAITranslateTask extends import_plugin_async_task_manager.TaskT
|
|
|
214
225
|
async getReferenceMaps(textIds, locales) {
|
|
215
226
|
const result = /* @__PURE__ */ new Map();
|
|
216
227
|
await Promise.all(
|
|
217
|
-
locales.map(async (locale) => {
|
|
228
|
+
Array.from(new Set(locales)).map(async (locale) => {
|
|
218
229
|
result.set(locale, await this.getLocaleReferences(textIds, locale));
|
|
219
230
|
})
|
|
220
231
|
);
|
|
221
232
|
return result;
|
|
222
233
|
}
|
|
234
|
+
async getBuiltInReferenceMaps(rows, locales) {
|
|
235
|
+
const result = /* @__PURE__ */ new Map();
|
|
236
|
+
if (!rows.length) {
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
await Promise.all(
|
|
240
|
+
Array.from(new Set(locales)).map(async (locale) => {
|
|
241
|
+
var _a;
|
|
242
|
+
const resources = await this.app.localeManager.getCacheResources(locale);
|
|
243
|
+
const references = /* @__PURE__ */ new Map();
|
|
244
|
+
for (const row of rows) {
|
|
245
|
+
const moduleName = (0, import_translation_scope.getModuleName)(row);
|
|
246
|
+
if (!moduleName) {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const modules = Array.from(/* @__PURE__ */ new Set([(0, import_translation_scope.normalizeModuleName)(moduleName), moduleName]));
|
|
250
|
+
for (const module2 of modules) {
|
|
251
|
+
const translation = (_a = resources == null ? void 0 : resources[module2]) == null ? void 0 : _a[row.text];
|
|
252
|
+
if (translation) {
|
|
253
|
+
references.set(String(row.id), translation);
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
result.set(locale, references);
|
|
259
|
+
})
|
|
260
|
+
);
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
223
263
|
pickDbReference(row, references, locales) {
|
|
224
264
|
var _a;
|
|
225
265
|
for (const locale of [locales.primary, locales.fallback].filter(isString)) {
|
|
@@ -250,10 +290,10 @@ class LocalizationAITranslateTask extends import_plugin_async_task_manager.TaskT
|
|
|
250
290
|
};
|
|
251
291
|
}
|
|
252
292
|
async buildTranslationItems(batch, referenceLocales, chunkIndex) {
|
|
253
|
-
const
|
|
293
|
+
const builtInRows = batch.filter((item) => item.isBuiltIn).map((item) => item.row);
|
|
254
294
|
const customTextIds = batch.filter((item) => !item.isBuiltIn).map((item) => item.row.id);
|
|
255
|
-
const builtInReferences = await this.
|
|
256
|
-
|
|
295
|
+
const builtInReferences = await this.getBuiltInReferenceMaps(
|
|
296
|
+
builtInRows,
|
|
257
297
|
[referenceLocales.builtIn.primary, referenceLocales.builtIn.fallback].filter(isString)
|
|
258
298
|
);
|
|
259
299
|
const customReferences = await this.getReferenceMaps(
|
|
@@ -262,7 +302,7 @@ class LocalizationAITranslateTask extends import_plugin_async_task_manager.TaskT
|
|
|
262
302
|
);
|
|
263
303
|
return batch.map(({ row, isBuiltIn }) => {
|
|
264
304
|
const references = isBuiltIn ? referenceLocales.builtIn : referenceLocales.custom;
|
|
265
|
-
const reference =
|
|
305
|
+
const reference = isBuiltIn ? pickBuiltInResourceReference(row, builtInReferences, references) : this.pickDbReference(row, customReferences, references);
|
|
266
306
|
return {
|
|
267
307
|
row,
|
|
268
308
|
chunkIndex,
|
|
@@ -561,5 +601,6 @@ ${sourceText}
|
|
|
561
601
|
// Annotate the CommonJS export names for ESM import in node:
|
|
562
602
|
0 && (module.exports = {
|
|
563
603
|
LOCALIZATION_AI_TRANSLATE_TASK_TYPE,
|
|
564
|
-
LocalizationAITranslateTask
|
|
604
|
+
LocalizationAITranslateTask,
|
|
605
|
+
pickBuiltInResourceReference
|
|
565
606
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-localization",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.37",
|
|
4
4
|
"main": "dist/server/index.js",
|
|
5
5
|
"homepage": "https://docs.nocobase.com/handbook/localization-management",
|
|
6
6
|
"homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/localization-management",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"description": "Allows to manage localization resources of the application.",
|
|
31
31
|
"description.ru-RU": "Позволяет управлять ресурсами локализации приложения.",
|
|
32
32
|
"description.zh-CN": "支持管理应用程序的本地化资源。",
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "7132e5b83ecc0e42b54715eaf1429c72bcef34ae"
|
|
34
34
|
}
|