@nocobase/plugin-localization 1.2.13-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.
- package/package.json +2 -2
- package/dist/client/Localization.d.ts +0 -10
- package/dist/client/index.d.ts +0 -13
- package/dist/client/index.js +0 -10
- package/dist/client/locale/index.d.ts +0 -10
- package/dist/client/schemas/localization.d.ts +0 -10
- package/dist/externalVersion.js +0 -24
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -48
- package/dist/locale/en-US.json +0 -24
- package/dist/locale/ko_KR.json +0 -23
- package/dist/locale/zh-CN.json +0 -24
- package/dist/node_modules/deepmerge/.editorconfig +0 -7
- package/dist/node_modules/deepmerge/.eslintcache +0 -1
- package/dist/node_modules/deepmerge/dist/cjs.js +0 -1
- package/dist/node_modules/deepmerge/dist/umd.js +0 -139
- package/dist/node_modules/deepmerge/index.d.ts +0 -20
- package/dist/node_modules/deepmerge/index.js +0 -106
- package/dist/node_modules/deepmerge/license.txt +0 -21
- package/dist/node_modules/deepmerge/package.json +0 -1
- package/dist/node_modules/deepmerge/rollup.config.js +0 -22
- package/dist/server/actions/localization.d.ts +0 -23
- package/dist/server/actions/localization.js +0 -237
- package/dist/server/actions/localizationTexts.d.ts +0 -13
- package/dist/server/actions/localizationTexts.js +0 -139
- package/dist/server/collections/localization-texts.d.ts +0 -10
- package/dist/server/collections/localization-texts.js +0 -95
- package/dist/server/collections/localization-translations.d.ts +0 -10
- package/dist/server/collections/localization-translations.js +0 -93
- package/dist/server/constans.d.ts +0 -16
- package/dist/server/constans.js +0 -57
- package/dist/server/index.d.ts +0 -9
- package/dist/server/index.js +0 -42
- package/dist/server/migrations/20230706200900-roles-add-translation.d.ts +0 -14
- package/dist/server/migrations/20230706200900-roles-add-translation.js +0 -59
- package/dist/server/migrations/20231206161851-fix-module.d.ts +0 -14
- package/dist/server/migrations/20231206161851-fix-module.js +0 -100
- package/dist/server/migrations/20240425224508-change-locale-module.d.ts +0 -14
- package/dist/server/migrations/20240425224508-change-locale-module.js +0 -51
- package/dist/server/migrations/20240426123538-delete-pkg-name-ns.d.ts +0 -28
- package/dist/server/migrations/20240426123538-delete-pkg-name-ns.js +0 -82
- package/dist/server/plugin.d.ts +0 -23
- package/dist/server/plugin.js +0 -156
- package/dist/server/resources.d.ts +0 -27
- package/dist/server/resources.js +0 -101
- package/dist/server/utils.d.ts +0 -11
- package/dist/server/utils.js +0 -89
- package/dist/swagger/index.json +0 -156
package/dist/server/resources.js
DELETED
|
@@ -1,101 +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 resources_exports = {};
|
|
28
|
-
__export(resources_exports, {
|
|
29
|
-
default: () => Resources
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(resources_exports);
|
|
32
|
-
class Resources {
|
|
33
|
-
cache;
|
|
34
|
-
db;
|
|
35
|
-
constructor(db, cache) {
|
|
36
|
-
this.cache = cache;
|
|
37
|
-
this.db = db;
|
|
38
|
-
}
|
|
39
|
-
async getTexts(transaction) {
|
|
40
|
-
if (!await this.db.collectionExistsInDb("localizationTexts")) {
|
|
41
|
-
return [];
|
|
42
|
-
}
|
|
43
|
-
return await this.cache.wrap(`texts`, async () => {
|
|
44
|
-
return await this.db.getRepository("localizationTexts").find({
|
|
45
|
-
fields: ["id", "module", "text"],
|
|
46
|
-
raw: true,
|
|
47
|
-
transaction
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
async getTranslations(locale) {
|
|
52
|
-
if (!await this.db.collectionExistsInDb("localizationTranslations")) {
|
|
53
|
-
return [];
|
|
54
|
-
}
|
|
55
|
-
return await this.cache.wrap(`translations:${locale}`, async () => {
|
|
56
|
-
return await this.db.getRepository("localizationTranslations").find({
|
|
57
|
-
fields: ["textId", "translation"],
|
|
58
|
-
filter: { locale },
|
|
59
|
-
raw: true
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
async getResources(locale) {
|
|
64
|
-
const [texts, translations] = await Promise.all([this.getTexts(), this.getTranslations(locale)]);
|
|
65
|
-
const resources = {};
|
|
66
|
-
const textsMap = texts.reduce((map, item) => {
|
|
67
|
-
map[item.id] = item;
|
|
68
|
-
return map;
|
|
69
|
-
}, {});
|
|
70
|
-
translations.forEach((item) => {
|
|
71
|
-
const text = textsMap[item.textId];
|
|
72
|
-
if (!text) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const module2 = text.module;
|
|
76
|
-
if (!resources[module2]) {
|
|
77
|
-
resources[module2] = {};
|
|
78
|
-
}
|
|
79
|
-
resources[module2][text.text] = item.translation;
|
|
80
|
-
});
|
|
81
|
-
return resources;
|
|
82
|
-
}
|
|
83
|
-
async filterExists(texts, transaction) {
|
|
84
|
-
const existTexts = await this.getTexts(transaction);
|
|
85
|
-
return texts.filter((text) => {
|
|
86
|
-
return !existTexts.find((item) => item.text === text.text && item.module === text.module);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
async updateCacheTexts(texts, transaction) {
|
|
90
|
-
const newTexts = texts.map((text) => ({
|
|
91
|
-
id: text.id,
|
|
92
|
-
module: text.module,
|
|
93
|
-
text: text.text
|
|
94
|
-
}));
|
|
95
|
-
const existTexts = await this.getTexts(transaction);
|
|
96
|
-
await this.cache.set(`texts`, [...existTexts, ...newTexts]);
|
|
97
|
-
}
|
|
98
|
-
async resetCache(locale) {
|
|
99
|
-
await this.cache.del(`translations:${locale}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
package/dist/server/utils.d.ts
DELETED
|
@@ -1,11 +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
|
-
export declare const compile: (title: string) => string;
|
|
10
|
-
export declare const getTextsFromUISchema: (schema: any) => any[];
|
|
11
|
-
export declare const getTextsFromDBRecord: (fields: string[], record: any) => any[];
|
package/dist/server/utils.js
DELETED
|
@@ -1,89 +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 utils_exports = {};
|
|
28
|
-
__export(utils_exports, {
|
|
29
|
-
compile: () => compile,
|
|
30
|
-
getTextsFromDBRecord: () => getTextsFromDBRecord,
|
|
31
|
-
getTextsFromUISchema: () => getTextsFromUISchema
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(utils_exports);
|
|
34
|
-
const compile = (title) => (title || "").replace(/{{\s*t\(["|'|`](.*)["|'|`]\)\s*}}/g, "$1");
|
|
35
|
-
/* istanbul ignore next -- @preserve */
|
|
36
|
-
const getTextsFromUISchema = (schema) => {
|
|
37
|
-
var _a, _b, _c, _d;
|
|
38
|
-
const texts = [];
|
|
39
|
-
const title = compile(schema.title);
|
|
40
|
-
const componentPropsTitle = compile((_a = schema["x-component-props"]) == null ? void 0 : _a.title);
|
|
41
|
-
const decoratorPropsTitle = compile((_b = schema["x-decorator-props"]) == null ? void 0 : _b.title);
|
|
42
|
-
if (title) {
|
|
43
|
-
texts.push(title);
|
|
44
|
-
}
|
|
45
|
-
if (componentPropsTitle) {
|
|
46
|
-
texts.push(componentPropsTitle);
|
|
47
|
-
}
|
|
48
|
-
if (decoratorPropsTitle) {
|
|
49
|
-
texts.push(decoratorPropsTitle);
|
|
50
|
-
}
|
|
51
|
-
if ((_d = (_c = schema["x-data-templates"]) == null ? void 0 : _c.items) == null ? void 0 : _d.length) {
|
|
52
|
-
schema["x-data-templates"].items.forEach((item) => {
|
|
53
|
-
const title2 = compile(item.title);
|
|
54
|
-
if (title2) {
|
|
55
|
-
texts.push(title2);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
return texts;
|
|
60
|
-
};
|
|
61
|
-
const getTextsFromDBRecord = (fields, record) => {
|
|
62
|
-
const texts = [];
|
|
63
|
-
fields.forEach((field) => {
|
|
64
|
-
var _a, _b;
|
|
65
|
-
const value = record[field];
|
|
66
|
-
if (typeof value === "string") {
|
|
67
|
-
texts.push(compile(value));
|
|
68
|
-
}
|
|
69
|
-
if (typeof value === "object") {
|
|
70
|
-
if ((_a = value == null ? void 0 : value.uiSchema) == null ? void 0 : _a.title) {
|
|
71
|
-
texts.push(compile(value.uiSchema.title));
|
|
72
|
-
}
|
|
73
|
-
if ((_b = value == null ? void 0 : value.uiSchema) == null ? void 0 : _b.enum) {
|
|
74
|
-
value.uiSchema.enum.forEach((item) => {
|
|
75
|
-
if (item == null ? void 0 : item.label) {
|
|
76
|
-
texts.push(compile(item.label));
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
return texts;
|
|
83
|
-
};
|
|
84
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
-
0 && (module.exports = {
|
|
86
|
-
compile,
|
|
87
|
-
getTextsFromDBRecord,
|
|
88
|
-
getTextsFromUISchema
|
|
89
|
-
});
|
package/dist/swagger/index.json
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"openapi": "3.0.2",
|
|
3
|
-
"info": {
|
|
4
|
-
"title": "NocoBase API - Localization management plugin"
|
|
5
|
-
},
|
|
6
|
-
"tags": [],
|
|
7
|
-
"paths": {
|
|
8
|
-
"/localization:sync": {
|
|
9
|
-
"post": {
|
|
10
|
-
"tags": ["localization"],
|
|
11
|
-
"description": "Synchronize localization resources",
|
|
12
|
-
"parameters": [
|
|
13
|
-
{
|
|
14
|
-
"name": "X-Locale",
|
|
15
|
-
"in": "header",
|
|
16
|
-
"defalut": "en-US",
|
|
17
|
-
"schema": {
|
|
18
|
-
"type": "string"
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
],
|
|
22
|
-
"requestBody": {
|
|
23
|
-
"content": {
|
|
24
|
-
"application/json": {
|
|
25
|
-
"schema": {
|
|
26
|
-
"type": "object",
|
|
27
|
-
"properties": {
|
|
28
|
-
"type": {
|
|
29
|
-
"type": "array",
|
|
30
|
-
"items": {
|
|
31
|
-
"type": "string",
|
|
32
|
-
"enum": ["local", "menu", "db"]
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
"responses": {
|
|
41
|
-
"200": {
|
|
42
|
-
"description": "OK"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"/localization:publish": {
|
|
48
|
-
"post": {
|
|
49
|
-
"tags": ["localization"],
|
|
50
|
-
"description": "Publish localization resources (Reset cache)",
|
|
51
|
-
"parameters": [
|
|
52
|
-
{
|
|
53
|
-
"name": "X-Locale",
|
|
54
|
-
"in": "header",
|
|
55
|
-
"defalut": "en-US",
|
|
56
|
-
"schema": {
|
|
57
|
-
"type": "string"
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
],
|
|
61
|
-
"responses": {
|
|
62
|
-
"200": {
|
|
63
|
-
"description": "OK"
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
"/localizationTexts:list": {
|
|
69
|
-
"get": {
|
|
70
|
-
"tags": ["localizationTexts"],
|
|
71
|
-
"description": "Retrive localization texts with translations",
|
|
72
|
-
"parameters": [
|
|
73
|
-
{
|
|
74
|
-
"name": "X-Locale",
|
|
75
|
-
"in": "header",
|
|
76
|
-
"defalut": "en-US",
|
|
77
|
-
"schema": {
|
|
78
|
-
"type": "string"
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
"name": "keyword",
|
|
83
|
-
"in": "query",
|
|
84
|
-
"description": "Search keyword",
|
|
85
|
-
"schema": {
|
|
86
|
-
"type": "string"
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
"name": "hasTranslation",
|
|
91
|
-
"in": "query",
|
|
92
|
-
"description": "true - list all, false - list only untranslated",
|
|
93
|
-
"schema": {
|
|
94
|
-
"type": "boolean"
|
|
95
|
-
},
|
|
96
|
-
"defalut": true
|
|
97
|
-
}
|
|
98
|
-
],
|
|
99
|
-
"responses": {
|
|
100
|
-
"200": {
|
|
101
|
-
"description": "OK"
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
"/localizationTranslations:updateOrCreate": {
|
|
107
|
-
"post": {
|
|
108
|
-
"tags": ["localizationTranslations"],
|
|
109
|
-
"description": "Update or create localization translations",
|
|
110
|
-
"parameters": [
|
|
111
|
-
{
|
|
112
|
-
"name": "textId",
|
|
113
|
-
"in": "query",
|
|
114
|
-
"schema": {
|
|
115
|
-
"type": "integer"
|
|
116
|
-
},
|
|
117
|
-
"required": true
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
"name": "locale",
|
|
121
|
-
"in": "query",
|
|
122
|
-
"schema": {
|
|
123
|
-
"type": "string"
|
|
124
|
-
},
|
|
125
|
-
"required": true
|
|
126
|
-
}
|
|
127
|
-
],
|
|
128
|
-
"requestBody": {
|
|
129
|
-
"content": {
|
|
130
|
-
"application/json": {
|
|
131
|
-
"schema": {
|
|
132
|
-
"type": "object",
|
|
133
|
-
"properties": {
|
|
134
|
-
"textId": {
|
|
135
|
-
"type": "integer"
|
|
136
|
-
},
|
|
137
|
-
"locale": {
|
|
138
|
-
"type": "string"
|
|
139
|
-
},
|
|
140
|
-
"translation": {
|
|
141
|
-
"type": "string"
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
"responses": {
|
|
149
|
-
"200": {
|
|
150
|
-
"description": "OK"
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|