@adminforth/i18n 2.0.30 → 2.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/build.log +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +39 -8
- package/index.ts +41 -10
- package/package.json +5 -4
package/build.log
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
61
61
|
tryProcessAndWatch(adminforth: IAdminForth): Promise<void>;
|
|
62
62
|
validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource): void;
|
|
63
63
|
applyPluralization(str: string, number: number, lang: string): string;
|
|
64
|
-
slavicPluralRule(choice: any, choicesLength: any): 0 | 2 | 1
|
|
64
|
+
slavicPluralRule(choice: any, choicesLength: any): 3 | 0 | 2 | 1;
|
|
65
65
|
instanceUniqueRepresentation(pluginOptions: any): string;
|
|
66
66
|
getCategoryTranslations(category: string, lang: string): Promise<Record<string, string>>;
|
|
67
67
|
languagesList(): Promise<{
|
package/dist/index.js
CHANGED
|
@@ -7,8 +7,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { AdminForthPlugin, Filters, suggestIfTypo, AdminForthDataTypes, RAMLock, filtersTools, AdminForthFilterOperators } from "adminforth";
|
|
10
|
+
import { AdminForthPlugin, parseBody, Filters, suggestIfTypo, AdminForthDataTypes, RAMLock, filtersTools, AdminForthFilterOperators } from "adminforth";
|
|
11
|
+
import { z } from "zod";
|
|
11
12
|
import iso6391 from 'iso-639-1';
|
|
13
|
+
const updateFieldBodySchema = z.object({
|
|
14
|
+
resourceId: z.string(),
|
|
15
|
+
recordId: z.union([z.string(), z.number()]),
|
|
16
|
+
field: z.string(),
|
|
17
|
+
value: z.unknown(),
|
|
18
|
+
reviewed: z.boolean().nullish(),
|
|
19
|
+
}).strict();
|
|
20
|
+
const translateSelectedBodySchema = z.object({
|
|
21
|
+
selectedLanguages: z.array(z.string()).optional(),
|
|
22
|
+
selectedIds: z.array(z.union([z.string(), z.number()])),
|
|
23
|
+
}).strict();
|
|
24
|
+
const getFilteredIdsBodySchema = z.object({
|
|
25
|
+
filters: z.any(),
|
|
26
|
+
}).passthrough();
|
|
12
27
|
import path from 'path';
|
|
13
28
|
import fs from 'fs-extra';
|
|
14
29
|
import chokidar from 'chokidar';
|
|
@@ -1021,8 +1036,12 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
1021
1036
|
server.endpoint({
|
|
1022
1037
|
method: 'POST',
|
|
1023
1038
|
path: `/plugin/${this.pluginInstanceId}/update-field`,
|
|
1024
|
-
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers }) {
|
|
1025
|
-
const
|
|
1039
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers, response }) {
|
|
1040
|
+
const parsed = parseBody(updateFieldBodySchema, body, response);
|
|
1041
|
+
if ('error' in parsed)
|
|
1042
|
+
return parsed.error;
|
|
1043
|
+
const data = parsed.data;
|
|
1044
|
+
const { resourceId, recordId, field, value, reviewed } = data;
|
|
1026
1045
|
if (resourceId !== this.resourceConfig.resourceId) {
|
|
1027
1046
|
return { error: 'Invalid resourceId' };
|
|
1028
1047
|
}
|
|
@@ -1076,13 +1095,21 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
1076
1095
|
method: 'POST',
|
|
1077
1096
|
path: `/plugin/${this.pluginInstanceId}/translate-selected-to-languages`,
|
|
1078
1097
|
noAuth: false,
|
|
1079
|
-
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, tr, adminUser }) {
|
|
1080
|
-
const
|
|
1081
|
-
|
|
1098
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, tr, adminUser, response }) {
|
|
1099
|
+
const parsed = parseBody(translateSelectedBodySchema, body, response);
|
|
1100
|
+
if ('error' in parsed)
|
|
1101
|
+
return parsed.error;
|
|
1102
|
+
const data = parsed.data;
|
|
1103
|
+
const selectedLanguages = data.selectedLanguages;
|
|
1104
|
+
const selectedIds = data.selectedIds;
|
|
1082
1105
|
if (!Array.isArray(selectedIds) || selectedIds.length === 0) {
|
|
1083
1106
|
return { ok: false, error: 'No records selected' };
|
|
1084
1107
|
}
|
|
1085
|
-
const jobId = yield this.bulkTranslate({
|
|
1108
|
+
const jobId = yield this.bulkTranslate({
|
|
1109
|
+
selectedIds: selectedIds,
|
|
1110
|
+
selectedLanguages: selectedLanguages,
|
|
1111
|
+
adminUser,
|
|
1112
|
+
});
|
|
1086
1113
|
return {
|
|
1087
1114
|
ok: true,
|
|
1088
1115
|
jobId: jobId,
|
|
@@ -1092,8 +1119,12 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
1092
1119
|
server.endpoint({
|
|
1093
1120
|
method: 'POST',
|
|
1094
1121
|
path: `/plugin/${this.pluginInstanceId}/get_filtered_ids`,
|
|
1095
|
-
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers, query, cookies, requestUrl }) {
|
|
1122
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers, query, cookies, requestUrl, response }) {
|
|
1096
1123
|
var _b, _c;
|
|
1124
|
+
const parsed = parseBody(getFilteredIdsBodySchema, body, response);
|
|
1125
|
+
if ('error' in parsed)
|
|
1126
|
+
return parsed.error;
|
|
1127
|
+
const data = parsed.data;
|
|
1097
1128
|
const resource = this.resourceConfig;
|
|
1098
1129
|
for (const hook of ((_c = (_b = resource.hooks) === null || _b === void 0 ? void 0 : _b.list) === null || _c === void 0 ? void 0 : _c.beforeDatasourceRequest) || []) {
|
|
1099
1130
|
const filterTools = filtersTools.get(body);
|
package/index.ts
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import AdminForth, { AdminForthPlugin, Filters, suggestIfTypo, AdminForthDataTypes, RAMLock, filtersTools, AdminForthFilterOperators } from "adminforth";
|
|
1
|
+
import AdminForth, { AdminForthPlugin, parseBody, Filters, suggestIfTypo, AdminForthDataTypes, RAMLock, filtersTools, AdminForthFilterOperators } from "adminforth";
|
|
2
2
|
import type { IAdminForth, IHttpServer, AdminForthComponentDeclaration, AdminForthResourceColumn, AdminForthResource, BeforeLoginConfirmationFunction, AdminForthConfigMenuItem, AdminUser } from "adminforth";
|
|
3
3
|
import type { PluginOptions, SupportedLanguage } from './types.js';
|
|
4
|
+
import { z } from "zod";
|
|
4
5
|
import iso6391 from 'iso-639-1';
|
|
6
|
+
|
|
7
|
+
const updateFieldBodySchema = z.object({
|
|
8
|
+
resourceId: z.string(),
|
|
9
|
+
recordId: z.union([z.string(), z.number()]),
|
|
10
|
+
field: z.string(),
|
|
11
|
+
value: z.unknown(),
|
|
12
|
+
reviewed: z.boolean().nullish(),
|
|
13
|
+
}).strict();
|
|
14
|
+
|
|
15
|
+
const translateSelectedBodySchema = z.object({
|
|
16
|
+
selectedLanguages: z.array(z.string()).optional(),
|
|
17
|
+
selectedIds: z.array(z.union([z.string(), z.number()])),
|
|
18
|
+
}).strict();
|
|
19
|
+
|
|
20
|
+
const getFilteredIdsBodySchema = z.object({
|
|
21
|
+
filters: z.any(),
|
|
22
|
+
}).passthrough();
|
|
5
23
|
import { iso31661Alpha2ToAlpha3 } from 'iso-3166';
|
|
6
24
|
import path from 'path';
|
|
7
25
|
import fs from 'fs-extra';
|
|
@@ -1252,8 +1270,11 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
1252
1270
|
server.endpoint({
|
|
1253
1271
|
method: 'POST',
|
|
1254
1272
|
path: `/plugin/${this.pluginInstanceId}/update-field`,
|
|
1255
|
-
handler: async ({ body, adminUser, headers }) => {
|
|
1256
|
-
const
|
|
1273
|
+
handler: async ({ body, adminUser, headers, response }) => {
|
|
1274
|
+
const parsed = parseBody(updateFieldBodySchema, body, response);
|
|
1275
|
+
if ('error' in parsed) return parsed.error;
|
|
1276
|
+
const data = parsed.data;
|
|
1277
|
+
const { resourceId, recordId, field, value, reviewed } = data;
|
|
1257
1278
|
if (resourceId !== this.resourceConfig.resourceId) {
|
|
1258
1279
|
return { error: 'Invalid resourceId' };
|
|
1259
1280
|
}
|
|
@@ -1274,7 +1295,7 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
1274
1295
|
let result;
|
|
1275
1296
|
await lock.run(`edit-trans-${recordId}`, async () => {
|
|
1276
1297
|
// put into lock so 2 editors will not update the same record at the same time
|
|
1277
|
-
oldRecord = await connector.getRecordByPrimaryKey(resource, recordId)
|
|
1298
|
+
oldRecord = await connector.getRecordByPrimaryKey(resource, recordId as string)
|
|
1278
1299
|
|
|
1279
1300
|
if (!oldRecord) {
|
|
1280
1301
|
result = { error: 'Record not found' };
|
|
@@ -1305,7 +1326,7 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
1305
1326
|
return { error: result.error };
|
|
1306
1327
|
}
|
|
1307
1328
|
|
|
1308
|
-
const updatedRecord = await connector.getRecordByPrimaryKey(resource, recordId);
|
|
1329
|
+
const updatedRecord = await connector.getRecordByPrimaryKey(resource, recordId as string);
|
|
1309
1330
|
|
|
1310
1331
|
return { record: updatedRecord };
|
|
1311
1332
|
}
|
|
@@ -1315,15 +1336,22 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
1315
1336
|
method: 'POST',
|
|
1316
1337
|
path: `/plugin/${this.pluginInstanceId}/translate-selected-to-languages`,
|
|
1317
1338
|
noAuth: false,
|
|
1318
|
-
handler: async ({ body, tr, adminUser }) => {
|
|
1319
|
-
const
|
|
1320
|
-
|
|
1339
|
+
handler: async ({ body, tr, adminUser, response }) => {
|
|
1340
|
+
const parsed = parseBody(translateSelectedBodySchema, body, response);
|
|
1341
|
+
if ('error' in parsed) return parsed.error;
|
|
1342
|
+
const data = parsed.data;
|
|
1343
|
+
const selectedLanguages = data.selectedLanguages;
|
|
1344
|
+
const selectedIds = data.selectedIds;
|
|
1321
1345
|
|
|
1322
1346
|
if (!Array.isArray(selectedIds) || selectedIds.length === 0) {
|
|
1323
1347
|
return { ok: false, error: 'No records selected' };
|
|
1324
1348
|
}
|
|
1325
1349
|
|
|
1326
|
-
const jobId = await this.bulkTranslate({
|
|
1350
|
+
const jobId = await this.bulkTranslate({
|
|
1351
|
+
selectedIds: selectedIds as string[],
|
|
1352
|
+
selectedLanguages: selectedLanguages as SupportedLanguage[] | undefined,
|
|
1353
|
+
adminUser,
|
|
1354
|
+
});
|
|
1327
1355
|
|
|
1328
1356
|
return {
|
|
1329
1357
|
ok: true,
|
|
@@ -1335,7 +1363,10 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
1335
1363
|
server.endpoint({
|
|
1336
1364
|
method: 'POST',
|
|
1337
1365
|
path: `/plugin/${this.pluginInstanceId}/get_filtered_ids`,
|
|
1338
|
-
handler: async ({ body, adminUser, headers, query, cookies, requestUrl }) => {
|
|
1366
|
+
handler: async ({ body, adminUser, headers, query, cookies, requestUrl, response }) => {
|
|
1367
|
+
const parsed = parseBody(getFilteredIdsBodySchema, body, response);
|
|
1368
|
+
if ('error' in parsed) return parsed.error;
|
|
1369
|
+
const data = parsed.data;
|
|
1339
1370
|
const resource = this.resourceConfig;
|
|
1340
1371
|
|
|
1341
1372
|
for (const hook of resource.hooks?.list?.beforeDatasourceRequest || []) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/i18n",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -35,14 +35,15 @@
|
|
|
35
35
|
"fs-extra": "^11.3.2",
|
|
36
36
|
"iso-3166": "^4.3.0",
|
|
37
37
|
"iso-639-1": "^3.1.3",
|
|
38
|
-
"p-limit": "^7.3.0"
|
|
38
|
+
"p-limit": "^7.3.0",
|
|
39
|
+
"zod": "^4.3.6"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
|
-
"adminforth": "^3.
|
|
42
|
+
"adminforth": "^3.7.1"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@types/node": "^22.10.7",
|
|
45
|
-
"adminforth": "^3.
|
|
46
|
+
"adminforth": "^3.7.1",
|
|
46
47
|
"i18n-iso-countries": "^7.13.0",
|
|
47
48
|
"semantic-release": "^24.2.1",
|
|
48
49
|
"semantic-release-slack-bot": "^4.0.2",
|