@payload-enchants/translator 0.0.1-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -0
- package/README.md +193 -0
- package/dist/client/api/index.d.ts +8 -0
- package/dist/client/api/index.d.ts.map +1 -0
- package/dist/client/api/index.js +28 -0
- package/dist/client/api/index.js.map +1 -0
- package/dist/client/components/CustomSaveButton/CustomSaveButton.d.ts +4 -0
- package/dist/client/components/CustomSaveButton/CustomSaveButton.d.ts.map +1 -0
- package/dist/client/components/CustomSaveButton/CustomSaveButton.js +22 -0
- package/dist/client/components/CustomSaveButton/CustomSaveButton.js.map +1 -0
- package/dist/client/components/CustomSaveButton/index.d.ts +2 -0
- package/dist/client/components/CustomSaveButton/index.d.ts.map +1 -0
- package/dist/client/components/CustomSaveButton/index.js +3 -0
- package/dist/client/components/CustomSaveButton/index.js.map +1 -0
- package/dist/client/components/CustomSaveButton/styles.scss +5 -0
- package/dist/client/components/LocaleLabel/LocaleLabel.d.ts +6 -0
- package/dist/client/components/LocaleLabel/LocaleLabel.d.ts.map +1 -0
- package/dist/client/components/LocaleLabel/LocaleLabel.js +19 -0
- package/dist/client/components/LocaleLabel/LocaleLabel.js.map +1 -0
- package/dist/client/components/LocaleLabel/index.d.ts +2 -0
- package/dist/client/components/LocaleLabel/index.d.ts.map +1 -0
- package/dist/client/components/LocaleLabel/index.js +3 -0
- package/dist/client/components/LocaleLabel/index.js.map +1 -0
- package/dist/client/components/ResolverButton/ResolverButton.d.ts +6 -0
- package/dist/client/components/ResolverButton/ResolverButton.d.ts.map +1 -0
- package/dist/client/components/ResolverButton/ResolverButton.js +16 -0
- package/dist/client/components/ResolverButton/ResolverButton.js.map +1 -0
- package/dist/client/components/ResolverButton/index.d.ts +2 -0
- package/dist/client/components/ResolverButton/index.d.ts.map +1 -0
- package/dist/client/components/ResolverButton/index.js +3 -0
- package/dist/client/components/ResolverButton/index.js.map +1 -0
- package/dist/client/components/TranslatorModal/Content.d.ts +3 -0
- package/dist/client/components/TranslatorModal/Content.d.ts.map +1 -0
- package/dist/client/components/TranslatorModal/Content.js +42 -0
- package/dist/client/components/TranslatorModal/Content.js.map +1 -0
- package/dist/client/components/TranslatorModal/TranslatorModal.d.ts +4 -0
- package/dist/client/components/TranslatorModal/TranslatorModal.d.ts.map +1 -0
- package/dist/client/components/TranslatorModal/TranslatorModal.js +21 -0
- package/dist/client/components/TranslatorModal/TranslatorModal.js.map +1 -0
- package/dist/client/components/TranslatorModal/index.d.ts +2 -0
- package/dist/client/components/TranslatorModal/index.d.ts.map +1 -0
- package/dist/client/components/TranslatorModal/index.js +3 -0
- package/dist/client/components/TranslatorModal/index.js.map +1 -0
- package/dist/client/components/TranslatorModal/styles.scss +76 -0
- package/dist/client/providers/Translator/TranslatorProvider.d.ts +5 -0
- package/dist/client/providers/Translator/TranslatorProvider.d.ts.map +1 -0
- package/dist/client/providers/Translator/TranslatorProvider.js +100 -0
- package/dist/client/providers/Translator/TranslatorProvider.js.map +1 -0
- package/dist/client/providers/Translator/context.d.ts +22 -0
- package/dist/client/providers/Translator/context.d.ts.map +1 -0
- package/dist/client/providers/Translator/context.js +9 -0
- package/dist/client/providers/Translator/context.js.map +1 -0
- package/dist/i18n-translations.d.ts +25 -0
- package/dist/i18n-translations.d.ts.map +1 -0
- package/dist/i18n-translations.js +26 -0
- package/dist/i18n-translations.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/dist/resolvers/copy.d.ts +3 -0
- package/dist/resolvers/copy.d.ts.map +1 -0
- package/dist/resolvers/copy.js +14 -0
- package/dist/resolvers/copy.js.map +1 -0
- package/dist/resolvers/google.d.ts +11 -0
- package/dist/resolvers/google.d.ts.map +1 -0
- package/dist/resolvers/google.js +47 -0
- package/dist/resolvers/google.js.map +1 -0
- package/dist/resolvers/openAI.d.ts +21 -0
- package/dist/resolvers/openAI.d.ts.map +1 -0
- package/dist/resolvers/openAI.js +97 -0
- package/dist/resolvers/openAI.js.map +1 -0
- package/dist/resolvers/types.d.ts +20 -0
- package/dist/resolvers/types.d.ts.map +1 -0
- package/dist/resolvers/types.js +3 -0
- package/dist/resolvers/types.js.map +1 -0
- package/dist/translate/endpoint.d.ts +3 -0
- package/dist/translate/endpoint.d.ts.map +1 -0
- package/dist/translate/endpoint.js +22 -0
- package/dist/translate/endpoint.js.map +1 -0
- package/dist/translate/findEntityWithConfig.d.ts +15 -0
- package/dist/translate/findEntityWithConfig.d.ts.map +1 -0
- package/dist/translate/findEntityWithConfig.js +32 -0
- package/dist/translate/findEntityWithConfig.js.map +1 -0
- package/dist/translate/operation.d.ts +9 -0
- package/dist/translate/operation.d.ts.map +1 -0
- package/dist/translate/operation.js +74 -0
- package/dist/translate/operation.js.map +1 -0
- package/dist/translate/traverseFields.d.ts +13 -0
- package/dist/translate/traverseFields.d.ts.map +1 -0
- package/dist/translate/traverseFields.js +160 -0
- package/dist/translate/traverseFields.js.map +1 -0
- package/dist/translate/traverseRichText.d.ts +6 -0
- package/dist/translate/traverseRichText.d.ts.map +1 -0
- package/dist/translate/traverseRichText.js +17 -0
- package/dist/translate/traverseRichText.js.map +1 -0
- package/dist/translate/types.d.ts +25 -0
- package/dist/translate/types.d.ts.map +1 -0
- package/dist/translate/types.js +3 -0
- package/dist/translate/types.js.map +1 -0
- package/dist/translate/updateEntity.d.ts +14 -0
- package/dist/translate/updateEntity.d.ts.map +1 -0
- package/dist/translate/updateEntity.js +26 -0
- package/dist/translate/updateEntity.js.map +1 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/chunkArray.d.ts +2 -0
- package/dist/utils/chunkArray.d.ts.map +1 -0
- package/dist/utils/chunkArray.js +7 -0
- package/dist/utils/chunkArray.js.map +1 -0
- package/dist/utils/isEmpty.d.ts +2 -0
- package/dist/utils/isEmpty.d.ts.map +1 -0
- package/dist/utils/isEmpty.js +8 -0
- package/dist/utils/isEmpty.js.map +1 -0
- package/package.json +75 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/translate/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAMrD,eAAO,MAAM,iBAAiB,EAAE,cAqB/B,CAAC"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { APIError } from 'payload/errors';
|
2
|
+
import { translateOperation } from './operation';
|
3
|
+
export const translateEndpoint = async (req)=>{
|
4
|
+
if (!req.json) throw new APIError('Content-Type should be json');
|
5
|
+
const args = await req.json();
|
6
|
+
const { collectionSlug, emptyOnly, globalSlug, id, locale, localeFrom, resolver } = args;
|
7
|
+
const result = await translateOperation({
|
8
|
+
collectionSlug,
|
9
|
+
emptyOnly,
|
10
|
+
globalSlug,
|
11
|
+
id,
|
12
|
+
locale,
|
13
|
+
localeFrom,
|
14
|
+
overrideAccess: false,
|
15
|
+
req,
|
16
|
+
resolver,
|
17
|
+
update: false
|
18
|
+
});
|
19
|
+
return Response.json(result);
|
20
|
+
};
|
21
|
+
|
22
|
+
//# sourceMappingURL=endpoint.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/translate/endpoint.ts"],"sourcesContent":["import type { PayloadHandler } from 'payload/config';\r\nimport { APIError } from 'payload/errors';\r\n\r\nimport { translateOperation } from './operation';\r\nimport type { TranslateEndpointArgs } from './types';\r\n\r\nexport const translateEndpoint: PayloadHandler = async (req) => {\r\n if (!req.json) throw new APIError('Content-Type should be json');\r\n\r\n const args: TranslateEndpointArgs = await req.json();\r\n\r\n const { collectionSlug, emptyOnly, globalSlug, id, locale, localeFrom, resolver } = args;\r\n\r\n const result = await translateOperation({\r\n collectionSlug,\r\n emptyOnly,\r\n globalSlug,\r\n id,\r\n locale,\r\n localeFrom,\r\n overrideAccess: false,\r\n req,\r\n resolver,\r\n update: false,\r\n });\r\n\r\n return Response.json(result);\r\n};\r\n"],"names":["APIError","translateOperation","translateEndpoint","req","json","args","collectionSlug","emptyOnly","globalSlug","id","locale","localeFrom","resolver","result","overrideAccess","update","Response"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,QAAQ,QAAQ,iBAAiB;AAE1C,SAASC,kBAAkB,QAAQ,cAAc;AAGjD,OAAO,MAAMC,oBAAoC,OAAOC;IACtD,IAAI,CAACA,IAAIC,IAAI,EAAE,MAAM,IAAIJ,SAAS;IAElC,MAAMK,OAA8B,MAAMF,IAAIC,IAAI;IAElD,MAAM,EAAEE,cAAc,EAAEC,SAAS,EAAEC,UAAU,EAAEC,EAAE,EAAEC,MAAM,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAGP;IAEpF,MAAMQ,SAAS,MAAMZ,mBAAmB;QACtCK;QACAC;QACAC;QACAC;QACAC;QACAC;QACAG,gBAAgB;QAChBX;QACAS;QACAG,QAAQ;IACV;IAEA,OAAOC,SAASZ,IAAI,CAACS;AACvB,EAAE"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import type { PayloadRequest, SanitizedCollectionConfig, SanitizedGlobalConfig, TypeWithID } from 'payload/types';
|
2
|
+
type Args = {
|
3
|
+
collectionSlug?: string;
|
4
|
+
globalSlug?: string;
|
5
|
+
id?: number | string;
|
6
|
+
locale: string;
|
7
|
+
overrideAccess?: boolean;
|
8
|
+
req: PayloadRequest;
|
9
|
+
};
|
10
|
+
export declare const findEntityWithConfig: (args: Args) => Promise<{
|
11
|
+
config: SanitizedCollectionConfig | SanitizedGlobalConfig;
|
12
|
+
doc: Record<string, unknown> & TypeWithID;
|
13
|
+
}>;
|
14
|
+
export {};
|
15
|
+
//# sourceMappingURL=findEntityWithConfig.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"findEntityWithConfig.d.ts","sourceRoot":"","sources":["../../src/translate/findEntityWithConfig.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,yBAAyB,EACzB,qBAAqB,EACrB,UAAU,EACX,MAAM,eAAe,CAAC;AAEvB,KAAK,IAAI,GAAG;IACV,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,GAAG,EAAE,cAAc,CAAC;CACrB,CAAC;AAOF,eAAO,MAAM,oBAAoB,SACzB,IAAI,KACT,QAAQ;IACT,MAAM,EAAE,yBAAyB,GAAG,qBAAqB,CAAC;IAC1D,GAAG,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAAC;CAC3C,CAwCA,CAAC"}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { APIError } from 'payload/errors';
|
2
|
+
const findConfigBySlug = (slug, enities)=>enities.find((entity)=>entity.slug === slug);
|
3
|
+
export const findEntityWithConfig = async (args)=>{
|
4
|
+
const { collectionSlug, globalSlug, id, locale, overrideAccess, req } = args;
|
5
|
+
if (!collectionSlug && !globalSlug) throw new APIError('Bad Request', 400);
|
6
|
+
const { payload } = req;
|
7
|
+
const { config } = payload;
|
8
|
+
const isGlobal = !!globalSlug;
|
9
|
+
if (!isGlobal && !id) throw new APIError('Bad Request', 400);
|
10
|
+
const entityConfig = isGlobal ? findConfigBySlug(globalSlug, config.globals) : findConfigBySlug(collectionSlug, config.collections);
|
11
|
+
if (!entityConfig) throw new APIError('Bad Request', 400);
|
12
|
+
const docPromise = isGlobal ? payload.findGlobal({
|
13
|
+
depth: 0,
|
14
|
+
locale,
|
15
|
+
overrideAccess,
|
16
|
+
req,
|
17
|
+
slug: args.globalSlug
|
18
|
+
}) : payload.findByID({
|
19
|
+
collection: collectionSlug,
|
20
|
+
depth: 0,
|
21
|
+
id: id,
|
22
|
+
locale,
|
23
|
+
overrideAccess,
|
24
|
+
req
|
25
|
+
});
|
26
|
+
return {
|
27
|
+
config: entityConfig,
|
28
|
+
doc: await docPromise
|
29
|
+
};
|
30
|
+
};
|
31
|
+
|
32
|
+
//# sourceMappingURL=findEntityWithConfig.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/translate/findEntityWithConfig.ts"],"sourcesContent":["import { APIError } from 'payload/errors';\r\nimport type {\r\n PayloadRequest,\r\n SanitizedCollectionConfig,\r\n SanitizedGlobalConfig,\r\n TypeWithID,\r\n} from 'payload/types';\r\n\r\ntype Args = {\r\n collectionSlug?: string;\r\n globalSlug?: string;\r\n id?: number | string;\r\n locale: string;\r\n overrideAccess?: boolean;\r\n req: PayloadRequest;\r\n};\r\n\r\nconst findConfigBySlug = (\r\n slug: string,\r\n enities: SanitizedCollectionConfig[] | SanitizedGlobalConfig[],\r\n) => enities.find((entity) => entity.slug === slug);\r\n\r\nexport const findEntityWithConfig = async (\r\n args: Args,\r\n): Promise<{\r\n config: SanitizedCollectionConfig | SanitizedGlobalConfig;\r\n doc: Record<string, unknown> & TypeWithID;\r\n}> => {\r\n const { collectionSlug, globalSlug, id, locale, overrideAccess, req } = args;\r\n\r\n if (!collectionSlug && !globalSlug) throw new APIError('Bad Request', 400);\r\n\r\n const { payload } = req;\r\n\r\n const { config } = payload;\r\n\r\n const isGlobal = !!globalSlug;\r\n\r\n if (!isGlobal && !id) throw new APIError('Bad Request', 400);\r\n\r\n const entityConfig = isGlobal\r\n ? findConfigBySlug(globalSlug, config.globals)\r\n : findConfigBySlug(collectionSlug as string, config.collections);\r\n\r\n if (!entityConfig) throw new APIError('Bad Request', 400);\r\n\r\n const docPromise = isGlobal\r\n ? payload.findGlobal({\r\n depth: 0,\r\n locale,\r\n overrideAccess,\r\n req,\r\n slug: args.globalSlug as string,\r\n })\r\n : payload.findByID({\r\n collection: collectionSlug as string,\r\n depth: 0,\r\n id: id as number | string,\r\n locale,\r\n overrideAccess,\r\n req,\r\n });\r\n\r\n return {\r\n config: entityConfig,\r\n doc: await docPromise,\r\n };\r\n};\r\n"],"names":["APIError","findConfigBySlug","slug","enities","find","entity","findEntityWithConfig","args","collectionSlug","globalSlug","id","locale","overrideAccess","req","payload","config","isGlobal","entityConfig","globals","collections","docPromise","findGlobal","depth","findByID","collection","doc"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,QAAQ,QAAQ,iBAAiB;AAiB1C,MAAMC,mBAAmB,CACvBC,MACAC,UACGA,QAAQC,IAAI,CAAC,CAACC,SAAWA,OAAOH,IAAI,KAAKA;AAE9C,OAAO,MAAMI,uBAAuB,OAClCC;IAKA,MAAM,EAAEC,cAAc,EAAEC,UAAU,EAAEC,EAAE,EAAEC,MAAM,EAAEC,cAAc,EAAEC,GAAG,EAAE,GAAGN;IAExE,IAAI,CAACC,kBAAkB,CAACC,YAAY,MAAM,IAAIT,SAAS,eAAe;IAEtE,MAAM,EAAEc,OAAO,EAAE,GAAGD;IAEpB,MAAM,EAAEE,MAAM,EAAE,GAAGD;IAEnB,MAAME,WAAW,CAAC,CAACP;IAEnB,IAAI,CAACO,YAAY,CAACN,IAAI,MAAM,IAAIV,SAAS,eAAe;IAExD,MAAMiB,eAAeD,WACjBf,iBAAiBQ,YAAYM,OAAOG,OAAO,IAC3CjB,iBAAiBO,gBAA0BO,OAAOI,WAAW;IAEjE,IAAI,CAACF,cAAc,MAAM,IAAIjB,SAAS,eAAe;IAErD,MAAMoB,aAAaJ,WACfF,QAAQO,UAAU,CAAC;QACjBC,OAAO;QACPX;QACAC;QACAC;QACAX,MAAMK,KAAKE,UAAU;IACvB,KACAK,QAAQS,QAAQ,CAAC;QACfC,YAAYhB;QACZc,OAAO;QACPZ,IAAIA;QACJC;QACAC;QACAC;IACF;IAEJ,OAAO;QACLE,QAAQE;QACRQ,KAAK,MAAML;IACb;AACF,EAAE"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import type { Payload, PayloadRequest } from 'payload/types';
|
2
|
+
import type { TranslateArgs, TranslateResult } from './types';
|
3
|
+
export type TranslateOperationArgs = ({
|
4
|
+
payload: Payload;
|
5
|
+
} | {
|
6
|
+
req: PayloadRequest;
|
7
|
+
}) & TranslateArgs;
|
8
|
+
export declare const translateOperation: (args: TranslateOperationArgs) => Promise<TranslateResult>;
|
9
|
+
//# sourceMappingURL=operation.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/translate/operation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAK7D,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAoB,MAAM,SAAS,CAAC;AAGhF,MAAM,MAAM,sBAAsB,GAAG,CACjC;IACE,OAAO,EAAE,OAAO,CAAC;CAClB,GACD;IACE,GAAG,EAAE,cAAc,CAAC;CACrB,CACJ,GACC,aAAa,CAAC;AAEhB,eAAO,MAAM,kBAAkB,SAAgB,sBAAsB,6BAuFpE,CAAC"}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import { APIError } from 'payload/errors';
|
2
|
+
import { findEntityWithConfig } from './findEntityWithConfig';
|
3
|
+
import { traverseFields } from './traverseFields';
|
4
|
+
import { updateEntity } from './updateEntity';
|
5
|
+
export const translateOperation = async (args)=>{
|
6
|
+
const req = 'req' in args ? args.req : {
|
7
|
+
payload: args.payload
|
8
|
+
};
|
9
|
+
const { collectionSlug, globalSlug, id, locale, localeFrom, overrideAccess } = args;
|
10
|
+
const { config, doc: dataFrom } = await findEntityWithConfig({
|
11
|
+
collectionSlug,
|
12
|
+
globalSlug,
|
13
|
+
id,
|
14
|
+
locale: localeFrom,
|
15
|
+
req
|
16
|
+
});
|
17
|
+
const resolver = (req.payload.config.custom?.translator?.resolvers ?? []).find((each)=>each.key === args.resolver);
|
18
|
+
if (!resolver) throw new APIError(`Resolver with the key ${args.resolver} was not found`);
|
19
|
+
const valuesToTranslate = [];
|
20
|
+
let translatedData = args.data;
|
21
|
+
if (!translatedData) {
|
22
|
+
const { doc } = await findEntityWithConfig({
|
23
|
+
collectionSlug,
|
24
|
+
globalSlug,
|
25
|
+
id,
|
26
|
+
locale,
|
27
|
+
overrideAccess,
|
28
|
+
req
|
29
|
+
});
|
30
|
+
translatedData = doc;
|
31
|
+
}
|
32
|
+
traverseFields({
|
33
|
+
dataFrom,
|
34
|
+
emptyOnly: args.emptyOnly,
|
35
|
+
fields: config.fields,
|
36
|
+
translatedData,
|
37
|
+
valuesToTranslate
|
38
|
+
});
|
39
|
+
const resolveResult = await resolver.resolve({
|
40
|
+
localeFrom: args.localeFrom,
|
41
|
+
localeTo: args.locale,
|
42
|
+
req,
|
43
|
+
texts: valuesToTranslate.map((each)=>each.value)
|
44
|
+
});
|
45
|
+
let result;
|
46
|
+
if (!resolveResult.success) {
|
47
|
+
result = {
|
48
|
+
success: false
|
49
|
+
};
|
50
|
+
} else {
|
51
|
+
resolveResult.translatedTexts.forEach((translated, index)=>{
|
52
|
+
valuesToTranslate[index].onTranslate(translated);
|
53
|
+
});
|
54
|
+
if (args.update) {
|
55
|
+
await updateEntity({
|
56
|
+
collectionSlug,
|
57
|
+
data: translatedData,
|
58
|
+
depth: 0,
|
59
|
+
globalSlug,
|
60
|
+
id,
|
61
|
+
locale,
|
62
|
+
overrideAccess,
|
63
|
+
req
|
64
|
+
});
|
65
|
+
}
|
66
|
+
result = {
|
67
|
+
success: true,
|
68
|
+
translatedData
|
69
|
+
};
|
70
|
+
}
|
71
|
+
return result;
|
72
|
+
};
|
73
|
+
|
74
|
+
//# sourceMappingURL=operation.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/translate/operation.ts"],"sourcesContent":["import { APIError } from 'payload/errors';\r\nimport type { Payload, PayloadRequest } from 'payload/types';\r\n\r\nimport type { TranslateResolver } from '../resolvers/types';\r\nimport { findEntityWithConfig } from './findEntityWithConfig';\r\nimport { traverseFields } from './traverseFields';\r\nimport type { TranslateArgs, TranslateResult, ValueToTranslate } from './types';\r\nimport { updateEntity } from './updateEntity';\r\n\r\nexport type TranslateOperationArgs = (\r\n | {\r\n payload: Payload;\r\n }\r\n | {\r\n req: PayloadRequest;\r\n }\r\n) &\r\n TranslateArgs;\r\n\r\nexport const translateOperation = async (args: TranslateOperationArgs) => {\r\n const req: PayloadRequest =\r\n 'req' in args\r\n ? args.req\r\n : ({\r\n payload: args.payload,\r\n } as PayloadRequest);\r\n\r\n const { collectionSlug, globalSlug, id, locale, localeFrom, overrideAccess } = args;\r\n\r\n const { config, doc: dataFrom } = await findEntityWithConfig({\r\n collectionSlug,\r\n globalSlug,\r\n id,\r\n locale: localeFrom,\r\n req,\r\n });\r\n\r\n const resolver = (\r\n (req.payload.config.custom?.translator?.resolvers as TranslateResolver[]) ?? []\r\n ).find((each) => each.key === args.resolver);\r\n\r\n if (!resolver) throw new APIError(`Resolver with the key ${args.resolver} was not found`);\r\n\r\n const valuesToTranslate: ValueToTranslate[] = [];\r\n\r\n let translatedData = args.data;\r\n\r\n if (!translatedData) {\r\n const { doc } = await findEntityWithConfig({\r\n collectionSlug,\r\n globalSlug,\r\n id,\r\n locale,\r\n overrideAccess,\r\n req,\r\n });\r\n\r\n translatedData = doc;\r\n }\r\n\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly: args.emptyOnly,\r\n fields: config.fields,\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n\r\n const resolveResult = await resolver.resolve({\r\n localeFrom: args.localeFrom,\r\n localeTo: args.locale,\r\n req,\r\n texts: valuesToTranslate.map((each) => each.value),\r\n });\r\n\r\n let result: TranslateResult;\r\n\r\n if (!resolveResult.success) {\r\n result = {\r\n success: false,\r\n };\r\n } else {\r\n resolveResult.translatedTexts.forEach((translated, index) => {\r\n valuesToTranslate[index].onTranslate(translated);\r\n });\r\n\r\n if (args.update) {\r\n await updateEntity({\r\n collectionSlug,\r\n data: translatedData,\r\n depth: 0,\r\n globalSlug,\r\n id,\r\n locale,\r\n overrideAccess,\r\n req,\r\n });\r\n }\r\n\r\n result = {\r\n success: true,\r\n translatedData,\r\n };\r\n }\r\n\r\n return result;\r\n};\r\n"],"names":["APIError","findEntityWithConfig","traverseFields","updateEntity","translateOperation","args","req","payload","collectionSlug","globalSlug","id","locale","localeFrom","overrideAccess","config","doc","dataFrom","resolver","custom","translator","resolvers","find","each","key","valuesToTranslate","translatedData","data","emptyOnly","fields","resolveResult","resolve","localeTo","texts","map","value","result","success","translatedTexts","forEach","translated","index","onTranslate","update","depth"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,QAAQ,QAAQ,iBAAiB;AAI1C,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,cAAc,QAAQ,mBAAmB;AAElD,SAASC,YAAY,QAAQ,iBAAiB;AAY9C,OAAO,MAAMC,qBAAqB,OAAOC;IACvC,MAAMC,MACJ,SAASD,OACLA,KAAKC,GAAG,GACP;QACCC,SAASF,KAAKE,OAAO;IACvB;IAEN,MAAM,EAAEC,cAAc,EAAEC,UAAU,EAAEC,EAAE,EAAEC,MAAM,EAAEC,UAAU,EAAEC,cAAc,EAAE,GAAGR;IAE/E,MAAM,EAAES,MAAM,EAAEC,KAAKC,QAAQ,EAAE,GAAG,MAAMf,qBAAqB;QAC3DO;QACAC;QACAC;QACAC,QAAQC;QACRN;IACF;IAEA,MAAMW,WAAW,AACf,CAAA,AAACX,IAAIC,OAAO,CAACO,MAAM,CAACI,MAAM,EAAEC,YAAYC,aAAqC,EAAE,AAAD,EAC9EC,IAAI,CAAC,CAACC,OAASA,KAAKC,GAAG,KAAKlB,KAAKY,QAAQ;IAE3C,IAAI,CAACA,UAAU,MAAM,IAAIjB,SAAS,CAAC,sBAAsB,EAAEK,KAAKY,QAAQ,CAAC,cAAc,CAAC;IAExF,MAAMO,oBAAwC,EAAE;IAEhD,IAAIC,iBAAiBpB,KAAKqB,IAAI;IAE9B,IAAI,CAACD,gBAAgB;QACnB,MAAM,EAAEV,GAAG,EAAE,GAAG,MAAMd,qBAAqB;YACzCO;YACAC;YACAC;YACAC;YACAE;YACAP;QACF;QAEAmB,iBAAiBV;IACnB;IAEAb,eAAe;QACbc;QACAW,WAAWtB,KAAKsB,SAAS;QACzBC,QAAQd,OAAOc,MAAM;QACrBH;QACAD;IACF;IAEA,MAAMK,gBAAgB,MAAMZ,SAASa,OAAO,CAAC;QAC3ClB,YAAYP,KAAKO,UAAU;QAC3BmB,UAAU1B,KAAKM,MAAM;QACrBL;QACA0B,OAAOR,kBAAkBS,GAAG,CAAC,CAACX,OAASA,KAAKY,KAAK;IACnD;IAEA,IAAIC;IAEJ,IAAI,CAACN,cAAcO,OAAO,EAAE;QAC1BD,SAAS;YACPC,SAAS;QACX;IACF,OAAO;QACLP,cAAcQ,eAAe,CAACC,OAAO,CAAC,CAACC,YAAYC;YACjDhB,iBAAiB,CAACgB,MAAM,CAACC,WAAW,CAACF;QACvC;QAEA,IAAIlC,KAAKqC,MAAM,EAAE;YACf,MAAMvC,aAAa;gBACjBK;gBACAkB,MAAMD;gBACNkB,OAAO;gBACPlC;gBACAC;gBACAC;gBACAE;gBACAP;YACF;QACF;QAEA6B,SAAS;YACPC,SAAS;YACTX;QACF;IACF;IAEA,OAAOU;AACT,EAAE"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { type Field } from 'payload/types';
|
2
|
+
import type { ValueToTranslate } from './types';
|
3
|
+
export declare const traverseFields: ({ dataFrom, emptyOnly, fields, localizedParent, siblingDataFrom, siblingDataTranslated, translatedData, valuesToTranslate, }: {
|
4
|
+
dataFrom: Record<string, unknown>;
|
5
|
+
emptyOnly?: boolean;
|
6
|
+
fields: Field[];
|
7
|
+
localizedParent?: boolean;
|
8
|
+
siblingDataFrom?: Record<string, unknown>;
|
9
|
+
siblingDataTranslated?: Record<string, unknown>;
|
10
|
+
translatedData: Record<string, unknown>;
|
11
|
+
valuesToTranslate: ValueToTranslate[];
|
12
|
+
}) => void;
|
13
|
+
//# sourceMappingURL=traverseFields.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/translate/traverseFields.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,KAAK,EAAc,MAAM,eAAe,CAAC;AAIvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,eAAO,MAAM,cAAc,iIASxB;IACD,QAAQ,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,qBAAqB,CAAC,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;IAChD,cAAc,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;CACvC,SAmNA,CAAC"}
|
@@ -0,0 +1,160 @@
|
|
1
|
+
import ObjectID from 'bson-objectid';
|
2
|
+
import { APIError } from 'payload/errors';
|
3
|
+
import { tabHasName } from 'payload/types';
|
4
|
+
import { isEmpty } from '../utils/isEmpty';
|
5
|
+
import { traverseRichText } from './traverseRichText';
|
6
|
+
export const traverseFields = ({ dataFrom, emptyOnly, fields, localizedParent, siblingDataFrom, siblingDataTranslated, translatedData, valuesToTranslate })=>{
|
7
|
+
siblingDataFrom = siblingDataFrom ?? dataFrom;
|
8
|
+
siblingDataTranslated = siblingDataTranslated ?? translatedData;
|
9
|
+
fields.forEach((field)=>{
|
10
|
+
switch(field.type){
|
11
|
+
case 'tabs':
|
12
|
+
field.tabs.forEach((tab)=>{
|
13
|
+
const hasName = tabHasName(tab);
|
14
|
+
const tabDataFrom = hasName ? siblingDataFrom[tab.name] : siblingDataFrom;
|
15
|
+
if (!tabDataFrom) return;
|
16
|
+
const tabDataTranslated = hasName ? siblingDataTranslated[tab.name] ?? {} : siblingDataTranslated;
|
17
|
+
traverseFields({
|
18
|
+
dataFrom,
|
19
|
+
emptyOnly,
|
20
|
+
fields: tab.fields,
|
21
|
+
localizedParent: tab.localized,
|
22
|
+
siblingDataFrom: tabDataFrom,
|
23
|
+
siblingDataTranslated: tabDataTranslated,
|
24
|
+
translatedData,
|
25
|
+
valuesToTranslate
|
26
|
+
});
|
27
|
+
});
|
28
|
+
break;
|
29
|
+
case 'group':
|
30
|
+
const groupDataFrom = siblingDataFrom[field.name];
|
31
|
+
if (!groupDataFrom) break;
|
32
|
+
const groupDataTranslated = siblingDataTranslated[field.name] ?? {};
|
33
|
+
traverseFields({
|
34
|
+
dataFrom,
|
35
|
+
emptyOnly,
|
36
|
+
fields: field.fields,
|
37
|
+
localizedParent: field.localized,
|
38
|
+
siblingDataFrom: groupDataFrom,
|
39
|
+
siblingDataTranslated: groupDataTranslated,
|
40
|
+
translatedData,
|
41
|
+
valuesToTranslate
|
42
|
+
});
|
43
|
+
break;
|
44
|
+
case 'array':
|
45
|
+
const arrayDataFrom = siblingDataFrom[field.name];
|
46
|
+
if (isEmpty(arrayDataFrom)) break;
|
47
|
+
const arrayDataTranslated = [];
|
48
|
+
const currentArrayDataInTranslated = Array.isArray(siblingDataTranslated[field.name]) ? siblingDataTranslated[field.name] : undefined;
|
49
|
+
arrayDataFrom.forEach((item, index)=>{
|
50
|
+
const currentArrayItemInTranslated = currentArrayDataInTranslated?.[index];
|
51
|
+
arrayDataTranslated.push({
|
52
|
+
// ensure ids are different, Postgres doesn't like the same.
|
53
|
+
id: currentArrayItemInTranslated?.id ?? ObjectID().toHexString()
|
54
|
+
});
|
55
|
+
traverseFields({
|
56
|
+
dataFrom,
|
57
|
+
emptyOnly,
|
58
|
+
fields: field.fields,
|
59
|
+
localizedParent: localizedParent ?? field.localized,
|
60
|
+
siblingDataFrom: item,
|
61
|
+
siblingDataTranslated: arrayDataTranslated[index],
|
62
|
+
translatedData,
|
63
|
+
valuesToTranslate
|
64
|
+
});
|
65
|
+
});
|
66
|
+
siblingDataTranslated[field.name] = arrayDataTranslated;
|
67
|
+
break;
|
68
|
+
case 'blocks':
|
69
|
+
const blockDataFrom = siblingDataFrom[field.name];
|
70
|
+
if (isEmpty(blockDataFrom)) break;
|
71
|
+
const currentBlockDataInTranslated = Array.isArray(siblingDataTranslated[field.name]) ? siblingDataTranslated[field.name] : undefined;
|
72
|
+
const blockDataTranslated = [];
|
73
|
+
blockDataFrom.forEach((item, index)=>{
|
74
|
+
const currentBlockItemInTranslated = currentBlockDataInTranslated?.[index];
|
75
|
+
blockDataTranslated.push({
|
76
|
+
blockType: item.blockType,
|
77
|
+
// ensure ids are different, needed with Postgres
|
78
|
+
id: currentBlockItemInTranslated?.id ?? ObjectID().toHexString()
|
79
|
+
});
|
80
|
+
const block = field.blocks.find((each)=>each.slug === item.blockType);
|
81
|
+
if (!block) throw new APIError(`Block with slug ${item.blockType} is not found`);
|
82
|
+
traverseFields({
|
83
|
+
dataFrom,
|
84
|
+
emptyOnly,
|
85
|
+
fields: block.fields,
|
86
|
+
localizedParent,
|
87
|
+
siblingDataFrom: item,
|
88
|
+
siblingDataTranslated: blockDataTranslated[index],
|
89
|
+
translatedData,
|
90
|
+
valuesToTranslate
|
91
|
+
});
|
92
|
+
});
|
93
|
+
siblingDataTranslated[field.name] = blockDataTranslated;
|
94
|
+
break;
|
95
|
+
case 'collapsible':
|
96
|
+
case 'row':
|
97
|
+
traverseFields({
|
98
|
+
dataFrom,
|
99
|
+
emptyOnly,
|
100
|
+
fields: field.fields,
|
101
|
+
localizedParent,
|
102
|
+
siblingDataFrom,
|
103
|
+
siblingDataTranslated,
|
104
|
+
translatedData,
|
105
|
+
valuesToTranslate
|
106
|
+
});
|
107
|
+
break;
|
108
|
+
// long ass cases here we have
|
109
|
+
case 'date':
|
110
|
+
case 'checkbox':
|
111
|
+
case 'json':
|
112
|
+
case 'code':
|
113
|
+
case 'email':
|
114
|
+
case 'number':
|
115
|
+
case 'point':
|
116
|
+
case 'radio':
|
117
|
+
case 'relationship':
|
118
|
+
case 'select':
|
119
|
+
case 'upload':
|
120
|
+
siblingDataTranslated[field.name] = siblingDataFrom[field.name];
|
121
|
+
break;
|
122
|
+
case 'text':
|
123
|
+
case 'textarea':
|
124
|
+
if (!field.localized && !localizedParent && isEmpty(siblingDataFrom[field.name])) return;
|
125
|
+
if (emptyOnly && siblingDataTranslated[field.name]) return;
|
126
|
+
valuesToTranslate.push({
|
127
|
+
onTranslate: (translated)=>{
|
128
|
+
siblingDataTranslated[field.name] = translated;
|
129
|
+
},
|
130
|
+
value: siblingDataFrom[field.name]
|
131
|
+
});
|
132
|
+
break;
|
133
|
+
case 'richText':
|
134
|
+
if (!field.localized && !localizedParent && isEmpty(siblingDataFrom[field.name])) break;
|
135
|
+
if (emptyOnly && siblingDataTranslated[field.name]) return;
|
136
|
+
const richTextDataFrom = siblingDataFrom[field.name];
|
137
|
+
siblingDataTranslated[field.name] = richTextDataFrom;
|
138
|
+
const isSlate = Array.isArray(richTextDataFrom);
|
139
|
+
const isLexical = 'root' in richTextDataFrom;
|
140
|
+
if (!isSlate && !isLexical) break;
|
141
|
+
const root = isLexical ? siblingDataTranslated[field.name].root : siblingDataTranslated[field.name]?.[0];
|
142
|
+
traverseRichText({
|
143
|
+
onText: (siblingData)=>{
|
144
|
+
valuesToTranslate.push({
|
145
|
+
onTranslate: (translated)=>{
|
146
|
+
siblingData.text = translated;
|
147
|
+
},
|
148
|
+
value: siblingData.text
|
149
|
+
});
|
150
|
+
},
|
151
|
+
root
|
152
|
+
});
|
153
|
+
break;
|
154
|
+
default:
|
155
|
+
break;
|
156
|
+
}
|
157
|
+
});
|
158
|
+
};
|
159
|
+
|
160
|
+
//# sourceMappingURL=traverseFields.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/translate/traverseFields.ts"],"sourcesContent":["import ObjectID from 'bson-objectid';\r\nimport { APIError } from 'payload/errors';\r\nimport { type Field, tabHasName } from 'payload/types';\r\n\r\nimport { isEmpty } from '../utils/isEmpty';\r\nimport { traverseRichText } from './traverseRichText';\r\nimport type { ValueToTranslate } from './types';\r\n\r\nexport const traverseFields = ({\r\n dataFrom,\r\n emptyOnly,\r\n fields,\r\n localizedParent,\r\n siblingDataFrom,\r\n siblingDataTranslated,\r\n translatedData,\r\n valuesToTranslate,\r\n}: {\r\n dataFrom: Record<string, unknown>;\r\n emptyOnly?: boolean;\r\n fields: Field[];\r\n localizedParent?: boolean;\r\n siblingDataFrom?: Record<string, unknown>;\r\n siblingDataTranslated?: Record<string, unknown>;\r\n translatedData: Record<string, unknown>;\r\n valuesToTranslate: ValueToTranslate[];\r\n}) => {\r\n siblingDataFrom = siblingDataFrom ?? dataFrom;\r\n siblingDataTranslated = siblingDataTranslated ?? translatedData;\r\n\r\n fields.forEach((field) => {\r\n switch (field.type) {\r\n case 'tabs':\r\n field.tabs.forEach((tab) => {\r\n const hasName = tabHasName(tab);\r\n\r\n const tabDataFrom = hasName\r\n ? (siblingDataFrom[tab.name] as Record<string, unknown>)\r\n : siblingDataFrom;\r\n\r\n if (!tabDataFrom) return;\r\n\r\n const tabDataTranslated = hasName\r\n ? (siblingDataTranslated[tab.name] as Record<string, unknown>) ?? {}\r\n : siblingDataTranslated;\r\n\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: tab.fields,\r\n localizedParent: tab.localized,\r\n siblingDataFrom: tabDataFrom,\r\n siblingDataTranslated: tabDataTranslated,\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n });\r\n\r\n break;\r\n\r\n case 'group':\r\n const groupDataFrom = siblingDataFrom[field.name] as Record<string, unknown>;\r\n\r\n if (!groupDataFrom) break;\r\n\r\n const groupDataTranslated =\r\n (siblingDataTranslated[field.name] as Record<string, unknown>) ?? {};\r\n\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: field.fields,\r\n localizedParent: field.localized,\r\n siblingDataFrom: groupDataFrom,\r\n siblingDataTranslated: groupDataTranslated,\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n\r\n break;\r\n\r\n case 'array':\r\n const arrayDataFrom = siblingDataFrom[field.name] as {\r\n id: string;\r\n }[];\r\n\r\n if (isEmpty(arrayDataFrom)) break;\r\n\r\n const arrayDataTranslated = [] as { id: string }[];\r\n\r\n const currentArrayDataInTranslated = Array.isArray(siblingDataTranslated[field.name])\r\n ? (siblingDataTranslated[field.name] as { id: string }[])\r\n : undefined;\r\n\r\n arrayDataFrom.forEach((item, index) => {\r\n const currentArrayItemInTranslated = currentArrayDataInTranslated?.[index];\r\n\r\n arrayDataTranslated.push({\r\n // ensure ids are different, Postgres doesn't like the same.\r\n id: currentArrayItemInTranslated?.id ?? ObjectID().toHexString(),\r\n });\r\n\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: field.fields,\r\n localizedParent: localizedParent ?? field.localized,\r\n siblingDataFrom: item,\r\n siblingDataTranslated: arrayDataTranslated[index],\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n });\r\n\r\n siblingDataTranslated[field.name] = arrayDataTranslated;\r\n\r\n break;\r\n\r\n case 'blocks':\r\n const blockDataFrom = siblingDataFrom[field.name] as { blockType: string; id: string }[];\r\n\r\n if (isEmpty(blockDataFrom)) break;\r\n\r\n const currentBlockDataInTranslated = Array.isArray(siblingDataTranslated[field.name])\r\n ? (siblingDataTranslated[field.name] as { id: string }[])\r\n : undefined;\r\n\r\n const blockDataTranslated = [] as { blockType: string; id: string }[];\r\n\r\n blockDataFrom.forEach((item, index) => {\r\n const currentBlockItemInTranslated = currentBlockDataInTranslated?.[index];\r\n\r\n blockDataTranslated.push({\r\n blockType: item.blockType,\r\n // ensure ids are different, needed with Postgres\r\n id: currentBlockItemInTranslated?.id ?? ObjectID().toHexString(),\r\n });\r\n\r\n const block = field.blocks.find((each) => each.slug === item.blockType);\r\n\r\n if (!block) throw new APIError(`Block with slug ${item.blockType} is not found`);\r\n\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: block.fields,\r\n localizedParent,\r\n siblingDataFrom: item,\r\n siblingDataTranslated: blockDataTranslated[index],\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n });\r\n\r\n siblingDataTranslated[field.name] = blockDataTranslated;\r\n\r\n break;\r\n\r\n case 'collapsible':\r\n case 'row':\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: field.fields,\r\n localizedParent,\r\n siblingDataFrom,\r\n siblingDataTranslated,\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n break;\r\n\r\n // long ass cases here we have\r\n case 'date':\r\n case 'checkbox':\r\n case 'json':\r\n case 'code':\r\n case 'email':\r\n case 'number':\r\n case 'point':\r\n case 'radio':\r\n case 'relationship':\r\n case 'select':\r\n case 'upload':\r\n siblingDataTranslated[field.name] = siblingDataFrom[field.name];\r\n\r\n break;\r\n\r\n case 'text':\r\n case 'textarea':\r\n if (!field.localized && !localizedParent && isEmpty(siblingDataFrom[field.name])) return;\r\n if (emptyOnly && siblingDataTranslated[field.name]) return;\r\n\r\n valuesToTranslate.push({\r\n onTranslate: (translated: string) => {\r\n siblingDataTranslated[field.name] = translated;\r\n },\r\n value: siblingDataFrom[field.name],\r\n });\r\n break;\r\n\r\n case 'richText':\r\n if (!field.localized && !localizedParent && isEmpty(siblingDataFrom[field.name])) break;\r\n if (emptyOnly && siblingDataTranslated[field.name]) return;\r\n const richTextDataFrom = siblingDataFrom[field.name] as object;\r\n\r\n siblingDataTranslated[field.name] = richTextDataFrom;\r\n const isSlate = Array.isArray(richTextDataFrom);\r\n\r\n const isLexical = 'root' in richTextDataFrom;\r\n\r\n if (!isSlate && !isLexical) break;\r\n\r\n const root = (\r\n isLexical\r\n ? (siblingDataTranslated[field.name] as Record<string, unknown>).root\r\n : (siblingDataTranslated[field.name] as unknown[])?.[0]\r\n ) as Record<string, unknown>;\r\n\r\n traverseRichText({\r\n onText: (siblingData) => {\r\n valuesToTranslate.push({\r\n onTranslate: (translated: string) => {\r\n siblingData.text = translated;\r\n },\r\n value: siblingData.text,\r\n });\r\n },\r\n root,\r\n });\r\n\r\n break;\r\n\r\n default:\r\n break;\r\n }\r\n });\r\n};\r\n"],"names":["ObjectID","APIError","tabHasName","isEmpty","traverseRichText","traverseFields","dataFrom","emptyOnly","fields","localizedParent","siblingDataFrom","siblingDataTranslated","translatedData","valuesToTranslate","forEach","field","type","tabs","tab","hasName","tabDataFrom","name","tabDataTranslated","localized","groupDataFrom","groupDataTranslated","arrayDataFrom","arrayDataTranslated","currentArrayDataInTranslated","Array","isArray","undefined","item","index","currentArrayItemInTranslated","push","id","toHexString","blockDataFrom","currentBlockDataInTranslated","blockDataTranslated","currentBlockItemInTranslated","blockType","block","blocks","find","each","slug","onTranslate","translated","value","richTextDataFrom","isSlate","isLexical","root","onText","siblingData","text"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"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"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"traverseRichText.d.ts","sourceRoot":"","sources":["../../src/translate/traverseRichText.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,mCAI1B;IACD,MAAM,EAAE,CAAC,WAAW,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IACvD,IAAI,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,WAAW,CAAC,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC,SAgBA,CAAC"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
export const traverseRichText = ({ onText, root, siblingData })=>{
|
2
|
+
siblingData = siblingData ?? root;
|
3
|
+
if (siblingData.text) {
|
4
|
+
onText(siblingData);
|
5
|
+
}
|
6
|
+
if (Array.isArray(siblingData?.children)) {
|
7
|
+
siblingData.children.forEach((siblingData)=>{
|
8
|
+
traverseRichText({
|
9
|
+
onText,
|
10
|
+
root,
|
11
|
+
siblingData
|
12
|
+
});
|
13
|
+
});
|
14
|
+
}
|
15
|
+
};
|
16
|
+
|
17
|
+
//# sourceMappingURL=traverseRichText.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/translate/traverseRichText.ts"],"sourcesContent":["export const traverseRichText = ({\r\n onText,\r\n root,\r\n siblingData,\r\n}: {\r\n onText: (siblingData: Record<string, unknown>) => void;\r\n root: Record<string, unknown>;\r\n siblingData?: Record<string, unknown>;\r\n}) => {\r\n siblingData = siblingData ?? root;\r\n\r\n if (siblingData.text) {\r\n onText(siblingData);\r\n }\r\n\r\n if (Array.isArray(siblingData?.children)) {\r\n siblingData.children.forEach((siblingData) => {\r\n traverseRichText({\r\n onText,\r\n root,\r\n siblingData,\r\n });\r\n });\r\n }\r\n};\r\n"],"names":["traverseRichText","onText","root","siblingData","text","Array","isArray","children","forEach"],"rangeMappings":";;;;;;;;;;;;;;","mappings":"AAAA,OAAO,MAAMA,mBAAmB,CAAC,EAC/BC,MAAM,EACNC,IAAI,EACJC,WAAW,EAKZ;IACCA,cAAcA,eAAeD;IAE7B,IAAIC,YAAYC,IAAI,EAAE;QACpBH,OAAOE;IACT;IAEA,IAAIE,MAAMC,OAAO,CAACH,aAAaI,WAAW;QACxCJ,YAAYI,QAAQ,CAACC,OAAO,CAAC,CAACL;YAC5BH,iBAAiB;gBACfC;gBACAC;gBACAC;YACF;QACF;IACF;AACF,EAAE"}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
export type ValueToTranslate = {
|
2
|
+
onTranslate: (translatedValue: any) => void;
|
3
|
+
value: any;
|
4
|
+
};
|
5
|
+
export type TranslateArgs = {
|
6
|
+
collectionSlug?: string;
|
7
|
+
data?: Record<string, any>;
|
8
|
+
emptyOnly?: boolean;
|
9
|
+
globalSlug?: string;
|
10
|
+
id?: number | string;
|
11
|
+
/** active locale */
|
12
|
+
locale: string;
|
13
|
+
localeFrom: string;
|
14
|
+
overrideAccess?: boolean;
|
15
|
+
resolver: string;
|
16
|
+
update?: boolean;
|
17
|
+
};
|
18
|
+
export type TranslateResult = {
|
19
|
+
success: false;
|
20
|
+
} | {
|
21
|
+
success: true;
|
22
|
+
translatedData: Record<string, any>;
|
23
|
+
};
|
24
|
+
export type TranslateEndpointArgs = Omit<TranslateArgs, 'data' | 'update'>;
|
25
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/translate/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,CAAC,eAAe,EAAE,GAAG,KAAK,IAAI,CAAC;IAC5C,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,oBAAoB;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,eAAe,GACvB;IACE,OAAO,EAAE,KAAK,CAAC;CAChB,GACD;IACE,OAAO,EAAE,IAAI,CAAC;IACd,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACrC,CAAC;AAEN,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/translate/types.ts"],"sourcesContent":["export type ValueToTranslate = {\r\n onTranslate: (translatedValue: any) => void;\r\n value: any;\r\n};\r\n\r\nexport type TranslateArgs = {\r\n collectionSlug?: string;\r\n data?: Record<string, any>;\r\n emptyOnly?: boolean;\r\n globalSlug?: string;\r\n id?: number | string;\r\n /** active locale */\r\n locale: string;\r\n localeFrom: string;\r\n overrideAccess?: boolean;\r\n resolver: string;\r\n update?: boolean;\r\n};\r\n\r\nexport type TranslateResult =\r\n | {\r\n success: false;\r\n }\r\n | {\r\n success: true;\r\n translatedData: Record<string, any>;\r\n };\r\n\r\nexport type TranslateEndpointArgs = Omit<TranslateArgs, 'data' | 'update'>;\r\n"],"names":[],"rangeMappings":"","mappings":"AA4BA,WAA2E"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { PayloadRequest, TypeWithID } from 'payload/types';
|
2
|
+
type Args = {
|
3
|
+
collectionSlug?: string;
|
4
|
+
data: Record<string, any>;
|
5
|
+
depth?: number;
|
6
|
+
globalSlug?: string;
|
7
|
+
id?: number | string;
|
8
|
+
locale: string;
|
9
|
+
overrideAccess?: boolean;
|
10
|
+
req: PayloadRequest;
|
11
|
+
};
|
12
|
+
export declare const updateEntity: ({ collectionSlug, data, depth: incomingDepth, globalSlug, id, locale, overrideAccess, req, }: Args) => Promise<Record<string, unknown> & TypeWithID>;
|
13
|
+
export {};
|
14
|
+
//# sourceMappingURL=updateEntity.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"updateEntity.d.ts","sourceRoot":"","sources":["../../src/translate/updateEntity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhE,KAAK,IAAI,GAAG;IACV,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,GAAG,EAAE,cAAc,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,YAAY,iGAStB,IAAI,KAAG,QAAQ,OAAO,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CA6BrD,CAAC"}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { APIError } from 'payload/errors';
|
2
|
+
export const updateEntity = ({ collectionSlug, data, depth: incomingDepth, globalSlug, id, locale, overrideAccess, req })=>{
|
3
|
+
if (!collectionSlug && !globalSlug) throw new APIError('Bad Request', 400);
|
4
|
+
const isGlobal = !!globalSlug;
|
5
|
+
if (!isGlobal && !id) throw new APIError('Bad Request', 400);
|
6
|
+
const depth = incomingDepth ?? req.payload.config.defaultDepth;
|
7
|
+
const promise = isGlobal ? req.payload.updateGlobal({
|
8
|
+
data,
|
9
|
+
depth,
|
10
|
+
locale,
|
11
|
+
overrideAccess,
|
12
|
+
req,
|
13
|
+
slug: globalSlug
|
14
|
+
}) : req.payload.update({
|
15
|
+
collection: collectionSlug,
|
16
|
+
data,
|
17
|
+
depth,
|
18
|
+
id: id,
|
19
|
+
locale,
|
20
|
+
overrideAccess,
|
21
|
+
req
|
22
|
+
});
|
23
|
+
return promise;
|
24
|
+
};
|
25
|
+
|
26
|
+
//# sourceMappingURL=updateEntity.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/translate/updateEntity.ts"],"sourcesContent":["import { APIError } from 'payload/errors';\r\nimport type { PayloadRequest, TypeWithID } from 'payload/types';\r\n\r\ntype Args = {\r\n collectionSlug?: string;\r\n data: Record<string, any>;\r\n depth?: number;\r\n globalSlug?: string;\r\n id?: number | string;\r\n locale: string;\r\n overrideAccess?: boolean;\r\n req: PayloadRequest;\r\n};\r\n\r\nexport const updateEntity = ({\r\n collectionSlug,\r\n data,\r\n depth: incomingDepth,\r\n globalSlug,\r\n id,\r\n locale,\r\n overrideAccess,\r\n req,\r\n}: Args): Promise<Record<string, unknown> & TypeWithID> => {\r\n if (!collectionSlug && !globalSlug) throw new APIError('Bad Request', 400);\r\n\r\n const isGlobal = !!globalSlug;\r\n\r\n if (!isGlobal && !id) throw new APIError('Bad Request', 400);\r\n\r\n const depth = incomingDepth ?? req.payload.config.defaultDepth;\r\n\r\n const promise = isGlobal\r\n ? req.payload.updateGlobal({\r\n data,\r\n depth,\r\n locale,\r\n overrideAccess,\r\n req,\r\n slug: globalSlug as string,\r\n })\r\n : req.payload.update({\r\n collection: collectionSlug as string,\r\n data,\r\n depth,\r\n id: id as number | string,\r\n locale,\r\n overrideAccess,\r\n req,\r\n });\r\n\r\n return promise;\r\n};\r\n"],"names":["APIError","updateEntity","collectionSlug","data","depth","incomingDepth","globalSlug","id","locale","overrideAccess","req","isGlobal","payload","config","defaultDepth","promise","updateGlobal","slug","update","collection"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,QAAQ,QAAQ,iBAAiB;AAc1C,OAAO,MAAMC,eAAe,CAAC,EAC3BC,cAAc,EACdC,IAAI,EACJC,OAAOC,aAAa,EACpBC,UAAU,EACVC,EAAE,EACFC,MAAM,EACNC,cAAc,EACdC,GAAG,EACE;IACL,IAAI,CAACR,kBAAkB,CAACI,YAAY,MAAM,IAAIN,SAAS,eAAe;IAEtE,MAAMW,WAAW,CAAC,CAACL;IAEnB,IAAI,CAACK,YAAY,CAACJ,IAAI,MAAM,IAAIP,SAAS,eAAe;IAExD,MAAMI,QAAQC,iBAAiBK,IAAIE,OAAO,CAACC,MAAM,CAACC,YAAY;IAE9D,MAAMC,UAAUJ,WACZD,IAAIE,OAAO,CAACI,YAAY,CAAC;QACvBb;QACAC;QACAI;QACAC;QACAC;QACAO,MAAMX;IACR,KACAI,IAAIE,OAAO,CAACM,MAAM,CAAC;QACjBC,YAAYjB;QACZC;QACAC;QACAG,IAAIA;QACJC;QACAC;QACAC;IACF;IAEJ,OAAOK;AACT,EAAE"}
|
package/dist/types.d.ts
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { GeneratedTypes } from 'payload';
|
2
|
+
import type { TranslateResolver } from './resolvers/types';
|
3
|
+
export type TranslatorConfig = {
|
4
|
+
/**
|
5
|
+
* Collections with the enabled translator in the admin UI
|
6
|
+
*/
|
7
|
+
collections: (keyof GeneratedTypes['collections'])[];
|
8
|
+
/**
|
9
|
+
* Disable the plugin
|
10
|
+
*/
|
11
|
+
disabled?: boolean;
|
12
|
+
/**
|
13
|
+
* Globals with the enabled translator in the admin UI
|
14
|
+
*/
|
15
|
+
globals: (keyof GeneratedTypes['globals'])[];
|
16
|
+
/**
|
17
|
+
* Add resolvers that you want to include, examples on how to write your own in ./plugin/src/resolvers
|
18
|
+
*/
|
19
|
+
resolvers: TranslateResolver[];
|
20
|
+
};
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,WAAW,EAAE,CAAC,MAAM,cAAc,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC;IACrD;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,OAAO,EAAE,CAAC,MAAM,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;IAC7C;;OAEG;IACH,SAAS,EAAE,iBAAiB,EAAE,CAAC;CAChC,CAAC"}
|
package/dist/types.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { GeneratedTypes } from 'payload';\r\n\r\nimport type { TranslateResolver } from './resolvers/types';\r\n\r\nexport type TranslatorConfig = {\r\n /**\r\n * Collections with the enabled translator in the admin UI\r\n */\r\n collections: (keyof GeneratedTypes['collections'])[];\r\n /**\r\n * Disable the plugin\r\n */\r\n disabled?: boolean;\r\n /**\r\n * Globals with the enabled translator in the admin UI\r\n */\r\n globals: (keyof GeneratedTypes['globals'])[];\r\n /**\r\n * Add resolvers that you want to include, examples on how to write your own in ./plugin/src/resolvers\r\n */\r\n resolvers: TranslateResolver[];\r\n};\r\n"],"names":[],"rangeMappings":"","mappings":"AAIA,WAiBE"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"chunkArray.d.ts","sourceRoot":"","sources":["../../src/utils/chunkArray.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,aAAc,CAAC,EAAE,UAAU,MAAM,KAAG,CAAC,EAAE,EAI7D,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/utils/chunkArray.ts"],"sourcesContent":["export const chunkArray = <T>(array: T[], length: number): T[][] => {\r\n return Array.from({ length: Math.ceil(array.length / length) }, (_, i) =>\r\n array.slice(i * length, i * length + length),\r\n );\r\n};\r\n"],"names":["chunkArray","array","length","Array","from","Math","ceil","_","i","slice"],"rangeMappings":";;;;","mappings":"AAAA,OAAO,MAAMA,aAAa,CAAIC,OAAYC;IACxC,OAAOC,MAAMC,IAAI,CAAC;QAAEF,QAAQG,KAAKC,IAAI,CAACL,MAAMC,MAAM,GAAGA;IAAQ,GAAG,CAACK,GAAGC,IAClEP,MAAMQ,KAAK,CAACD,IAAIN,QAAQM,IAAIN,SAASA;AAEzC,EAAE"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"isEmpty.d.ts","sourceRoot":"","sources":["../../src/utils/isEmpty.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UAAW,OAAO,YAMrC,CAAC"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
export const isEmpty = (value)=>{
|
2
|
+
if (Array.isArray(value)) return value.length === 0;
|
3
|
+
if (value === null || typeof value === 'undefined') return true;
|
4
|
+
if (typeof value === 'object' && Object.keys(value).length === 0) return true;
|
5
|
+
return false;
|
6
|
+
};
|
7
|
+
|
8
|
+
//# sourceMappingURL=isEmpty.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/utils/isEmpty.ts"],"sourcesContent":["export const isEmpty = (value: unknown) => {\r\n if (Array.isArray(value)) return value.length === 0;\r\n if (value === null || typeof value === 'undefined') return true;\r\n if (typeof value === 'object' && Object.keys(value).length === 0) return true;\r\n\r\n return false;\r\n};\r\n"],"names":["isEmpty","value","Array","isArray","length","Object","keys"],"rangeMappings":";;;;;","mappings":"AAAA,OAAO,MAAMA,UAAU,CAACC;IACtB,IAAIC,MAAMC,OAAO,CAACF,QAAQ,OAAOA,MAAMG,MAAM,KAAK;IAClD,IAAIH,UAAU,QAAQ,OAAOA,UAAU,aAAa,OAAO;IAC3D,IAAI,OAAOA,UAAU,YAAYI,OAAOC,IAAI,CAACL,OAAOG,MAAM,KAAK,GAAG,OAAO;IAEzE,OAAO;AACT,EAAE"}
|