@nocobase/plugin-localization 1.2.12-alpha → 1.3.0-alpha.20240710084543

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.
Files changed (48) hide show
  1. package/package.json +2 -2
  2. package/dist/client/Localization.d.ts +0 -10
  3. package/dist/client/index.d.ts +0 -13
  4. package/dist/client/index.js +0 -10
  5. package/dist/client/locale/index.d.ts +0 -10
  6. package/dist/client/schemas/localization.d.ts +0 -10
  7. package/dist/externalVersion.js +0 -24
  8. package/dist/index.d.ts +0 -10
  9. package/dist/index.js +0 -48
  10. package/dist/locale/en-US.json +0 -24
  11. package/dist/locale/ko_KR.json +0 -23
  12. package/dist/locale/zh-CN.json +0 -24
  13. package/dist/node_modules/deepmerge/.editorconfig +0 -7
  14. package/dist/node_modules/deepmerge/.eslintcache +0 -1
  15. package/dist/node_modules/deepmerge/dist/cjs.js +0 -1
  16. package/dist/node_modules/deepmerge/dist/umd.js +0 -139
  17. package/dist/node_modules/deepmerge/index.d.ts +0 -20
  18. package/dist/node_modules/deepmerge/index.js +0 -106
  19. package/dist/node_modules/deepmerge/license.txt +0 -21
  20. package/dist/node_modules/deepmerge/package.json +0 -1
  21. package/dist/node_modules/deepmerge/rollup.config.js +0 -22
  22. package/dist/server/actions/localization.d.ts +0 -23
  23. package/dist/server/actions/localization.js +0 -237
  24. package/dist/server/actions/localizationTexts.d.ts +0 -13
  25. package/dist/server/actions/localizationTexts.js +0 -139
  26. package/dist/server/collections/localization-texts.d.ts +0 -10
  27. package/dist/server/collections/localization-texts.js +0 -95
  28. package/dist/server/collections/localization-translations.d.ts +0 -10
  29. package/dist/server/collections/localization-translations.js +0 -93
  30. package/dist/server/constans.d.ts +0 -16
  31. package/dist/server/constans.js +0 -57
  32. package/dist/server/index.d.ts +0 -9
  33. package/dist/server/index.js +0 -42
  34. package/dist/server/migrations/20230706200900-roles-add-translation.d.ts +0 -14
  35. package/dist/server/migrations/20230706200900-roles-add-translation.js +0 -59
  36. package/dist/server/migrations/20231206161851-fix-module.d.ts +0 -14
  37. package/dist/server/migrations/20231206161851-fix-module.js +0 -100
  38. package/dist/server/migrations/20240425224508-change-locale-module.d.ts +0 -14
  39. package/dist/server/migrations/20240425224508-change-locale-module.js +0 -51
  40. package/dist/server/migrations/20240426123538-delete-pkg-name-ns.d.ts +0 -28
  41. package/dist/server/migrations/20240426123538-delete-pkg-name-ns.js +0 -82
  42. package/dist/server/plugin.d.ts +0 -23
  43. package/dist/server/plugin.js +0 -156
  44. package/dist/server/resources.d.ts +0 -27
  45. package/dist/server/resources.js +0 -101
  46. package/dist/server/utils.d.ts +0 -11
  47. package/dist/server/utils.js +0 -89
  48. package/dist/swagger/index.json +0 -156
