@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":"TranslatorProvider.d.ts","sourceRoot":"","sources":["../../../../src/client/providers/Translator/TranslatorProvider.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,SAAS,EAAqB,MAAM,OAAO,CAAC;AAS1D,eAAO,MAAM,kBAAkB,iBAAkB;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,gCA8HvE,CAAC"}
|
@@ -0,0 +1,100 @@
|
|
1
|
+
import { toast } from '@payloadcms/ui/elements';
|
2
|
+
import { useModal } from '@payloadcms/ui/elements/Modal';
|
3
|
+
import { useAllFormFields } from '@payloadcms/ui/forms/Form';
|
4
|
+
import { useConfig } from '@payloadcms/ui/providers/Config';
|
5
|
+
import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
|
6
|
+
import { useLocale } from '@payloadcms/ui/providers/Locale';
|
7
|
+
import { useTranslation } from '@payloadcms/ui/providers/Translation';
|
8
|
+
import { getFormState } from '@payloadcms/ui/utilities/getFormState';
|
9
|
+
import { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues';
|
10
|
+
import { useMemo, useState } from 'react';
|
11
|
+
import { createClient } from '../../api';
|
12
|
+
import { TranslatorContext } from './context';
|
13
|
+
const modalSlug = 'translator-modal';
|
14
|
+
export const TranslatorProvider = ({ children })=>{
|
15
|
+
const [resolver, setResolver] = useState(null);
|
16
|
+
const [data, dispatch] = useAllFormFields();
|
17
|
+
const { collectionSlug, globalSlug, id } = useDocumentInfo();
|
18
|
+
const modal = useModal();
|
19
|
+
const { t } = useTranslation();
|
20
|
+
const resolverT = (key)=>{
|
21
|
+
if (!resolver) return '';
|
22
|
+
return t(`plugin-translator:resolver_${resolver}_${key}`);
|
23
|
+
};
|
24
|
+
const locale = useLocale();
|
25
|
+
const { admin: { custom }, localization, routes: { api }, serverURL } = useConfig();
|
26
|
+
const apiClient = createClient({
|
27
|
+
api,
|
28
|
+
serverURL
|
29
|
+
});
|
30
|
+
const resolverConfig = useMemo(()=>{
|
31
|
+
if (!resolver) return null;
|
32
|
+
const resolvers = custom?.translator?.resolvers || undefined;
|
33
|
+
if (!resolvers) return null;
|
34
|
+
const resolverConfig = resolvers.find((each)=>each.key === resolver);
|
35
|
+
return resolverConfig ?? null;
|
36
|
+
}, [
|
37
|
+
custom,
|
38
|
+
resolver
|
39
|
+
]);
|
40
|
+
if (!localization) throw new Error('Localization config is not provided and PluginTranslator is used');
|
41
|
+
const localesOptions = localization.locales.filter((each)=>each.code !== locale.code);
|
42
|
+
const [localeToTranslateFrom, setLocaleToTranslateFrom] = useState(()=>{
|
43
|
+
const defaultFromOptions = localesOptions.find((each)=>localization.defaultLocale === each.code);
|
44
|
+
if (defaultFromOptions) return defaultFromOptions.code;
|
45
|
+
return localesOptions[0].code;
|
46
|
+
});
|
47
|
+
const closeTranslator = ()=>modal.closeModal(modalSlug);
|
48
|
+
const submit = async ({ emptyOnly })=>{
|
49
|
+
if (!resolver) return;
|
50
|
+
const args = {
|
51
|
+
collectionSlug,
|
52
|
+
data: reduceFieldsToValues(data, true),
|
53
|
+
emptyOnly,
|
54
|
+
globalSlug,
|
55
|
+
id: id === null ? undefined : id,
|
56
|
+
locale: locale.code,
|
57
|
+
localeFrom: localeToTranslateFrom,
|
58
|
+
resolver
|
59
|
+
};
|
60
|
+
const result = await apiClient.translate(args);
|
61
|
+
if (!result.success) {
|
62
|
+
toast.error(resolverT('errorMessage'));
|
63
|
+
return;
|
64
|
+
}
|
65
|
+
dispatch({
|
66
|
+
state: await getFormState({
|
67
|
+
apiRoute: api,
|
68
|
+
body: {
|
69
|
+
collectionSlug,
|
70
|
+
data: result.translatedData,
|
71
|
+
globalSlug,
|
72
|
+
locale: locale.code,
|
73
|
+
schemaPath: collectionSlug || globalSlug || ''
|
74
|
+
},
|
75
|
+
serverURL
|
76
|
+
}),
|
77
|
+
type: 'REPLACE_STATE'
|
78
|
+
});
|
79
|
+
if (resolverConfig) toast.success(resolverT('successMessage'));
|
80
|
+
closeTranslator();
|
81
|
+
};
|
82
|
+
return /*#__PURE__*/ React.createElement(TranslatorContext.Provider, {
|
83
|
+
value: {
|
84
|
+
closeTranslator,
|
85
|
+
localeToTranslateFrom,
|
86
|
+
localesOptions,
|
87
|
+
modalSlug,
|
88
|
+
openTranslator: ({ resolverKey })=>{
|
89
|
+
setResolver(resolverKey);
|
90
|
+
modal.openModal(modalSlug);
|
91
|
+
},
|
92
|
+
resolver: resolverConfig,
|
93
|
+
resolverT,
|
94
|
+
setLocaleToTranslateFrom,
|
95
|
+
submit
|
96
|
+
}
|
97
|
+
}, children);
|
98
|
+
};
|
99
|
+
|
100
|
+
//# sourceMappingURL=TranslatorProvider.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/client/providers/Translator/TranslatorProvider.tsx"],"sourcesContent":["import { toast } from '@payloadcms/ui/elements';\r\nimport { useModal } from '@payloadcms/ui/elements/Modal';\r\nimport { useAllFormFields } from '@payloadcms/ui/forms/Form';\r\nimport { useConfig } from '@payloadcms/ui/providers/Config';\r\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';\r\nimport { useLocale } from '@payloadcms/ui/providers/Locale';\r\nimport { useTranslation } from '@payloadcms/ui/providers/Translation';\r\nimport { getFormState } from '@payloadcms/ui/utilities/getFormState';\r\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues';\r\nimport { type ReactNode, useMemo, useState } from 'react';\r\n\r\nimport type { TranslateResolver } from '../../../resolvers/types';\r\nimport type { TranslateArgs } from '../../../translate/types';\r\nimport { createClient } from '../../api';\r\nimport { TranslatorContext } from './context';\r\n\r\nconst modalSlug = 'translator-modal';\r\n\r\nexport const TranslatorProvider = ({ children }: { children: ReactNode }) => {\r\n const [resolver, setResolver] = useState<null | string>(null);\r\n\r\n const [data, dispatch] = useAllFormFields();\r\n\r\n const { collectionSlug, globalSlug, id } = useDocumentInfo();\r\n\r\n const modal = useModal();\r\n\r\n const { t } = useTranslation();\r\n\r\n const resolverT = (\r\n key:\r\n | 'buttonLabel'\r\n | 'errorMessage'\r\n | 'modalTitle'\r\n | 'submitButtonLabelEmpty'\r\n | 'submitButtonLabelFull'\r\n | 'successMessage',\r\n ) => {\r\n if (!resolver) return '';\r\n\r\n return t(`plugin-translator:resolver_${resolver}_${key}`);\r\n };\r\n\r\n const locale = useLocale();\r\n\r\n const {\r\n admin: { custom },\r\n localization,\r\n routes: { api },\r\n serverURL,\r\n } = useConfig();\r\n\r\n const apiClient = createClient({ api, serverURL });\r\n\r\n const resolverConfig = useMemo(() => {\r\n if (!resolver) return null;\r\n\r\n const resolvers = (custom?.translator?.resolvers as TranslateResolver[]) || undefined;\r\n\r\n if (!resolvers) return null;\r\n\r\n const resolverConfig = resolvers.find((each) => each.key === resolver);\r\n\r\n return resolverConfig ?? null;\r\n }, [custom, resolver]);\r\n\r\n if (!localization)\r\n throw new Error('Localization config is not provided and PluginTranslator is used');\r\n\r\n const localesOptions = localization.locales.filter((each) => each.code !== locale.code);\r\n\r\n const [localeToTranslateFrom, setLocaleToTranslateFrom] = useState(() => {\r\n const defaultFromOptions = localesOptions.find(\r\n (each) => localization.defaultLocale === each.code,\r\n );\r\n\r\n if (defaultFromOptions) return defaultFromOptions.code;\r\n\r\n return localesOptions[0].code;\r\n });\r\n\r\n const closeTranslator = () => modal.closeModal(modalSlug);\r\n\r\n const submit = async ({ emptyOnly }: { emptyOnly: boolean }) => {\r\n if (!resolver) return;\r\n\r\n const args: TranslateArgs = {\r\n collectionSlug,\r\n data: reduceFieldsToValues(data, true),\r\n emptyOnly,\r\n globalSlug,\r\n id: id === null ? undefined : id,\r\n locale: locale.code,\r\n localeFrom: localeToTranslateFrom,\r\n resolver,\r\n };\r\n\r\n const result = await apiClient.translate(args);\r\n\r\n if (!result.success) {\r\n toast.error(resolverT('errorMessage'));\r\n\r\n return;\r\n }\r\n\r\n dispatch({\r\n state: await getFormState({\r\n apiRoute: api,\r\n body: {\r\n collectionSlug,\r\n data: result.translatedData,\r\n globalSlug,\r\n locale: locale.code,\r\n schemaPath: collectionSlug || globalSlug || '',\r\n },\r\n serverURL,\r\n }),\r\n type: 'REPLACE_STATE',\r\n });\r\n\r\n if (resolverConfig) toast.success(resolverT('successMessage'));\r\n closeTranslator();\r\n };\r\n\r\n return (\r\n <TranslatorContext.Provider\r\n value={{\r\n closeTranslator,\r\n localeToTranslateFrom,\r\n localesOptions,\r\n modalSlug,\r\n openTranslator: ({ resolverKey }) => {\r\n setResolver(resolverKey);\r\n modal.openModal(modalSlug);\r\n },\r\n resolver: resolverConfig,\r\n resolverT,\r\n setLocaleToTranslateFrom,\r\n submit,\r\n }}\r\n >\r\n {children}\r\n </TranslatorContext.Provider>\r\n );\r\n};\r\n"],"names":["toast","useModal","useAllFormFields","useConfig","useDocumentInfo","useLocale","useTranslation","getFormState","reduceFieldsToValues","useMemo","useState","createClient","TranslatorContext","modalSlug","TranslatorProvider","children","resolver","setResolver","data","dispatch","collectionSlug","globalSlug","id","modal","t","resolverT","key","locale","admin","custom","localization","routes","api","serverURL","apiClient","resolverConfig","resolvers","translator","undefined","find","each","Error","localesOptions","locales","filter","code","localeToTranslateFrom","setLocaleToTranslateFrom","defaultFromOptions","defaultLocale","closeTranslator","closeModal","submit","emptyOnly","args","localeFrom","result","translate","success","error","state","apiRoute","body","translatedData","schemaPath","type","Provider","value","openTranslator","resolverKey","openModal"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,KAAK,QAAQ,0BAA0B;AAChD,SAASC,QAAQ,QAAQ,gCAAgC;AACzD,SAASC,gBAAgB,QAAQ,4BAA4B;AAC7D,SAASC,SAAS,QAAQ,kCAAkC;AAC5D,SAASC,eAAe,QAAQ,wCAAwC;AACxE,SAASC,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F;OAECrC;AAGP,EAAE"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/// <reference types="react" resolution-mode="require"/>
|
2
|
+
import type { Locale } from 'payload/config';
|
3
|
+
import type { TranslateResolver } from '../../../resolvers/types';
|
4
|
+
type TranslatorContextData = {
|
5
|
+
closeTranslator: () => void;
|
6
|
+
localeToTranslateFrom: string;
|
7
|
+
localesOptions: Locale[];
|
8
|
+
modalSlug: string;
|
9
|
+
openTranslator: (args: {
|
10
|
+
resolverKey: string;
|
11
|
+
}) => void;
|
12
|
+
resolver: TranslateResolver | null;
|
13
|
+
resolverT: (key: 'buttonLabel' | 'errorMessage' | 'modalTitle' | 'submitButtonLabelEmpty' | 'submitButtonLabelFull' | 'successMessage') => string;
|
14
|
+
setLocaleToTranslateFrom: (code: string) => void;
|
15
|
+
submit: (args: {
|
16
|
+
emptyOnly: boolean;
|
17
|
+
}) => Promise<void>;
|
18
|
+
};
|
19
|
+
export declare const TranslatorContext: import("react").Context<TranslatorContextData | null>;
|
20
|
+
export declare const useTranslator: () => TranslatorContextData;
|
21
|
+
export {};
|
22
|
+
//# sourceMappingURL=context.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/client/providers/Translator/context.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAG7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,KAAK,qBAAqB,GAAG;IAC3B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,CAAC,IAAI,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACxD,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,CACT,GAAG,EACC,aAAa,GACb,cAAc,GACd,YAAY,GACZ,wBAAwB,GACxB,uBAAuB,GACvB,gBAAgB,KACjB,MAAM,CAAC;IACZ,wBAAwB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,MAAM,EAAE,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD,CAAC;AAEF,eAAO,MAAM,iBAAiB,uDAAoD,CAAC;AAEnF,eAAO,MAAM,aAAa,6BAMzB,CAAC"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { createContext, useContext } from 'react';
|
2
|
+
export const TranslatorContext = createContext(null);
|
3
|
+
export const useTranslator = ()=>{
|
4
|
+
const context = useContext(TranslatorContext);
|
5
|
+
if (context === null) throw new Error('useTranslator must be used within TranslatorProvider');
|
6
|
+
return context;
|
7
|
+
};
|
8
|
+
|
9
|
+
//# sourceMappingURL=context.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/client/providers/Translator/context.ts"],"sourcesContent":["import type { Locale } from 'payload/config';\r\nimport { createContext, useContext } from 'react';\r\n\r\nimport type { TranslateResolver } from '../../../resolvers/types';\r\n\r\ntype TranslatorContextData = {\r\n closeTranslator: () => void;\r\n localeToTranslateFrom: string;\r\n localesOptions: Locale[];\r\n modalSlug: string;\r\n openTranslator: (args: { resolverKey: string }) => void;\r\n resolver: TranslateResolver | null;\r\n resolverT: (\r\n key:\r\n | 'buttonLabel'\r\n | 'errorMessage'\r\n | 'modalTitle'\r\n | 'submitButtonLabelEmpty'\r\n | 'submitButtonLabelFull'\r\n | 'successMessage',\r\n ) => string;\r\n setLocaleToTranslateFrom: (code: string) => void;\r\n submit: (args: { emptyOnly: boolean }) => Promise<void>;\r\n};\r\n\r\nexport const TranslatorContext = createContext<TranslatorContextData | null>(null);\r\n\r\nexport const useTranslator = () => {\r\n const context = useContext(TranslatorContext);\r\n\r\n if (context === null) throw new Error('useTranslator must be used within TranslatorProvider');\r\n\r\n return context;\r\n};\r\n"],"names":["createContext","useContext","TranslatorContext","useTranslator","context","Error"],"rangeMappings":";;;;;;","mappings":"AACA,SAASA,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AAwBlD,OAAO,MAAMC,oBAAoBF,cAA4C,MAAM;AAEnF,OAAO,MAAMG,gBAAgB;IAC3B,MAAMC,UAAUH,WAAWC;IAE3B,IAAIE,YAAY,MAAM,MAAM,IAAIC,MAAM;IAEtC,OAAOD;AACT,EAAE"}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
export declare const translations: {
|
2
|
+
en: {
|
3
|
+
'plugin-translator': {
|
4
|
+
resolver_copy_buttonLabel: string;
|
5
|
+
resolver_copy_errorMessage: string;
|
6
|
+
resolver_copy_modalTitle: string;
|
7
|
+
resolver_copy_submitButtonLabelEmpty: string;
|
8
|
+
resolver_copy_submitButtonLabelFull: string;
|
9
|
+
resolver_copy_successMessage: string;
|
10
|
+
resolver_google_buttonLabel: string;
|
11
|
+
resolver_google_errorMessage: string;
|
12
|
+
resolver_google_modalTitle: string;
|
13
|
+
resolver_google_submitButtonLabelEmpty: string;
|
14
|
+
resolver_google_submitButtonLabelFull: string;
|
15
|
+
resolver_google_successMessage: string;
|
16
|
+
resolver_openai_buttonLabel: string;
|
17
|
+
resolver_openai_errorMessage: string;
|
18
|
+
resolver_openai_modalTitle: string;
|
19
|
+
resolver_openai_submitButtonLabelEmpty: string;
|
20
|
+
resolver_openai_submitButtonLabelFull: string;
|
21
|
+
resolver_openai_successMessage: string;
|
22
|
+
};
|
23
|
+
};
|
24
|
+
};
|
25
|
+
//# sourceMappingURL=i18n-translations.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"i18n-translations.d.ts","sourceRoot":"","sources":["../src/i18n-translations.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;CAyBxB,CAAC"}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
export const translations = {
|
2
|
+
en: {
|
3
|
+
'plugin-translator': {
|
4
|
+
resolver_copy_buttonLabel: 'Copy from other locale',
|
5
|
+
resolver_copy_errorMessage: 'An error occurred when trying to translate the data',
|
6
|
+
resolver_copy_modalTitle: 'Choose the locale to copy from',
|
7
|
+
resolver_copy_submitButtonLabelEmpty: 'Copy only empty fields',
|
8
|
+
resolver_copy_submitButtonLabelFull: 'Copy all',
|
9
|
+
resolver_copy_successMessage: 'Successfully copied. Press "Save" to apply the changes.',
|
10
|
+
resolver_google_buttonLabel: 'Google Translate',
|
11
|
+
resolver_google_errorMessage: 'An error occurred when trying to translate the data',
|
12
|
+
resolver_google_modalTitle: 'Choose the locale to translate from',
|
13
|
+
resolver_google_submitButtonLabelEmpty: 'Translate only empty fields',
|
14
|
+
resolver_google_submitButtonLabelFull: 'Translate all',
|
15
|
+
resolver_google_successMessage: 'Successfully translated. Press "Save" to apply the changes.',
|
16
|
+
resolver_openai_buttonLabel: 'AI Translate',
|
17
|
+
resolver_openai_errorMessage: 'An error occurred when trying to translate the data',
|
18
|
+
resolver_openai_modalTitle: 'Choose the locale to translate from',
|
19
|
+
resolver_openai_submitButtonLabelEmpty: 'Translate only empty fields',
|
20
|
+
resolver_openai_submitButtonLabelFull: 'Translate all',
|
21
|
+
resolver_openai_successMessage: 'Successfully translated. Press "Save" to apply the changes.'
|
22
|
+
}
|
23
|
+
}
|
24
|
+
};
|
25
|
+
|
26
|
+
//# sourceMappingURL=i18n-translations.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/i18n-translations.ts"],"sourcesContent":["export const translations = {\r\n en: {\r\n 'plugin-translator': {\r\n resolver_copy_buttonLabel: 'Copy from other locale',\r\n resolver_copy_errorMessage: 'An error occurred when trying to translate the data',\r\n resolver_copy_modalTitle: 'Choose the locale to copy from',\r\n resolver_copy_submitButtonLabelEmpty: 'Copy only empty fields',\r\n resolver_copy_submitButtonLabelFull: 'Copy all',\r\n resolver_copy_successMessage: 'Successfully copied. Press \"Save\" to apply the changes.',\r\n\r\n resolver_google_buttonLabel: 'Google Translate',\r\n resolver_google_errorMessage: 'An error occurred when trying to translate the data',\r\n resolver_google_modalTitle: 'Choose the locale to translate from',\r\n resolver_google_submitButtonLabelEmpty: 'Translate only empty fields',\r\n resolver_google_submitButtonLabelFull: 'Translate all',\r\n resolver_google_successMessage: 'Successfully translated. Press \"Save\" to apply the changes.',\r\n\r\n resolver_openai_buttonLabel: 'AI Translate',\r\n resolver_openai_errorMessage: 'An error occurred when trying to translate the data',\r\n resolver_openai_modalTitle: 'Choose the locale to translate from',\r\n resolver_openai_submitButtonLabelEmpty: 'Translate only empty fields',\r\n resolver_openai_submitButtonLabelFull: 'Translate all',\r\n resolver_openai_successMessage: 'Successfully translated. Press \"Save\" to apply the changes.',\r\n },\r\n },\r\n};\r\n"],"names":["translations","en","resolver_copy_buttonLabel","resolver_copy_errorMessage","resolver_copy_modalTitle","resolver_copy_submitButtonLabelEmpty","resolver_copy_submitButtonLabelFull","resolver_copy_successMessage","resolver_google_buttonLabel","resolver_google_errorMessage","resolver_google_modalTitle","resolver_google_submitButtonLabelEmpty","resolver_google_submitButtonLabelFull","resolver_google_successMessage","resolver_openai_buttonLabel","resolver_openai_errorMessage","resolver_openai_modalTitle","resolver_openai_submitButtonLabelEmpty","resolver_openai_submitButtonLabelFull","resolver_openai_successMessage"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAO,MAAMA,eAAe;IAC1BC,IAAI;QACF,qBAAqB;YACnBC,2BAA2B;YAC3BC,4BAA4B;YAC5BC,0BAA0B;YAC1BC,sCAAsC;YACtCC,qCAAqC;YACrCC,8BAA8B;YAE9BC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCAAgC;YAEhCC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCAAgC;QAClC;IACF;AACF,EAAE"}
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
import type { Plugin } from 'payload/config';
|
2
|
+
import { translateOperation } from './translate/operation';
|
3
|
+
import type { TranslatorConfig } from './types';
|
4
|
+
export { translateOperation };
|
5
|
+
export declare const translator: (pluginConfig: TranslatorConfig) => Plugin;
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAM7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,eAAO,MAAM,UAAU,EAAE,CAAC,YAAY,EAAE,gBAAgB,KAAK,MA0E5D,CAAC"}
|
package/dist/index.js
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
/* eslint-disable perfectionist/sort-named-exports */ import { deepMerge } from 'payload/utilities';
|
2
|
+
import { CustomSaveButton } from './client/components/CustomSaveButton';
|
3
|
+
import { translations } from './i18n-translations';
|
4
|
+
import { translateEndpoint } from './translate/endpoint';
|
5
|
+
import { translateOperation } from './translate/operation';
|
6
|
+
export { translateOperation };
|
7
|
+
export const translator = (pluginConfig)=>{
|
8
|
+
return (config)=>{
|
9
|
+
if (pluginConfig.disabled || !config.localization || config.localization.locales.length < 2) return config;
|
10
|
+
return {
|
11
|
+
...config,
|
12
|
+
admin: {
|
13
|
+
...config.admin ?? {},
|
14
|
+
custom: {
|
15
|
+
...config.admin?.custom ?? {},
|
16
|
+
translator: {
|
17
|
+
resolvers: pluginConfig.resolvers.map(({ key })=>({
|
18
|
+
key
|
19
|
+
}))
|
20
|
+
}
|
21
|
+
}
|
22
|
+
},
|
23
|
+
collections: config.collections?.map((collection)=>{
|
24
|
+
if (!pluginConfig.collections.includes(collection.slug)) return collection;
|
25
|
+
return {
|
26
|
+
...collection,
|
27
|
+
admin: {
|
28
|
+
...collection.admin ?? {},
|
29
|
+
components: {
|
30
|
+
...collection.admin?.components ?? {},
|
31
|
+
edit: {
|
32
|
+
...collection.admin?.components?.edit ?? {},
|
33
|
+
SaveButton: CustomSaveButton
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
};
|
38
|
+
}) ?? [],
|
39
|
+
custom: {
|
40
|
+
...config.custom ?? {},
|
41
|
+
translator: {
|
42
|
+
resolvers: pluginConfig.resolvers
|
43
|
+
}
|
44
|
+
},
|
45
|
+
endpoints: [
|
46
|
+
...config.endpoints ?? [],
|
47
|
+
{
|
48
|
+
handler: translateEndpoint,
|
49
|
+
method: 'post',
|
50
|
+
path: '/translator/translate'
|
51
|
+
}
|
52
|
+
],
|
53
|
+
globals: config.globals?.map((global)=>{
|
54
|
+
if (!pluginConfig.globals.includes(global.slug)) return global;
|
55
|
+
return {
|
56
|
+
...global,
|
57
|
+
admin: {
|
58
|
+
...global.admin ?? {},
|
59
|
+
components: {
|
60
|
+
...global.admin?.components ?? {},
|
61
|
+
elements: {
|
62
|
+
...global.admin?.components?.elements ?? {},
|
63
|
+
SaveButton: CustomSaveButton
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
};
|
68
|
+
}) ?? [],
|
69
|
+
i18n: {
|
70
|
+
...config.i18n,
|
71
|
+
translations: {
|
72
|
+
...deepMerge(config.i18n?.translations ?? {}, translations)
|
73
|
+
}
|
74
|
+
}
|
75
|
+
};
|
76
|
+
};
|
77
|
+
};
|
78
|
+
|
79
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-named-exports */\r\nimport type { Plugin } from 'payload/config';\r\nimport { deepMerge } from 'payload/utilities';\r\n\r\nimport { CustomSaveButton } from './client/components/CustomSaveButton';\r\nimport { translations } from './i18n-translations';\r\nimport { translateEndpoint } from './translate/endpoint';\r\nimport { translateOperation } from './translate/operation';\r\nimport type { TranslatorConfig } from './types';\r\n\r\nexport { translateOperation };\r\n\r\nexport const translator: (pluginConfig: TranslatorConfig) => Plugin = (pluginConfig) => {\r\n return (config) => {\r\n if (pluginConfig.disabled || !config.localization || config.localization.locales.length < 2)\r\n return config;\r\n\r\n return {\r\n ...config,\r\n admin: {\r\n ...(config.admin ?? {}),\r\n custom: {\r\n ...(config.admin?.custom ?? {}),\r\n translator: {\r\n resolvers: pluginConfig.resolvers.map(({ key }) => ({ key })),\r\n },\r\n },\r\n },\r\n collections:\r\n config.collections?.map((collection) => {\r\n if (!pluginConfig.collections.includes(collection.slug)) return collection;\r\n\r\n return {\r\n ...collection,\r\n admin: {\r\n ...(collection.admin ?? {}),\r\n components: {\r\n ...(collection.admin?.components ?? {}),\r\n edit: {\r\n ...(collection.admin?.components?.edit ?? {}),\r\n SaveButton: CustomSaveButton,\r\n },\r\n },\r\n },\r\n };\r\n }) ?? [],\r\n custom: {\r\n ...(config.custom ?? {}),\r\n translator: {\r\n resolvers: pluginConfig.resolvers,\r\n },\r\n },\r\n endpoints: [\r\n ...(config.endpoints ?? []),\r\n {\r\n handler: translateEndpoint,\r\n method: 'post',\r\n path: '/translator/translate',\r\n },\r\n ],\r\n globals:\r\n config.globals?.map((global) => {\r\n if (!pluginConfig.globals.includes(global.slug)) return global;\r\n\r\n return {\r\n ...global,\r\n admin: {\r\n ...(global.admin ?? {}),\r\n components: {\r\n ...(global.admin?.components ?? {}),\r\n elements: {\r\n ...(global.admin?.components?.elements ?? {}),\r\n SaveButton: CustomSaveButton,\r\n },\r\n },\r\n },\r\n };\r\n }) ?? [],\r\n i18n: {\r\n ...config.i18n,\r\n translations: {\r\n ...deepMerge(config.i18n?.translations ?? {}, translations),\r\n },\r\n },\r\n };\r\n };\r\n};\r\n"],"names":["deepMerge","CustomSaveButton","translations","translateEndpoint","translateOperation","translator","pluginConfig","config","disabled","localization","locales","length","admin","custom","resolvers","map","key","collections","collection","includes","slug","components","edit","SaveButton","endpoints","handler","method","path","globals","global","elements","i18n"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,mDAAmD,GAEnD,SAASA,SAAS,QAAQ,oBAAoB;AAE9C,SAASC,gBAAgB,QAAQ,uCAAuC;AACxE,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SAASC,iBAAiB,QAAQ,uBAAuB;AACzD,SAASC,kBAAkB,QAAQ,wBAAwB;AAG3D,SAASA,kBAAkB,GAAG;AAE9B,OAAO,MAAMC,aAAyD,CAACC;IACrE,OAAO,CAACC;QACN,IAAID,aAAaE,QAAQ,IAAI,CAACD,OAAOE,YAAY,IAAIF,OAAOE,YAAY,CAACC,OAAO,CAACC,MAAM,GAAG,GACxF,OAAOJ;QAET,OAAO;YACL,GAAGA,MAAM;YACTK,OAAO;gBACL,GAAIL,OAAOK,KAAK,IAAI,CAAC,CAAC;gBACtBC,QAAQ;oBACN,GAAIN,OAAOK,KAAK,EAAEC,UAAU,CAAC,CAAC;oBAC9BR,YAAY;wBACVS,WAAWR,aAAaQ,SAAS,CAACC,GAAG,CAAC,CAAC,EAAEC,GAAG,EAAE,GAAM,CAAA;gCAAEA;4BAAI,CAAA;oBAC5D;gBACF;YACF;YACAC,aACEV,OAAOU,WAAW,EAAEF,IAAI,CAACG;gBACvB,IAAI,CAACZ,aAAaW,WAAW,CAACE,QAAQ,CAACD,WAAWE,IAAI,GAAG,OAAOF;gBAEhE,OAAO;oBACL,GAAGA,UAAU;oBACbN,OAAO;wBACL,GAAIM,WAAWN,KAAK,IAAI,CAAC,CAAC;wBAC1B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|
+
{"version":3,"sources":["../../src/resolvers/copy.ts"],"sourcesContent":["import type { TranslateResolver } from './types';\r\n\r\nexport const copyResolver = (): TranslateResolver => {\r\n return {\r\n key: 'copy',\r\n resolve: (args) => {\r\n const { texts } = args;\r\n\r\n return {\r\n success: true,\r\n translatedTexts: texts,\r\n };\r\n },\r\n };\r\n};\r\n"],"names":["copyResolver","key","resolve","args","texts","success","translatedTexts"],"rangeMappings":";;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,eAAe;IAC1B,OAAO;QACLC,KAAK;QACLC,SAAS,CAACC;YACR,MAAM,EAAEC,KAAK,EAAE,GAAGD;YAElB,OAAO;gBACLE,SAAS;gBACTC,iBAAiBF;YACnB;QACF;IACF;AACF,EAAE"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { TranslateResolver } from './types';
|
2
|
+
export type GoogleResolverConfig = {
|
3
|
+
apiKey: string;
|
4
|
+
/**
|
5
|
+
* How many texts to include into 1 request
|
6
|
+
* @default 100
|
7
|
+
*/
|
8
|
+
chunkLength?: number;
|
9
|
+
};
|
10
|
+
export declare const googleResolver: ({ apiKey, chunkLength, }: GoogleResolverConfig) => TranslateResolver;
|
11
|
+
//# sourceMappingURL=google.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/resolvers/google.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAwBjD,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,cAAc,6BAGxB,oBAAoB,KAAG,iBAqDzB,CAAC"}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import { chunkArray } from '../utils/chunkArray';
|
2
|
+
const localeToCountryCodeMapper = {
|
3
|
+
ua: 'uk'
|
4
|
+
};
|
5
|
+
const mapLocale = (incoming)=>incoming in localeToCountryCodeMapper ? localeToCountryCodeMapper[incoming] : incoming;
|
6
|
+
export const googleResolver = ({ apiKey, chunkLength = 100 })=>{
|
7
|
+
return {
|
8
|
+
key: 'google',
|
9
|
+
resolve: async (args)=>{
|
10
|
+
const { localeFrom, localeTo, req, texts } = args;
|
11
|
+
const apiUrl = `https://translation.googleapis.com/language/translate/v2?key=${apiKey}`;
|
12
|
+
const responses = await Promise.all(chunkArray(texts, chunkLength).map((q)=>fetch(apiUrl, {
|
13
|
+
body: JSON.stringify({
|
14
|
+
q,
|
15
|
+
source: mapLocale(localeFrom),
|
16
|
+
target: mapLocale(localeTo)
|
17
|
+
}),
|
18
|
+
headers: {
|
19
|
+
'Content-Type': 'application/json'
|
20
|
+
},
|
21
|
+
method: 'POST'
|
22
|
+
}).then(async (res)=>{
|
23
|
+
const data = await res.json();
|
24
|
+
if (!res.ok) req.payload.logger.info({
|
25
|
+
googleResponse: data,
|
26
|
+
message: `An error occurred when trying to translate the data using Google API`
|
27
|
+
});
|
28
|
+
return {
|
29
|
+
data,
|
30
|
+
success: res.ok
|
31
|
+
};
|
32
|
+
})));
|
33
|
+
if (responses.some((res)=>!res.success)) {
|
34
|
+
return {
|
35
|
+
success: false
|
36
|
+
};
|
37
|
+
}
|
38
|
+
const translatedTexts = responses.flatMap((chunk)=>chunk.data.data.translations).map((translation)=>translation.translatedText);
|
39
|
+
return {
|
40
|
+
success: true,
|
41
|
+
translatedTexts
|
42
|
+
};
|
43
|
+
}
|
44
|
+
};
|
45
|
+
};
|
46
|
+
|
47
|
+
//# sourceMappingURL=google.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/resolvers/google.ts"],"sourcesContent":["import { chunkArray } from '../utils/chunkArray';\r\nimport type { TranslateResolver } from './types';\r\n\r\ntype GoogleResponse = {\r\n data: {\r\n data: {\r\n translations: {\r\n detectedSourceLanguage: string;\r\n model: string;\r\n translatedText: string;\r\n }[];\r\n };\r\n };\r\n success: boolean;\r\n};\r\n\r\nconst localeToCountryCodeMapper = {\r\n ua: 'uk',\r\n};\r\n\r\nconst mapLocale = (incoming: string) =>\r\n incoming in localeToCountryCodeMapper\r\n ? localeToCountryCodeMapper[incoming as keyof typeof localeToCountryCodeMapper]\r\n : incoming;\r\n\r\nexport type GoogleResolverConfig = {\r\n apiKey: string;\r\n /**\r\n * How many texts to include into 1 request\r\n * @default 100\r\n */\r\n chunkLength?: number;\r\n};\r\n\r\nexport const googleResolver = ({\r\n apiKey,\r\n chunkLength = 100,\r\n}: GoogleResolverConfig): TranslateResolver => {\r\n return {\r\n key: 'google',\r\n resolve: async (args) => {\r\n const { localeFrom, localeTo, req, texts } = args;\r\n\r\n const apiUrl = `https://translation.googleapis.com/language/translate/v2?key=${apiKey}`;\r\n\r\n const responses: GoogleResponse[] = await Promise.all(\r\n chunkArray(texts, chunkLength).map((q) =>\r\n fetch(apiUrl, {\r\n body: JSON.stringify({\r\n q,\r\n source: mapLocale(localeFrom),\r\n target: mapLocale(localeTo),\r\n }),\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n },\r\n method: 'POST',\r\n }).then(async (res) => {\r\n const data = await res.json();\r\n\r\n if (!res.ok)\r\n req.payload.logger.info({\r\n googleResponse: data,\r\n message: `An error occurred when trying to translate the data using Google API`,\r\n });\r\n\r\n return {\r\n data,\r\n success: res.ok,\r\n };\r\n }),\r\n ),\r\n );\r\n\r\n if (responses.some((res) => !res.success)) {\r\n return {\r\n success: false,\r\n };\r\n }\r\n\r\n const translatedTexts = responses\r\n .flatMap((chunk) => chunk.data.data.translations)\r\n .map((translation) => translation.translatedText);\r\n\r\n return {\r\n success: true,\r\n translatedTexts,\r\n };\r\n },\r\n };\r\n};\r\n"],"names":["chunkArray","localeToCountryCodeMapper","ua","mapLocale","incoming","googleResolver","apiKey","chunkLength","key","resolve","args","localeFrom","localeTo","req","texts","apiUrl","responses","Promise","all","map","q","fetch","body","JSON","stringify","source","target","headers","method","then","res","data","json","ok","payload","logger","info","googleResponse","message","success","some","translatedTexts","flatMap","chunk","translations","translation","translatedText"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,UAAU,QAAQ,sBAAsB;AAgBjD,MAAMC,4BAA4B;IAChCC,IAAI;AACN;AAEA,MAAMC,YAAY,CAACC,WACjBA,YAAYH,4BACRA,yBAAyB,CAACG,SAAmD,GAC7EA;AAWN,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,cAAc,GAAG,EACI;IACrB,OAAO;QACLC,KAAK;QACLC,SAAS,OAAOC;YACd,MAAM,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,KAAK,EAAE,GAAGJ;YAE7C,MAAMK,SAAS,CAAC,6DAA6D,EAAET,OAAO,CAAC;YAEvF,MAAMU,YAA8B,MAAMC,QAAQC,GAAG,CACnDlB,WAAWc,OAAOP,aAAaY,GAAG,CAAC,CAACC,IAClCC,MAAMN,QAAQ;oBACZO,MAAMC,KAAKC,SAAS,CAAC;wBACnBJ;wBACAK,QAAQtB,UAAUQ;wBAClBe,QAAQvB,UAAUS;oBACpB;oBACAe,SAAS;wBACP,gBAAgB;oBAClB;oBACAC,QAAQ;gBACV,GAAGC,IAAI,CAAC,OAAOC;oBACb,MAAMC,OAAO,MAAMD,IAAIE,IAAI;oBAE3B,IAAI,CAACF,IAAIG,EAAE,EACTpB,IAAIqB,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;wBACtBC,gBAAgBN;wBAChBO,SAAS,CAAC,oEAAoE,CAAC;oBACjF;oBAEF,OAAO;wBACLP;wBACAQ,SAAST,IAAIG,EAAE;oBACjB;gBACF;YAIJ,IAAIjB,UAAUwB,IAAI,CAAC,CAACV,MAAQ,CAACA,IAAIS,OAAO,GAAG;gBACzC,OAAO;oBACLA,SAAS;gBACX;YACF;YAEA,MAAME,kBAAkBzB,UACrB0B,OAAO,CAAC,CAACC,QAAUA,MAAMZ,IAAI,CAACA,IAAI,CAACa,YAAY,EAC/CzB,GAAG,CAAC,CAAC0B,cAAgBA,YAAYC,cAAc;YAElD,OAAO;gBACLP,SAAS;gBACTE;YACF;QACF;IACF;AACF,EAAE"}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { TranslateResolver } from './types';
|
2
|
+
export type OpenAIPrompt = (args: {
|
3
|
+
localeFrom: string;
|
4
|
+
localeTo: string;
|
5
|
+
texts: string[];
|
6
|
+
}) => string;
|
7
|
+
export type OpenAIResolverConfig = {
|
8
|
+
apiKey: string;
|
9
|
+
/**
|
10
|
+
* How many texts to include into 1 request
|
11
|
+
* @default 100
|
12
|
+
*/
|
13
|
+
chunkLength?: number;
|
14
|
+
/**
|
15
|
+
* @default "gpt-3.5-turbo"
|
16
|
+
*/
|
17
|
+
model?: string;
|
18
|
+
promt?: OpenAIPrompt;
|
19
|
+
};
|
20
|
+
export declare const openAIResolver: ({ apiKey, chunkLength, model, promt, }: OpenAIResolverConfig) => TranslateResolver;
|
21
|
+
//# sourceMappingURL=openAI.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"openAI.d.ts","sourceRoot":"","sources":["../../src/resolvers/openAI.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,KAAK,MAAM,CAAC;AAEb,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB,CAAC;AAcF,eAAO,MAAM,cAAc,2CAKxB,oBAAoB,KAAG,iBA6GzB,CAAC"}
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import { chunkArray } from '../utils/chunkArray';
|
2
|
+
const defaultPromt = ({ localeFrom, localeTo, texts })=>{
|
3
|
+
return `Translate me the following array: ${JSON.stringify(texts)} in locale=${localeFrom} to locale ${localeTo}, respond me with the same array structure`;
|
4
|
+
};
|
5
|
+
export const openAIResolver = ({ apiKey, chunkLength = 100, model = 'gpt-3.5-turbo', promt = defaultPromt })=>{
|
6
|
+
return {
|
7
|
+
key: 'openai',
|
8
|
+
resolve: async ({ localeFrom, localeTo, req, texts })=>{
|
9
|
+
const apiUrl = 'https://api.openai.com/v1/chat/completions';
|
10
|
+
try {
|
11
|
+
const respones = await Promise.all(chunkArray(texts, chunkLength).map((texts)=>{
|
12
|
+
return fetch(apiUrl, {
|
13
|
+
body: JSON.stringify({
|
14
|
+
messages: [
|
15
|
+
{
|
16
|
+
content: promt({
|
17
|
+
localeFrom,
|
18
|
+
localeTo,
|
19
|
+
texts
|
20
|
+
}),
|
21
|
+
role: 'user'
|
22
|
+
}
|
23
|
+
],
|
24
|
+
model
|
25
|
+
}),
|
26
|
+
headers: {
|
27
|
+
Authorization: `Bearer ${apiKey}`,
|
28
|
+
'Content-Type': 'application/json'
|
29
|
+
},
|
30
|
+
method: 'post'
|
31
|
+
}).then(async (res)=>{
|
32
|
+
const data = await res.json();
|
33
|
+
if (!res.ok) req.payload.logger.info({
|
34
|
+
message: `An error occurred when trying to translate the data using OpenAI API`,
|
35
|
+
openAIresponse: data
|
36
|
+
});
|
37
|
+
return {
|
38
|
+
data,
|
39
|
+
success: res.ok
|
40
|
+
};
|
41
|
+
});
|
42
|
+
}));
|
43
|
+
const translated = [];
|
44
|
+
for (const { data, success } of respones){
|
45
|
+
if (!success) return {
|
46
|
+
success: false
|
47
|
+
};
|
48
|
+
const content = data?.choices?.[0]?.message?.content;
|
49
|
+
if (!content) {
|
50
|
+
req.payload.logger.info(`An error occurred when trying to translate the data using OpenAI API - missing content in the response`);
|
51
|
+
return {
|
52
|
+
success: false
|
53
|
+
};
|
54
|
+
}
|
55
|
+
const translatedChunk = JSON.parse(content);
|
56
|
+
if (!Array.isArray(translatedChunk)) {
|
57
|
+
req.payload.logger.info({
|
58
|
+
data: translatedChunk,
|
59
|
+
message: `An error occurred when trying to translate the data using OpenAI API - parsed content is not an array`
|
60
|
+
});
|
61
|
+
return {
|
62
|
+
success: false
|
63
|
+
};
|
64
|
+
}
|
65
|
+
for (const text of translatedChunk){
|
66
|
+
if (typeof text !== 'string') {
|
67
|
+
req.payload.logger.info({
|
68
|
+
data: text,
|
69
|
+
message: `An error occurred when trying to translate the data using OpenAI API - parsed content is not an array`
|
70
|
+
});
|
71
|
+
return {
|
72
|
+
success: false
|
73
|
+
};
|
74
|
+
}
|
75
|
+
translated.push(text);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
return {
|
79
|
+
success: true,
|
80
|
+
translatedTexts: translated
|
81
|
+
};
|
82
|
+
} catch (e) {
|
83
|
+
if (e instanceof Error) {
|
84
|
+
req.payload.logger.info({
|
85
|
+
message: `An error occurred when trying to translate the data using OpenAI API`,
|
86
|
+
originalErr: e.message
|
87
|
+
});
|
88
|
+
}
|
89
|
+
return {
|
90
|
+
success: false
|
91
|
+
};
|
92
|
+
}
|
93
|
+
}
|
94
|
+
};
|
95
|
+
};
|
96
|
+
|
97
|
+
//# sourceMappingURL=openAI.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/resolvers/openAI.ts"],"sourcesContent":["import { chunkArray } from '../utils/chunkArray';\r\nimport type { TranslateResolver } from './types';\r\n\r\nexport type OpenAIPrompt = (args: {\r\n localeFrom: string;\r\n localeTo: string;\r\n texts: string[];\r\n}) => string;\r\n\r\nexport type OpenAIResolverConfig = {\r\n apiKey: string;\r\n /**\r\n * How many texts to include into 1 request\r\n * @default 100\r\n */\r\n chunkLength?: number;\r\n /**\r\n * @default \"gpt-3.5-turbo\"\r\n */\r\n model?: string;\r\n promt?: OpenAIPrompt;\r\n};\r\n\r\ntype OpenAIResponse = {\r\n choices: {\r\n message: {\r\n content: string;\r\n };\r\n }[];\r\n};\r\n\r\nconst defaultPromt: OpenAIPrompt = ({ localeFrom, localeTo, texts }) => {\r\n return `Translate me the following array: ${JSON.stringify(texts)} in locale=${localeFrom} to locale ${localeTo}, respond me with the same array structure`;\r\n};\r\n\r\nexport const openAIResolver = ({\r\n apiKey,\r\n chunkLength = 100,\r\n model = 'gpt-3.5-turbo',\r\n promt = defaultPromt,\r\n}: OpenAIResolverConfig): TranslateResolver => {\r\n return {\r\n key: 'openai',\r\n resolve: async ({ localeFrom, localeTo, req, texts }) => {\r\n const apiUrl = 'https://api.openai.com/v1/chat/completions';\r\n\r\n try {\r\n const respones: {\r\n data: OpenAIResponse;\r\n success: boolean;\r\n }[] = await Promise.all(\r\n chunkArray(texts, chunkLength).map((texts) => {\r\n return fetch(apiUrl, {\r\n body: JSON.stringify({\r\n messages: [\r\n {\r\n content: promt({ localeFrom, localeTo, texts }),\r\n role: 'user',\r\n },\r\n ],\r\n model,\r\n }),\r\n headers: {\r\n Authorization: `Bearer ${apiKey}`,\r\n 'Content-Type': 'application/json',\r\n },\r\n method: 'post',\r\n }).then(async (res) => {\r\n const data = await res.json();\r\n\r\n if (!res.ok)\r\n req.payload.logger.info({\r\n message: `An error occurred when trying to translate the data using OpenAI API`,\r\n openAIresponse: data,\r\n });\r\n\r\n return {\r\n data,\r\n success: res.ok,\r\n };\r\n });\r\n }),\r\n );\r\n\r\n const translated: string[] = [];\r\n\r\n for (const { data, success } of respones) {\r\n if (!success)\r\n return {\r\n success: false as const,\r\n };\r\n\r\n const content = data?.choices?.[0]?.message?.content;\r\n\r\n if (!content) {\r\n req.payload.logger.info(\r\n `An error occurred when trying to translate the data using OpenAI API - missing content in the response`,\r\n );\r\n\r\n return {\r\n success: false as const,\r\n };\r\n }\r\n\r\n const translatedChunk: string[] = JSON.parse(content);\r\n\r\n if (!Array.isArray(translatedChunk)) {\r\n req.payload.logger.info({\r\n data: translatedChunk,\r\n message: `An error occurred when trying to translate the data using OpenAI API - parsed content is not an array`,\r\n });\r\n\r\n return {\r\n success: false as const,\r\n };\r\n }\r\n\r\n for (const text of translatedChunk) {\r\n if (typeof text !== 'string') {\r\n req.payload.logger.info({\r\n data: text,\r\n message: `An error occurred when trying to translate the data using OpenAI API - parsed content is not an array`,\r\n });\r\n\r\n return {\r\n success: false as const,\r\n };\r\n }\r\n\r\n translated.push(text);\r\n }\r\n }\r\n\r\n return {\r\n success: true as const,\r\n translatedTexts: translated,\r\n };\r\n } catch (e) {\r\n if (e instanceof Error) {\r\n req.payload.logger.info({\r\n message: `An error occurred when trying to translate the data using OpenAI API`,\r\n originalErr: e.message,\r\n });\r\n }\r\n\r\n return { success: false as const };\r\n }\r\n },\r\n };\r\n};\r\n"],"names":["chunkArray","defaultPromt","localeFrom","localeTo","texts","JSON","stringify","openAIResolver","apiKey","chunkLength","model","promt","key","resolve","req","apiUrl","respones","Promise","all","map","fetch","body","messages","content","role","headers","Authorization","method","then","res","data","json","ok","payload","logger","info","message","openAIresponse","success","translated","choices","translatedChunk","parse","Array","isArray","text","push","translatedTexts","e","Error","originalErr"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,UAAU,QAAQ,sBAAsB;AA+BjD,MAAMC,eAA6B,CAAC,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,KAAK,EAAE;IACjE,OAAO,CAAC,kCAAkC,EAAEC,KAAKC,SAAS,CAACF,OAAO,WAAW,EAAEF,WAAW,WAAW,EAAEC,SAAS,0CAA0C,CAAC;AAC7J;AAEA,OAAO,MAAMI,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,cAAc,GAAG,EACjBC,QAAQ,eAAe,EACvBC,Q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BAAkB;wBACnC3B,IAAImB,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;4BACtBL,MAAMW;4BACNL,SAAS,CAAC,qGAAqG,CAAC;wBAClH;wBAEA,OAAO;4BACLE,SAAS;wBACX;oBACF;oBAEA,KAAK,MAAMO,QAAQJ,gBAAiB;wBAClC,IAAI,OAAOI,SAAS,UAAU;4BAC5B/B,IAAImB,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;gCACtBL,MAAMe;gCACNT,SAAS,CAAC,qGAAqG,CAAC;4BAClH;4BAEA,OAAO;gCACLE,SAAS;4BACX;wBACF;wBAEAC,WAAWO,IAAI,CAACD;oBAClB;gBACF;gBAEA,OAAO;oBACLP,SAAS;oBACTS,iBAAiBR;gBACnB;YACF,EAAE,OAAOS,GAAG;gBACV,IAAIA,aAAaC,OAAO;oBACtBnC,IAAImB,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;wBACtBC,SAAS,CAAC,oEAAoE,CAAC;wBAC/Ec,aAAaF,EAAEZ,OAAO;oBACxB;gBACF;gBAEA,OAAO;oBAAEE,SAAS;gBAAe;YACnC;QACF;IACF;AACF,EAAE"}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { PayloadRequest } from 'payload/types';
|
2
|
+
export type TranslateResolverArgs = {
|
3
|
+
/** Locale to translate from */
|
4
|
+
localeFrom: string;
|
5
|
+
/** Locale to translate to */
|
6
|
+
localeTo: string;
|
7
|
+
req: PayloadRequest;
|
8
|
+
texts: string[];
|
9
|
+
};
|
10
|
+
export type TranslateResolverResponse = {
|
11
|
+
success: false;
|
12
|
+
} | {
|
13
|
+
success: true;
|
14
|
+
translatedTexts: string[];
|
15
|
+
};
|
16
|
+
export type TranslateResolver = {
|
17
|
+
key: string;
|
18
|
+
resolve: (args: TranslateResolverArgs) => Promise<TranslateResolverResponse> | TranslateResolverResponse;
|
19
|
+
};
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/resolvers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,MAAM,qBAAqB,GAAG;IAClC,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,cAAc,CAAC;IACpB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACjC;IACE,OAAO,EAAE,KAAK,CAAC;CAChB,GACD;IACE,OAAO,EAAE,IAAI,CAAC;IACd,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEN,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,CACP,IAAI,EAAE,qBAAqB,KACxB,OAAO,CAAC,yBAAyB,CAAC,GAAG,yBAAyB,CAAC;CACrE,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/resolvers/types.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload/types';\r\n\r\nexport type TranslateResolverArgs = {\r\n /** Locale to translate from */\r\n localeFrom: string;\r\n /** Locale to translate to */\r\n localeTo: string;\r\n req: PayloadRequest;\r\n texts: string[];\r\n};\r\n\r\nexport type TranslateResolverResponse =\r\n | {\r\n success: false;\r\n }\r\n | {\r\n success: true;\r\n translatedTexts: string[];\r\n };\r\n\r\nexport type TranslateResolver = {\r\n key: string;\r\n resolve: (\r\n args: TranslateResolverArgs,\r\n ) => Promise<TranslateResolverResponse> | TranslateResolverResponse;\r\n};\r\n"],"names":[],"rangeMappings":"","mappings":"AAoBA,WAKE"}
|