@@ -1,42 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __export = (target, all) => {
17
- for (var name in all)
18
- __defProp(target, name, { get: all[name], enumerable: true });
19
- };
20
- var __copyProps = (to, from, except, desc) => {
21
- if (from && typeof from === "object" || typeof from === "function") {
22
- for (let key of __getOwnPropNames(from))
23
- if (!__hasOwnProp.call(to, key) && key !== except)
24
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
- }
26
- return to;
27
- };
28
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
- // If the importer is in node compatibility mode or this is not an ESM
30
- // file that has been converted to a CommonJS file using a Babel-
31
- // compatible transform (i.e. "__esModule" has not been set), then set
32
- // "default" to the CommonJS "module.exports" for node compatibility.
33
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
- mod
35
- ));
36
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
- var server_exports = {};
38
- __export(server_exports, {
39
- default: () => import_plugin.default
40
- });
41
- module.exports = __toCommonJS(server_exports);
42
- var import_plugin = __toESM(require("./plugin"));
@@ -1,14 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Migration } from '@nocobase/server';
10
- export default class AddTranslationToRoleTitleMigration extends Migration {
11
- appVersion: string;
12
- up(): Promise<void>;
13
- down(): Promise<void>;
14
- }
@@ -1,59 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var roles_add_translation_exports = {};
28
- __export(roles_add_translation_exports, {
29
- default: () => AddTranslationToRoleTitleMigration
30
- });
31
- module.exports = __toCommonJS(roles_add_translation_exports);
32
- var import_server = require("@nocobase/server");
33
- class AddTranslationToRoleTitleMigration extends import_server.Migration {
34
- appVersion = "<0.11.1-alpha.1";
35
- async up() {
36
- const repo = this.context.db.getRepository("fields");
37
- const field = await repo.findOne({
38
- where: {
39
- collectionName: "roles",
40
- name: "title"
41
- }
42
- });
43
- if (field) {
44
- await repo.update({
45
- filter: {
46
- key: field.key
47
- },
48
- values: {
49
- options: {
50
- ...field.options,
51
- translation: true
52
- }
53
- }
54
- });
55
- }
56
- }
57
- async down() {
58
- }
59
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Migration } from '@nocobase/server';
10
- export default class FixModuleMigration extends Migration {
11
- appVersion: string;
12
- up(): Promise<void>;
13
- down(): Promise<void>;
14
- }
@@ -1,100 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var fix_module_exports = {};
28
- __export(fix_module_exports, {
29
- default: () => FixModuleMigration
30
- });
31
- module.exports = __toCommonJS(fix_module_exports);
32
- var import_database = require("@nocobase/database");
33
- var import_server = require("@nocobase/server");
34
- var import_localization = require("../actions/localization");
35
- var import_constans = require("../constans");
36
- class FixModuleMigration extends import_server.Migration {
37
- appVersion = "<0.17.0-alpha.3";
38
- async up() {
39
- const result = await this.app.version.satisfies("<=0.17.0-alpha.4");
40
- if (!result) {
41
- return;
42
- }
43
- const resources = await this.app.localeManager.getCacheResources("zh-CN");
44
- const menus = await (0, import_localization.getTextsFromMenu)(this.context.db, true);
45
- const collections = await (0, import_localization.getTextsFromDB)(this.context.db);
46
- const db = this.context.db;
47
- await db.getCollection("localizationTexts").sync();
48
- await db.sequelize.transaction(async (t) => {
49
- const menuTexts = Object.keys(menus);
50
- await db.getModel("localizationTexts").update(
51
- {
52
- module: `resources.${import_constans.NAMESPACE_MENUS}`
53
- },
54
- {
55
- where: {
56
- text: {
57
- [import_database.Op.in]: menuTexts
58
- }
59
- },
60
- transaction: t
61
- }
62
- );
63
- const collectionTexts = Object.keys(collections);
64
- await db.getModel("localizationTexts").update(
65
- {
66
- module: `resources.${import_constans.NAMESPACE_COLLECTIONS}`
67
- },
68
- {
69
- where: {
70
- text: {
71
- [import_database.Op.in]: collectionTexts
72
- }
73
- },
74
- transaction: t
75
- }
76
- );
77
- for (const [module2, resource] of Object.entries(resources)) {
78
- if (module2 === "client") {
79
- continue;
80
- }
81
- const texts = Object.keys(resource);
82
- await db.getModel("localizationTexts").update(
83
- {
84
- module: `resources.${module2}`
85
- },
86
- {
87
- where: {
88
- text: {
89
- [import_database.Op.in]: texts
90
- }
91
- },
92
- transaction: t
93
- }
94
- );
95
- }
96
- });
97
- }
98
- async down() {
99
- }
100
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Migration } from '@nocobase/server';
10
- export default class extends Migration {
11
- on: string;
12
- appVersion: string;
13
- up(): Promise<void>;
14
- }
@@ -1,51 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var change_locale_module_exports = {};
28
- __export(change_locale_module_exports, {
29
- default: () => change_locale_module_default
30
- });
31
- module.exports = __toCommonJS(change_locale_module_exports);
32
- var import_server = require("@nocobase/server");
33
- class change_locale_module_default extends import_server.Migration {
34
- on = "afterLoad";
35
- // 'beforeLoad' or 'afterLoad'
36
- appVersion = "<1.0.0-alpha.1";
37
- async up() {
38
- const repo = this.db.getRepository("localizationTexts");
39
- if (!repo) {
40
- return;
41
- }
42
- await repo.update({
43
- filter: {
44
- module: "resources.localization-management"
45
- },
46
- values: {
47
- module: "resources.localization"
48
- }
49
- });
50
- }
51
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Migration } from '@nocobase/server';
10
- export default class extends Migration {
11
- on: string;
12
- appVersion: string;
13
- namesMp: {
14
- 'auth-cas': string;
15
- 'auth-oidc': string;
16
- 'auth-saml': string;
17
- 'field-china-region': string;
18
- 'action-custom-request': string;
19
- 'action-export': string;
20
- 'field-formula': string;
21
- 'block-iframe': string;
22
- 'action-import': string;
23
- localization: string;
24
- 'field-sequence': string;
25
- 'auth-sms': string;
26
- };
27
- up(): Promise<void>;
28
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var delete_pkg_name_ns_exports = {};
28
- __export(delete_pkg_name_ns_exports, {
29
- default: () => delete_pkg_name_ns_default
30
- });
31
- module.exports = __toCommonJS(delete_pkg_name_ns_exports);
32
- var import_server = require("@nocobase/server");
33
- class delete_pkg_name_ns_default extends import_server.Migration {
34
- on = "afterLoad";
35
- // 'beforeLoad' or 'afterLoad'
36
- appVersion = "<1.0.0-alpha.1";
37
- namesMp = {
38
- "auth-cas": "cas",
39
- "auth-oidc": "oidc",
40
- "auth-saml": "saml",
41
- "field-china-region": "china-region",
42
- "action-custom-request": "custom-request",
43
- "action-export": "export",
44
- "field-formula": "formula-field",
45
- "block-iframe": "iframe-block",
46
- "action-import": "import",
47
- localization: "localization-management",
48
- "field-sequence": "sequence-field",
49
- "auth-sms": "sms-auth"
50
- };
51
- async up() {
52
- const resources = await this.app.localeManager.getCacheResources("en-US");
53
- const modules = Object.keys(resources);
54
- Object.entries(this.namesMp).forEach(([newName, oldName]) => {
55
- if (!modules.includes(newName)) {
56
- return;
57
- }
58
- modules.push(oldName, `${import_server.OFFICIAL_PLUGIN_PREFIX}${oldName}`);
59
- });
60
- const toBeDeleted = [];
61
- modules.forEach((module2) => {
62
- if (!module2.startsWith(import_server.OFFICIAL_PLUGIN_PREFIX)) {
63
- return;
64
- }
65
- const name = module2.replace(import_server.OFFICIAL_PLUGIN_PREFIX, "");
66
- if (!modules.includes(name)) {
67
- return;
68
- }
69
- toBeDeleted.push(module2);
70
- });
71
- if (!toBeDeleted.length) {
72
- return;
73
- }
74
- await this.db.getRepository("localizationTexts").destroy({
75
- filter: {
76
- module: {
77
- $in: toBeDeleted.map((module2) => `resources.${module2}`)
78
- }
79
- }
80
- });
81
- }
82
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import PluginUISchemaStorageServer from '@nocobase/plugin-ui-schema-storage';
10
- import { InstallOptions, Plugin } from '@nocobase/server';
11
- import Resources from './resources';
12
- export declare class PluginLocalizationServer extends Plugin {
13
- resources: Resources;
14
- registerUISchemahook(plugin?: PluginUISchemaStorageServer): void;
15
- afterAdd(): void;
16
- beforeLoad(): void;
17
- load(): Promise<void>;
18
- install(options?: InstallOptions): Promise<void>;
19
- afterEnable(): Promise<void>;
20
- afterDisable(): Promise<void>;
21
- remove(): Promise<void>;
22
- }
23
- export default PluginLocalizationServer;
@@ -1,156 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __export = (target, all) => {
17
- for (var name in all)
18
- __defProp(target, name, { get: all[name], enumerable: true });
19
- };
20
- var __copyProps = (to, from, except, desc) => {
21
- if (from && typeof from === "object" || typeof from === "function") {
22
- for (let key of __getOwnPropNames(from))
23
- if (!__hasOwnProp.call(to, key) && key !== except)
24
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
- }
26
- return to;
27
- };
28
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
- // If the importer is in node compatibility mode or this is not an ESM
30
- // file that has been converted to a CommonJS file using a Babel-
31
- // compatible transform (i.e. "__esModule" has not been set), then set
32
- // "default" to the CommonJS "module.exports" for node compatibility.
33
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
- mod
35
- ));
36
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
- var plugin_exports = {};
38
- __export(plugin_exports, {
39
- PluginLocalizationServer: () => PluginLocalizationServer,
40
- default: () => plugin_default
41
- });
42
- module.exports = __toCommonJS(plugin_exports);
43
- var import_server = require("@nocobase/server");
44
- var import_path = require("path");
45
- var import_localization = __toESM(require("./actions/localization"));
46
- var import_localizationTexts = __toESM(require("./actions/localizationTexts"));
47
- var import_resources = __toESM(require("./resources"));
48
- var import_utils = require("./utils");
49
- var import_constans = require("./constans");
50
- class PluginLocalizationServer extends import_server.Plugin {
51
- resources;
52
- registerUISchemahook(plugin) {
53
- const uiSchemaStoragePlugin = plugin || this.app.getPlugin("ui-schema-storage");
54
- if (!uiSchemaStoragePlugin) {
55
- return;
56
- }
57
- uiSchemaStoragePlugin.serverHooks.register("onSelfSave", "extractTextToLocale", async ({ schemaInstance }) => {
58
- var _a;
59
- const module2 = `resources.${import_constans.NAMESPACE_MENUS}`;
60
- const schema = schemaInstance.get("schema");
61
- const title = (schema == null ? void 0 : schema.title) || ((_a = schema == null ? void 0 : schema["x-component-props"]) == null ? void 0 : _a.title);
62
- if (!title) {
63
- return;
64
- }
65
- const result = await this.resources.filterExists([{ text: title, module: module2 }]);
66
- if (!result.length) {
67
- return;
68
- }
69
- this.db.getRepository("localizationTexts").create({
70
- values: {
71
- module: module2,
72
- text: title
73
- }
74
- }).then((res) => this.resources.updateCacheTexts([res])).catch((err) => {
75
- });
76
- });
77
- }
78
- afterAdd() {
79
- }
80
- beforeLoad() {
81
- }
82
- async load() {
83
- await this.importCollections((0, import_path.resolve)(__dirname, "collections"));
84
- this.app.resource({
85
- name: "localizationTexts",
86
- actions: import_localizationTexts.default
87
- });
88
- this.app.resource({
89
- name: "localization",
90
- actions: import_localization.default
91
- });
92
- this.app.acl.registerSnippet({
93
- name: `pm.${this.name}.localization`,
94
- actions: ["localization:*", "localizationTexts:*", "localizationTranslations:*"]
95
- });
96
- this.db.on("afterSave", async (instance, options) => {
97
- const module2 = `resources.${import_constans.NAMESPACE_COLLECTIONS}`;
98
- const model = instance.constructor;
99
- const collection = model.collection;
100
- if (!collection) {
101
- return;
102
- }
103
- let texts = [];
104
- const fields = Array.from(collection.fields.values()).filter((field) => {
105
- var _a;
106
- return ((_a = field.options) == null ? void 0 : _a.translation) && instance["_changed"].has(field.name);
107
- }).map((field) => field.name);
108
- if (!fields.length) {
109
- return;
110
- }
111
- const textsFromDB = (0, import_utils.getTextsFromDBRecord)(fields, instance);
112
- textsFromDB.forEach((text) => {
113
- texts.push({ text, module: module2 });
114
- });
115
- texts = await this.resources.filterExists(texts, options == null ? void 0 : options.transaction);
116
- this.db.getModel("localizationTexts").bulkCreate(
117
- texts.map(({ text, module: module3 }) => ({
118
- module: module3,
119
- text
120
- })),
121
- {
122
- transaction: options == null ? void 0 : options.transaction
123
- }
124
- ).then((newTexts) => this.resources.updateCacheTexts(newTexts, options == null ? void 0 : options.transaction)).catch((err) => {
125
- });
126
- });
127
- const cache = await this.app.cacheManager.createCache({
128
- name: "localization",
129
- prefix: "localization",
130
- store: "memory"
131
- });
132
- this.resources = new import_resources.default(this.db, cache);
133
- this.registerUISchemahook();
134
- this.app.localeManager.registerResourceStorer("plugin-localization", {
135
- getResources: (lang) => this.resources.getResources(lang)
136
- });
137
- }
138
- async install(options) {
139
- }
140
- async afterEnable() {
141
- }
142
- async afterDisable() {
143
- const uiSchemaStoragePlugin = this.app.getPlugin("ui-schema-storage");
144
- if (!uiSchemaStoragePlugin) {
145
- return;
146
- }
147
- uiSchemaStoragePlugin.serverHooks.remove("onSelfSave", "extractTextToLocale");
148
- }
149
- async remove() {
150
- }
151
- }
152
- var plugin_default = PluginLocalizationServer;
153
- // Annotate the CommonJS export names for ESM import in node:
154
- 0 && (module.exports = {
155
- PluginLocalizationServer
156
- });
@@ -1,27 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Cache } from '@nocobase/cache';
10
- import { Database, Transaction } from '@nocobase/database';
11
- export default class Resources {
12
- cache: Cache;
13
- db: Database;
14
- constructor(db: Database, cache: Cache);
15
- getTexts(transaction?: Transaction): Promise<any>;
16
- getTranslations(locale: string): Promise<any>;
17
- getResources(locale: string): Promise<{}>;
18
- filterExists(texts: {
19
- text: string;
20
- module: string;
21
- }[], transaction?: Transaction): Promise<{
22
- text: string;
23
- module: string;
24
- }[]>;
25
- updateCacheTexts(texts: any[], transaction?: Transaction): Promise<void>;
26
- resetCache(locale: string): Promise<void>;
27
- }