@payload-enchants/translator 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -0
- package/dist/client/api/index.js.map +1 -1
- package/dist/client/components/CustomButton/CustomButtonWithTranslator.d.ts +3 -4
- package/dist/client/components/CustomButton/CustomButtonWithTranslator.d.ts.map +1 -1
- package/dist/client/components/CustomButton/CustomButtonWithTranslator.js +6 -5
- package/dist/client/components/CustomButton/CustomButtonWithTranslator.js.map +1 -1
- package/dist/client/components/CustomButton/index.d.ts +2 -1
- package/dist/client/components/CustomButton/index.d.ts.map +1 -1
- package/dist/client/components/CustomButton/index.js +5 -8
- package/dist/client/components/CustomButton/index.js.map +1 -1
- package/dist/client/components/LocaleLabel/LocaleLabel.js.map +1 -1
- package/dist/client/components/ResolverButton/ResolverButton.js +0 -1
- package/dist/client/components/ResolverButton/ResolverButton.js.map +1 -1
- package/dist/client/components/TranslatorModal/TranslatorModal.d.ts.map +1 -1
- package/dist/client/components/TranslatorModal/TranslatorModal.js +2 -3
- package/dist/client/components/TranslatorModal/TranslatorModal.js.map +1 -1
- package/dist/client/providers/Translator/TranslatorProvider.d.ts.map +1 -1
- package/dist/client/providers/Translator/TranslatorProvider.js +25 -19
- package/dist/client/providers/Translator/TranslatorProvider.js.map +1 -1
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +3 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/i18n-translations.d.ts +18 -0
- package/dist/i18n-translations.d.ts.map +1 -1
- package/dist/i18n-translations.js +18 -0
- package/dist/i18n-translations.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/resolvers/google.js +1 -1
- package/dist/resolvers/google.js.map +1 -1
- package/dist/resolvers/libreTranslate.d.ts +16 -0
- package/dist/resolvers/libreTranslate.d.ts.map +1 -0
- package/dist/resolvers/libreTranslate.js +48 -0
- package/dist/resolvers/libreTranslate.js.map +1 -0
- package/dist/resolvers/openAI.d.ts +2 -2
- package/dist/resolvers/openAI.d.ts.map +1 -1
- package/dist/resolvers/openAI.js +10 -10
- package/dist/resolvers/openAI.js.map +1 -1
- package/dist/translate/findEntityWithConfig.d.ts.map +1 -1
- package/dist/translate/findEntityWithConfig.js +4 -4
- package/dist/translate/findEntityWithConfig.js.map +1 -1
- package/dist/translate/operation.d.ts.map +1 -1
- package/dist/translate/operation.js +3 -1
- package/dist/translate/operation.js.map +1 -1
- package/dist/translate/traverseFields.d.ts.map +1 -1
- package/dist/translate/traverseFields.js +94 -86
- package/dist/translate/traverseFields.js.map +1 -1
- package/dist/translate/traverseRichText.js +3 -3
- package/dist/translate/traverseRichText.js.map +1 -1
- package/dist/translate/updateEntity.d.ts.map +1 -1
- package/dist/translate/updateEntity.js +2 -2
- package/dist/translate/updateEntity.js.map +1 -1
- package/package.json +17 -13
package/README.md
CHANGED
@@ -24,6 +24,7 @@ import { translator } from '@payload-enchants/translator';
|
|
24
24
|
import { copyResolver } from '@payload-enchants/translator/resolvers/copy';
|
25
25
|
import { googleResolver } from '@payload-enchants/translator/resolvers/google';
|
26
26
|
import { openAIResolver } from '@payload-enchants/translator/resolvers/openAI';
|
27
|
+
import { libreResolver } from '@payload-enchants/translator/resolvers/libreTranslate';
|
27
28
|
|
28
29
|
export default buildConfig({
|
29
30
|
plugins: [
|
@@ -41,6 +42,9 @@ export default buildConfig({
|
|
41
42
|
openAIResolver({
|
42
43
|
apiKey: process.env.OPENAI_KEY!,
|
43
44
|
}),
|
45
|
+
libreResolver({
|
46
|
+
apiKey: process.env.LIBRE_KEY!,
|
47
|
+
}),
|
44
48
|
],
|
45
49
|
}),
|
46
50
|
],
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/client/api/index.ts"],"sourcesContent":["import type { TranslateEndpointArgs, TranslateResult } from '../../translate/types';\n\nexport const createClient = ({ api, serverURL }: { api: string; serverURL: string }) => {\n const translate = async (args: TranslateEndpointArgs): Promise<TranslateResult> => {\n try {\n const response = await fetch(`${serverURL}${api}/translator/translate`, {\n body: JSON.stringify(args),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n });\n\n if (!response.ok) return { success: false };\n\n return response.json();\n } catch (e) {\n if (e instanceof Error) console.error(e.message);\n\n return { success: false };\n }\n };\n\n return {\n translate,\n };\n};\n"],"names":["createClient","api","serverURL","translate","args","response","fetch","body","JSON","stringify","credentials","headers","method","ok","success","json","e","Error","console","error","message"],"mappings":"AAEA,OAAO,MAAMA,eAAe,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAsC;IACjF,MAAMC,YAAY,OAAOC;QACvB,IAAI;YACF,MAAMC,WAAW,MAAMC,MAAM,
|
1
|
+
{"version":3,"sources":["../../../src/client/api/index.ts"],"sourcesContent":["import type { TranslateEndpointArgs, TranslateResult } from '../../translate/types';\n\nexport const createClient = ({ api, serverURL }: { api: string; serverURL: string }) => {\n const translate = async (args: TranslateEndpointArgs): Promise<TranslateResult> => {\n try {\n const response = await fetch(`${serverURL}${api}/translator/translate`, {\n body: JSON.stringify(args),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n });\n\n if (!response.ok) return { success: false };\n\n return response.json();\n } catch (e) {\n if (e instanceof Error) console.error(e.message);\n\n return { success: false };\n }\n };\n\n return {\n translate,\n };\n};\n"],"names":["createClient","api","serverURL","translate","args","response","fetch","body","JSON","stringify","credentials","headers","method","ok","success","json","e","Error","console","error","message"],"mappings":"AAEA,OAAO,MAAMA,eAAe,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAsC;IACjF,MAAMC,YAAY,OAAOC;QACvB,IAAI;YACF,MAAMC,WAAW,MAAMC,MAAM,GAAGJ,YAAYD,IAAI,qBAAqB,CAAC,EAAE;gBACtEM,MAAMC,KAAKC,SAAS,CAACL;gBACrBM,aAAa;gBACbC,SAAS;oBACP,gBAAgB;gBAClB;gBACAC,QAAQ;YACV;YAEA,IAAI,CAACP,SAASQ,EAAE,EAAE,OAAO;gBAAEC,SAAS;YAAM;YAE1C,OAAOT,SAASU,IAAI;QACtB,EAAE,OAAOC,GAAG;YACV,IAAIA,aAAaC,OAAOC,QAAQC,KAAK,CAACH,EAAEI,OAAO;YAE/C,OAAO;gBAAEN,SAAS;YAAM;QAC1B;IACF;IAEA,OAAO;QACLX;IACF;AACF,EAAE"}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import './styles.scss';
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
}) => string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null | undefined;
|
2
|
+
export declare const CustomButtonWithTranslator: ({ type }: {
|
3
|
+
type: "publish" | "save";
|
4
|
+
}) => import("react").JSX.Element;
|
6
5
|
//# sourceMappingURL=CustomButtonWithTranslator.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CustomButtonWithTranslator.d.ts","sourceRoot":"","sources":["../../../../src/client/components/CustomButton/CustomButtonWithTranslator.tsx"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC;
|
1
|
+
{"version":3,"file":"CustomButtonWithTranslator.d.ts","sourceRoot":"","sources":["../../../../src/client/components/CustomButton/CustomButtonWithTranslator.tsx"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC;AASvB,eAAO,MAAM,0BAA0B,aAAc;IAAE,IAAI,EAAE,SAAS,GAAG,MAAM,CAAA;CAAE,gCAsBhF,CAAC"}
|
@@ -1,15 +1,16 @@
|
|
1
1
|
'use client';
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
3
3
|
import './styles.scss';
|
4
|
-
import { useConfig, useDocumentInfo } from '@payloadcms/ui';
|
4
|
+
import { PublishButton, SaveButton, useConfig, useDocumentInfo } from '@payloadcms/ui';
|
5
5
|
import { TranslatorProvider } from '../../providers/Translator/TranslatorProvider';
|
6
6
|
import { ResolverButton } from '../ResolverButton';
|
7
7
|
import { TranslatorModal } from '../TranslatorModal';
|
8
|
-
export const CustomButtonWithTranslator = ({
|
9
|
-
const config = useConfig();
|
8
|
+
export const CustomButtonWithTranslator = ({ type })=>{
|
9
|
+
const { config } = useConfig();
|
10
|
+
const DefaultButton = type === 'publish' ? PublishButton : SaveButton;
|
10
11
|
const { globalSlug, id } = useDocumentInfo();
|
11
12
|
const resolvers = config.admin?.custom?.translator?.resolvers ?? [];
|
12
|
-
if (!id && !globalSlug) return
|
13
|
+
if (!id && !globalSlug) return /*#__PURE__*/ _jsx(DefaultButton, {});
|
13
14
|
return /*#__PURE__*/ _jsx(TranslatorProvider, {
|
14
15
|
children: /*#__PURE__*/ _jsxs("div", {
|
15
16
|
className: 'translator__custom-save-button',
|
@@ -18,7 +19,7 @@ export const CustomButtonWithTranslator = ({ defaultButton })=>{
|
|
18
19
|
resolvers.map((resolver)=>/*#__PURE__*/ _jsx(ResolverButton, {
|
19
20
|
resolver: resolver
|
20
21
|
}, resolver.key)),
|
21
|
-
|
22
|
+
/*#__PURE__*/ _jsx(DefaultButton, {})
|
22
23
|
]
|
23
24
|
})
|
24
25
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/components/CustomButton/CustomButtonWithTranslator.tsx"],"sourcesContent":["'use client';\n\nimport './styles.scss';\n\nimport { useConfig, useDocumentInfo } from '@payloadcms/ui';\
|
1
|
+
{"version":3,"sources":["../../../../src/client/components/CustomButton/CustomButtonWithTranslator.tsx"],"sourcesContent":["'use client';\n\nimport './styles.scss';\n\nimport { PublishButton, SaveButton, useConfig, useDocumentInfo } from '@payloadcms/ui';\n\nimport type { TranslateResolver } from '../../../resolvers/types';\nimport { TranslatorProvider } from '../../providers/Translator/TranslatorProvider';\nimport { ResolverButton } from '../ResolverButton';\nimport { TranslatorModal } from '../TranslatorModal';\n\nexport const CustomButtonWithTranslator = ({ type }: { type: 'publish' | 'save' }) => {\n const { config } = useConfig();\n\n const DefaultButton = type === 'publish' ? PublishButton : SaveButton;\n\n const { globalSlug, id } = useDocumentInfo();\n\n const resolvers = (config.admin?.custom?.translator?.resolvers as TranslateResolver[]) ?? [];\n\n if (!id && !globalSlug) return <DefaultButton />;\n\n return (\n <TranslatorProvider>\n <div className={'translator__custom-save-button'}>\n <TranslatorModal />\n {resolvers.map((resolver) => (\n <ResolverButton key={resolver.key} resolver={resolver} />\n ))}\n {<DefaultButton />}\n </div>\n </TranslatorProvider>\n );\n};\n"],"names":["PublishButton","SaveButton","useConfig","useDocumentInfo","TranslatorProvider","ResolverButton","TranslatorModal","CustomButtonWithTranslator","type","config","DefaultButton","globalSlug","id","resolvers","admin","custom","translator","div","className","map","resolver","key"],"mappings":"AAAA;;AAEA,OAAO,gBAAgB;AAEvB,SAASA,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,eAAe,QAAQ,iBAAiB;AAGvF,SAASC,kBAAkB,QAAQ,gDAAgD;AACnF,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,eAAe,QAAQ,qBAAqB;AAErD,OAAO,MAAMC,6BAA6B,CAAC,EAAEC,IAAI,EAAgC;IAC/E,MAAM,EAAEC,MAAM,EAAE,GAAGP;IAEnB,MAAMQ,gBAAgBF,SAAS,YAAYR,gBAAgBC;IAE3D,MAAM,EAAEU,UAAU,EAAEC,EAAE,EAAE,GAAGT;IAE3B,MAAMU,YAAY,AAACJ,OAAOK,KAAK,EAAEC,QAAQC,YAAYH,aAAqC,EAAE;IAE5F,IAAI,CAACD,MAAM,CAACD,YAAY,qBAAO,KAACD;IAEhC,qBACE,KAACN;kBACC,cAAA,MAACa;YAAIC,WAAW;;8BACd,KAACZ;gBACAO,UAAUM,GAAG,CAAC,CAACC,yBACd,KAACf;wBAAkCe,UAAUA;uBAAxBA,SAASC,GAAG;8BAElC,KAACX;;;;AAIV,EAAE"}
|
@@ -1,2 +1,3 @@
|
|
1
|
-
|
1
|
+
import type { CustomPublishButton, CustomSaveButton } from 'payload';
|
2
|
+
export declare const CustomButton: (type: "publish" | "save") => CustomPublishButton | CustomSaveButton;
|
2
3
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/components/CustomButton/index.tsx"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/components/CustomButton/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAErE,eAAO,MAAM,YAAY,SAAU,SAAS,GAAG,MAAM,KAAG,mBAAmB,GAAG,gBAO7E,CAAC"}
|
@@ -1,12 +1,9 @@
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import { DefaultPublishButton, DefaultSaveButton } from '@payloadcms/ui';
|
3
|
-
import { CustomButtonWithTranslator } from './CustomButtonWithTranslator';
|
4
1
|
export const CustomButton = (type)=>{
|
5
|
-
return
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
2
|
+
return {
|
3
|
+
clientProps: {
|
4
|
+
type
|
5
|
+
},
|
6
|
+
path: '@payload-enchants/translator/client#CustomButtonWithTranslator'
|
10
7
|
};
|
11
8
|
};
|
12
9
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/components/CustomButton/index.tsx"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../../../../src/client/components/CustomButton/index.tsx"],"sourcesContent":["import type { CustomPublishButton, CustomSaveButton } from 'payload';\n\nexport const CustomButton = (type: 'publish' | 'save'): CustomPublishButton | CustomSaveButton => {\n return {\n clientProps: {\n type,\n },\n path: '@payload-enchants/translator/client#CustomButtonWithTranslator',\n };\n};\n"],"names":["CustomButton","type","clientProps","path"],"mappings":"AAEA,OAAO,MAAMA,eAAe,CAACC;IAC3B,OAAO;QACLC,aAAa;YACXD;QACF;QACAE,MAAM;IACR;AACF,EAAE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/components/LocaleLabel/LocaleLabel.tsx"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations';\nimport { ChevronIcon, useTranslation } from '@payloadcms/ui';\nimport type { Locale } from 'payload';\n\nconst baseClass = 'localizer-button';\n\nexport const LocaleLabel = ({ locale }: { locale: Locale }) => {\n const { i18n, t } = useTranslation();\n\n return (\n <div aria-label={t('general:locale')} className={baseClass}>\n <div className={`${baseClass}__label`}>{`${t('general:locale')}:`}</div>\n \n <span className={`${baseClass}__current-label`}>\n {`${getTranslation(locale.label, i18n)}`}\n </span>\n \n <ChevronIcon className={`${baseClass}__chevron`} />\n </div>\n );\n};\n"],"names":["getTranslation","ChevronIcon","useTranslation","baseClass","LocaleLabel","locale","i18n","t","div","aria-label","className","span","label"],"mappings":";AAAA,SAASA,cAAc,QAAQ,2BAA2B;AAC1D,SAASC,WAAW,EAAEC,cAAc,QAAQ,iBAAiB;AAG7D,MAAMC,YAAY;AAElB,OAAO,MAAMC,cAAc,CAAC,EAAEC,MAAM,EAAsB;IACxD,MAAM,EAAEC,IAAI,EAAEC,CAAC,EAAE,GAAGL;IAEpB,qBACE,MAACM;QAAIC,cAAYF,EAAE;QAAmBG,WAAWP;;0BAC/C,KAACK;gBAAIE,WAAW,
|
1
|
+
{"version":3,"sources":["../../../../src/client/components/LocaleLabel/LocaleLabel.tsx"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations';\nimport { ChevronIcon, useTranslation } from '@payloadcms/ui';\nimport type { Locale } from 'payload';\n\nconst baseClass = 'localizer-button';\n\nexport const LocaleLabel = ({ locale }: { locale: Locale }) => {\n const { i18n, t } = useTranslation();\n\n return (\n <div aria-label={t('general:locale')} className={baseClass}>\n <div className={`${baseClass}__label`}>{`${t('general:locale')}:`}</div>\n \n <span className={`${baseClass}__current-label`}>\n {`${getTranslation(locale.label, i18n)}`}\n </span>\n \n <ChevronIcon className={`${baseClass}__chevron`} />\n </div>\n );\n};\n"],"names":["getTranslation","ChevronIcon","useTranslation","baseClass","LocaleLabel","locale","i18n","t","div","aria-label","className","span","label"],"mappings":";AAAA,SAASA,cAAc,QAAQ,2BAA2B;AAC1D,SAASC,WAAW,EAAEC,cAAc,QAAQ,iBAAiB;AAG7D,MAAMC,YAAY;AAElB,OAAO,MAAMC,cAAc,CAAC,EAAEC,MAAM,EAAsB;IACxD,MAAM,EAAEC,IAAI,EAAEC,CAAC,EAAE,GAAGL;IAEpB,qBACE,MAACM;QAAIC,cAAYF,EAAE;QAAmBG,WAAWP;;0BAC/C,KAACK;gBAAIE,WAAW,GAAGP,UAAU,OAAO,CAAC;0BAAG,GAAGI,EAAE,kBAAkB,CAAC,CAAC;;YAAO;0BAExE,KAACI;gBAAKD,WAAW,GAAGP,UAAU,eAAe,CAAC;0BAC3C,GAAGH,eAAeK,OAAOO,KAAK,EAAEN,OAAO;;YACnC;0BAEP,KAACL;gBAAYS,WAAW,GAAGP,UAAU,SAAS,CAAC;;;;AAGrD,EAAE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/components/ResolverButton/ResolverButton.tsx"],"sourcesContent":["import { Button, useTranslation } from '@payloadcms/ui';\n\nimport type { TranslateResolver } from '../../../resolvers/types';\nimport { useTranslator } from '../../providers/Translator/context';\n\nexport const ResolverButton = ({\n resolver: { key: resolverKey },\n}: {\n resolver: TranslateResolver;\n}) => {\n const { openTranslator } = useTranslator();\n\n const { t } = useTranslation();\n\n const handleClick = () => openTranslator({ resolverKey });\n\n return (\n <Button onClick={handleClick}
|
1
|
+
{"version":3,"sources":["../../../../src/client/components/ResolverButton/ResolverButton.tsx"],"sourcesContent":["import { Button, useTranslation } from '@payloadcms/ui';\n\nimport type { TranslateResolver } from '../../../resolvers/types';\nimport { useTranslator } from '../../providers/Translator/context';\n\nexport const ResolverButton = ({\n resolver: { key: resolverKey },\n}: {\n resolver: TranslateResolver;\n}) => {\n const { openTranslator } = useTranslator();\n\n const { t } = useTranslation();\n\n const handleClick = () => openTranslator({ resolverKey });\n\n return (\n <Button onClick={handleClick}>\n {t(`plugin-translator:resolver_${resolverKey}_buttonLabel` as Parameters<typeof t>[0])}\n </Button>\n );\n};\n"],"names":["Button","useTranslation","useTranslator","ResolverButton","resolver","key","resolverKey","openTranslator","t","handleClick","onClick"],"mappings":";AAAA,SAASA,MAAM,EAAEC,cAAc,QAAQ,iBAAiB;AAGxD,SAASC,aAAa,QAAQ,qCAAqC;AAEnE,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,UAAU,EAAEC,KAAKC,WAAW,EAAE,EAG/B;IACC,MAAM,EAAEC,cAAc,EAAE,GAAGL;IAE3B,MAAM,EAAEM,CAAC,EAAE,GAAGP;IAEd,MAAMQ,cAAc,IAAMF,eAAe;YAAED;QAAY;IAEvD,qBACE,KAACN;QAAOU,SAASD;kBACdD,EAAE,CAAC,2BAA2B,EAAEF,YAAY,YAAY,CAAC;;AAGhE,EAAE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"TranslatorModal.d.ts","sourceRoot":"","sources":["../../../../src/client/components/TranslatorModal/TranslatorModal.tsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAOvB,eAAO,MAAM,eAAe,+
|
1
|
+
{"version":3,"file":"TranslatorModal.d.ts","sourceRoot":"","sources":["../../../../src/client/components/TranslatorModal/TranslatorModal.tsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAOvB,eAAO,MAAM,eAAe,+CAa3B,CAAC"}
|
@@ -12,11 +12,10 @@ export const TranslatorModal = ()=>{
|
|
12
12
|
children: /*#__PURE__*/ _jsxs("div", {
|
13
13
|
className: 'translator__wrapper',
|
14
14
|
children: [
|
15
|
-
/*#__PURE__*/ _jsx("
|
15
|
+
/*#__PURE__*/ _jsx("button", {
|
16
16
|
"aria-label": "Close",
|
17
17
|
className: 'translator__close',
|
18
|
-
onClick: closeTranslator
|
19
|
-
role: "button"
|
18
|
+
onClick: closeTranslator
|
20
19
|
}),
|
21
20
|
/*#__PURE__*/ _jsx(Content, {})
|
22
21
|
]
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/components/TranslatorModal/TranslatorModal.tsx"],"sourcesContent":["import './styles.scss';\n\nimport { Modal } from '@payloadcms/ui';\n\nimport { useTranslator } from '../../providers/Translator/context';\nimport { Content } from './Content';\n\nexport const TranslatorModal = () => {\n const { closeTranslator, modalSlug, resolver } = useTranslator();\n\n if (!resolver) return;\n\n return (\n <Modal className={'translator__modal'} slug={modalSlug}>\n <div className={'translator__wrapper'}>\n <
|
1
|
+
{"version":3,"sources":["../../../../src/client/components/TranslatorModal/TranslatorModal.tsx"],"sourcesContent":["import './styles.scss';\n\nimport { Modal } from '@payloadcms/ui';\n\nimport { useTranslator } from '../../providers/Translator/context';\nimport { Content } from './Content';\n\nexport const TranslatorModal = () => {\n const { closeTranslator, modalSlug, resolver } = useTranslator();\n\n if (!resolver) return;\n\n return (\n <Modal className={'translator__modal'} slug={modalSlug}>\n <div className={'translator__wrapper'}>\n <button aria-label='Close' className={'translator__close'} onClick={closeTranslator} />\n <Content />\n </div>\n </Modal>\n );\n};\n"],"names":["Modal","useTranslator","Content","TranslatorModal","closeTranslator","modalSlug","resolver","className","slug","div","button","aria-label","onClick"],"mappings":";AAAA,OAAO,gBAAgB;AAEvB,SAASA,KAAK,QAAQ,iBAAiB;AAEvC,SAASC,aAAa,QAAQ,qCAAqC;AACnE,SAASC,OAAO,QAAQ,YAAY;AAEpC,OAAO,MAAMC,kBAAkB;IAC7B,MAAM,EAAEC,eAAe,EAAEC,SAAS,EAAEC,QAAQ,EAAE,GAAGL;IAEjD,IAAI,CAACK,UAAU;IAEf,qBACE,KAACN;QAAMO,WAAW;QAAqBC,MAAMH;kBAC3C,cAAA,MAACI;YAAIF,WAAW;;8BACd,KAACG;oBAAOC,cAAW;oBAAQJ,WAAW;oBAAqBK,SAASR;;8BACpE,KAACF;;;;AAIT,EAAE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"TranslatorProvider.d.ts","sourceRoot":"","sources":["../../../../src/client/providers/Translator/TranslatorProvider.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,SAAS,EAAgC,MAAM,OAAO,CAAC;AASrE,eAAO,MAAM,kBAAkB,iBAAkB;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,
|
1
|
+
{"version":3,"file":"TranslatorProvider.d.ts","sourceRoot":"","sources":["../../../../src/client/providers/Translator/TranslatorProvider.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,SAAS,EAAgC,MAAM,OAAO,CAAC;AASrE,eAAO,MAAM,kBAAkB,iBAAkB;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,gCA4IvE,CAAC"}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import { toast, useAllFormFields, useConfig, useDocumentInfo, useForm, useLocale, useModal, useTranslation } from '@payloadcms/ui';
|
3
|
-
import { getFormState } from '@payloadcms/ui/shared';
|
2
|
+
import { toast, useAllFormFields, useConfig, useDocumentInfo, useForm, useLocale, useModal, useServerFunctions, useTranslation } from '@payloadcms/ui';
|
4
3
|
import { reduceFieldsToValues } from 'payload/shared';
|
5
4
|
import { useEffect, useMemo, useState } from 'react';
|
6
5
|
import { createClient } from '../../api';
|
@@ -9,7 +8,8 @@ const modalSlug = 'translator-modal';
|
|
9
8
|
export const TranslatorProvider = ({ children })=>{
|
10
9
|
const [resolver, setResolver] = useState(null);
|
11
10
|
const [data, dispatch] = useAllFormFields();
|
12
|
-
const {
|
11
|
+
const { getFormState } = useServerFunctions();
|
12
|
+
const { collectionSlug, getDocPreferences, globalSlug, id } = useDocumentInfo();
|
13
13
|
const { setModified } = useForm();
|
14
14
|
const modal = useModal();
|
15
15
|
const { t } = useTranslation();
|
@@ -18,7 +18,7 @@ export const TranslatorProvider = ({ children })=>{
|
|
18
18
|
return t(`plugin-translator:resolver_${resolver}_${key}`);
|
19
19
|
};
|
20
20
|
const locale = useLocale();
|
21
|
-
const { admin: { custom }, localization, routes: { api }, serverURL } = useConfig();
|
21
|
+
const { config: { admin: { custom }, localization, routes: { api }, serverURL } } = useConfig();
|
22
22
|
const apiClient = createClient({
|
23
23
|
api,
|
24
24
|
serverURL
|
@@ -41,7 +41,9 @@ export const TranslatorProvider = ({ children })=>{
|
|
41
41
|
if (defaultFromOptions) setLocaleToTranslateFrom(defaultFromOptions.code);
|
42
42
|
setLocaleToTranslateFrom(localesOptions[0].code);
|
43
43
|
}, [
|
44
|
-
locale
|
44
|
+
locale,
|
45
|
+
localesOptions,
|
46
|
+
localization.defaultLocale
|
45
47
|
]);
|
46
48
|
const closeTranslator = ()=>modal.closeModal(modalSlug);
|
47
49
|
const submit = async ({ emptyOnly })=>{
|
@@ -61,21 +63,25 @@ export const TranslatorProvider = ({ children })=>{
|
|
61
63
|
toast.error(resolverT('errorMessage'));
|
62
64
|
return;
|
63
65
|
}
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
66
|
+
const { state } = await getFormState({
|
67
|
+
collectionSlug,
|
68
|
+
data: result.translatedData,
|
69
|
+
docPermissions: {
|
70
|
+
fields: true,
|
71
|
+
update: true
|
72
|
+
},
|
73
|
+
docPreferences: await getDocPreferences(),
|
74
|
+
globalSlug,
|
75
|
+
locale: locale.code,
|
76
|
+
operation: 'update',
|
77
|
+
renderAllFields: true,
|
78
|
+
schemaPath: collectionSlug || globalSlug || ''
|
77
79
|
});
|
78
|
-
if (
|
80
|
+
if (state) {
|
81
|
+
dispatch({
|
82
|
+
state,
|
83
|
+
type: 'REPLACE_STATE'
|
84
|
+
});
|
79
85
|
setModified(true);
|
80
86
|
toast.success(resolverT('successMessage'));
|
81
87
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/providers/Translator/TranslatorProvider.tsx"],"sourcesContent":["import {\n toast,\n useAllFormFields,\n useConfig,\n useDocumentInfo,\n useForm,\n useLocale,\n useModal,\n useTranslation,\n} from '@payloadcms/ui';\nimport {
|
1
|
+
{"version":3,"sources":["../../../../src/client/providers/Translator/TranslatorProvider.tsx"],"sourcesContent":["import {\n toast,\n useAllFormFields,\n useConfig,\n useDocumentInfo,\n useForm,\n useLocale,\n useModal,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui';\nimport { reduceFieldsToValues } from 'payload/shared';\nimport { type ReactNode, useEffect, useMemo, useState } from 'react';\n\nimport type { TranslateResolver } from '../../../resolvers/types';\nimport type { TranslateArgs } from '../../../translate/types';\nimport { createClient } from '../../api';\nimport { TranslatorContext } from './context';\n\nconst modalSlug = 'translator-modal';\n\nexport const TranslatorProvider = ({ children }: { children: ReactNode }) => {\n const [resolver, setResolver] = useState<null | string>(null);\n\n const [data, dispatch] = useAllFormFields();\n\n const { getFormState } = useServerFunctions();\n\n const { collectionSlug, getDocPreferences, globalSlug, id } = useDocumentInfo();\n\n const { setModified } = useForm();\n\n const modal = useModal();\n\n const { t } = useTranslation();\n\n const resolverT = (\n key:\n | 'buttonLabel'\n | 'errorMessage'\n | 'modalTitle'\n | 'submitButtonLabelEmpty'\n | 'submitButtonLabelFull'\n | 'successMessage',\n ) => {\n if (!resolver) return '';\n\n return t(`plugin-translator:resolver_${resolver}_${key}` as Parameters<typeof t>[0]);\n };\n\n const locale = useLocale();\n\n const {\n config: {\n admin: { custom },\n localization,\n routes: { api },\n serverURL,\n },\n } = useConfig();\n\n const apiClient = createClient({ api, serverURL });\n\n const resolverConfig = useMemo(() => {\n if (!resolver) return null;\n\n const resolvers = (custom?.translator?.resolvers as TranslateResolver[]) || undefined;\n\n if (!resolvers) return null;\n\n const resolverConfig = resolvers.find((each) => each.key === resolver);\n\n return resolverConfig ?? null;\n }, [custom, resolver]);\n\n if (!localization)\n throw new Error('Localization config is not provided and PluginTranslator is used');\n\n const localesOptions = localization.locales.filter((each) => each.code !== locale.code);\n\n const [localeToTranslateFrom, setLocaleToTranslateFrom] = useState<string>('');\n\n useEffect(() => {\n const defaultFromOptions = localesOptions.find(\n (each) => localization.defaultLocale === each.code,\n );\n\n if (defaultFromOptions) setLocaleToTranslateFrom(defaultFromOptions.code);\n setLocaleToTranslateFrom(localesOptions[0].code);\n }, [locale, localesOptions, localization.defaultLocale]);\n\n const closeTranslator = () => modal.closeModal(modalSlug);\n\n const submit = async ({ emptyOnly }: { emptyOnly: boolean }) => {\n if (!resolver) return;\n\n const args: TranslateArgs = {\n collectionSlug,\n data: reduceFieldsToValues(data, true),\n emptyOnly,\n globalSlug,\n id: id === null ? undefined : id,\n locale: locale.code,\n localeFrom: localeToTranslateFrom,\n resolver,\n };\n\n const result = await apiClient.translate(args);\n\n if (!result.success) {\n toast.error(resolverT('errorMessage'));\n\n return;\n }\n\n const { state } = await getFormState({\n collectionSlug,\n data: result.translatedData,\n docPermissions: {\n fields: true,\n update: true,\n },\n docPreferences: await getDocPreferences(),\n globalSlug,\n locale: locale.code,\n operation: 'update',\n renderAllFields: true,\n schemaPath: collectionSlug || globalSlug || '',\n });\n\n if (state) {\n dispatch({\n state,\n type: 'REPLACE_STATE',\n });\n setModified(true);\n toast.success(resolverT('successMessage'));\n }\n closeTranslator();\n };\n\n return (\n <TranslatorContext.Provider\n value={{\n closeTranslator,\n localeToTranslateFrom,\n localesOptions,\n modalSlug,\n openTranslator: ({ resolverKey }) => {\n setResolver(resolverKey);\n modal.openModal(modalSlug);\n },\n resolver: resolverConfig,\n resolverT,\n setLocaleToTranslateFrom,\n submit,\n }}\n >\n {children}\n </TranslatorContext.Provider>\n );\n};\n"],"names":["toast","useAllFormFields","useConfig","useDocumentInfo","useForm","useLocale","useModal","useServerFunctions","useTranslation","reduceFieldsToValues","useEffect","useMemo","useState","createClient","TranslatorContext","modalSlug","TranslatorProvider","children","resolver","setResolver","data","dispatch","getFormState","collectionSlug","getDocPreferences","globalSlug","id","setModified","modal","t","resolverT","key","locale","config","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","translatedData","docPermissions","fields","update","docPreferences","operation","renderAllFields","schemaPath","type","Provider","value","openTranslator","resolverKey","openModal"],"mappings":";AAAA,SACEA,KAAK,EACLC,gBAAgB,EAChBC,SAAS,EACTC,eAAe,EACfC,OAAO,EACPC,SAAS,EACTC,QAAQ,EACRC,kBAAkB,EAClBC,cAAc,QACT,iBAAiB;AACxB,SAASC,oBAAoB,QAAQ,iBAAiB;AACtD,SAAyBC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAIrE,SAASC,YAAY,QAAQ,YAAY;AACzC,SAASC,iBAAiB,QAAQ,YAAY;AAE9C,MAAMC,YAAY;AAElB,OAAO,MAAMC,qBAAqB,CAAC,EAAEC,QAAQ,EAA2B;IACtE,MAAM,CAACC,UAAUC,YAAY,GAAGP,SAAwB;IAExD,MAAM,CAACQ,MAAMC,SAAS,GAAGpB;IAEzB,MAAM,EAAEqB,YAAY,EAAE,GAAGf;IAEzB,MAAM,EAAEgB,cAAc,EAAEC,iBAAiB,EAAEC,UAAU,EAAEC,EAAE,EAAE,GAAGvB;IAE9D,MAAM,EAAEwB,WAAW,EAAE,GAAGvB;IAExB,MAAMwB,QAAQtB;IAEd,MAAM,EAAEuB,CAAC,EAAE,GAAGrB;IAEd,MAAMsB,YAAY,CAChBC;QAQA,IAAI,CAACb,UAAU,OAAO;QAEtB,OAAOW,EAAE,CAAC,2BAA2B,EAAEX,SAAS,CAAC,EAAEa,KAAK;IAC1D;IAEA,MAAMC,SAAS3B;IAEf,MAAM,EACJ4B,QAAQ,EACNC,OAAO,EAAEC,MAAM,EAAE,EACjBC,YAAY,EACZC,QAAQ,EAAEC,GAAG,EAAE,EACfC,SAAS,EACV,EACF,GAAGrC;IAEJ,MAAMsC,YAAY3B,aAAa;QAAEyB;QAAKC;IAAU;IAEhD,MAAME,iBAAiB9B,QAAQ;QAC7B,IAAI,CAACO,UAAU,OAAO;QAEtB,MAAMwB,YAAY,AAACP,QAAQQ,YAAYD,aAAqCE;QAE5E,IAAI,CAACF,WAAW,OAAO;QAEvB,MAAMD,iBAAiBC,UAAUG,IAAI,CAAC,CAACC,OAASA,KAAKf,GAAG,KAAKb;QAE7D,OAAOuB,kBAAkB;IAC3B,GAAG;QAACN;QAAQjB;KAAS;IAErB,IAAI,CAACkB,cACH,MAAM,IAAIW,MAAM;IAElB,MAAMC,iBAAiBZ,aAAaa,OAAO,CAACC,MAAM,CAAC,CAACJ,OAASA,KAAKK,IAAI,KAAKnB,OAAOmB,IAAI;IAEtF,MAAM,CAACC,uBAAuBC,yBAAyB,GAAGzC,SAAiB;IAE3EF,UAAU;QACR,MAAM4C,qBAAqBN,eAAeH,IAAI,CAC5C,CAACC,OAASV,aAAamB,aAAa,KAAKT,KAAKK,IAAI;QAGpD,IAAIG,oBAAoBD,yBAAyBC,mBAAmBH,IAAI;QACxEE,yBAAyBL,cAAc,CAAC,EAAE,CAACG,IAAI;IACjD,GAAG;QAACnB;QAAQgB;QAAgBZ,aAAamB,aAAa;KAAC;IAEvD,MAAMC,kBAAkB,IAAM5B,MAAM6B,UAAU,CAAC1C;IAE/C,MAAM2C,SAAS,OAAO,EAAEC,SAAS,EAA0B;QACzD,IAAI,CAACzC,UAAU;QAEf,MAAM0C,OAAsB;YAC1BrC;YACAH,MAAMX,qBAAqBW,MAAM;YACjCuC;YACAlC;YACAC,IAAIA,OAAO,OAAOkB,YAAYlB;YAC9BM,QAAQA,OAAOmB,IAAI;YACnBU,YAAYT;YACZlC;QACF;QAEA,MAAM4C,SAAS,MAAMtB,UAAUuB,SAAS,CAACH;QAEzC,IAAI,CAACE,OAAOE,OAAO,EAAE;YACnBhE,MAAMiE,KAAK,CAACnC,UAAU;YAEtB;QACF;QAEA,MAAM,EAAEoC,KAAK,EAAE,GAAG,MAAM5C,aAAa;YACnCC;YACAH,MAAM0C,OAAOK,cAAc;YAC3BC,gBAAgB;gBACdC,QAAQ;gBACRC,QAAQ;YACV;YACAC,gBAAgB,MAAM/C;YACtBC;YACAO,QAAQA,OAAOmB,IAAI;YACnBqB,WAAW;YACXC,iBAAiB;YACjBC,YAAYnD,kBAAkBE,cAAc;QAC9C;QAEA,IAAIyC,OAAO;YACT7C,SAAS;gBACP6C;gBACAS,MAAM;YACR;YACAhD,YAAY;YACZ3B,MAAMgE,OAAO,CAAClC,UAAU;QAC1B;QACA0B;IACF;IAEA,qBACE,KAAC1C,kBAAkB8D,QAAQ;QACzBC,OAAO;YACLrB;YACAJ;YACAJ;YACAjC;YACA+D,gBAAgB,CAAC,EAAEC,WAAW,EAAE;gBAC9B5D,YAAY4D;gBACZnD,MAAMoD,SAAS,CAACjE;YAClB;YACAG,UAAUuB;YACVX;YACAuB;YACAK;QACF;kBAECzC;;AAGP,EAAE"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,8DAA8D,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { CustomButtonWithTranslator } from '../client/components/CustomButton/CustomButtonWithTranslator';\n"],"names":["CustomButtonWithTranslator"],"mappings":"AAAA,SAASA,0BAA0B,QAAQ,+DAA+D"}
|
@@ -13,6 +13,12 @@ export declare const translations: {
|
|
13
13
|
resolver_google_submitButtonLabelEmpty: string;
|
14
14
|
resolver_google_submitButtonLabelFull: string;
|
15
15
|
resolver_google_successMessage: string;
|
16
|
+
resolver_libre_buttonLabel: string;
|
17
|
+
resolver_libre_errorMessage: string;
|
18
|
+
resolver_libre_modalTitle: string;
|
19
|
+
resolver_libre_submitButtonLabelEmpty: string;
|
20
|
+
resolver_libre_submitButtonLabelFull: string;
|
21
|
+
resolver_libre_successMessage: string;
|
16
22
|
resolver_openai_buttonLabel: string;
|
17
23
|
resolver_openai_errorMessage: string;
|
18
24
|
resolver_openai_modalTitle: string;
|
@@ -35,6 +41,12 @@ export declare const translations: {
|
|
35
41
|
resolver_google_submitButtonLabelEmpty: string;
|
36
42
|
resolver_google_submitButtonLabelFull: string;
|
37
43
|
resolver_google_successMessage: string;
|
44
|
+
resolver_libre_buttonLabel: string;
|
45
|
+
resolver_libre_errorMessage: string;
|
46
|
+
resolver_libre_modalTitle: string;
|
47
|
+
resolver_libre_submitButtonLabelEmpty: string;
|
48
|
+
resolver_libre_submitButtonLabelFull: string;
|
49
|
+
resolver_libre_successMessage: string;
|
38
50
|
resolver_openai_buttonLabel: string;
|
39
51
|
resolver_openai_errorMessage: string;
|
40
52
|
resolver_openai_modalTitle: string;
|
@@ -57,6 +69,12 @@ export declare const translations: {
|
|
57
69
|
resolver_google_submitButtonLabelEmpty: string;
|
58
70
|
resolver_google_submitButtonLabelFull: string;
|
59
71
|
resolver_google_successMessage: string;
|
72
|
+
resolver_libre_buttonLabel: string;
|
73
|
+
resolver_libre_errorMessage: string;
|
74
|
+
resolver_libre_modalTitle: string;
|
75
|
+
resolver_libre_submitButtonLabelEmpty: string;
|
76
|
+
resolver_libre_submitButtonLabelFull: string;
|
77
|
+
resolver_libre_successMessage: string;
|
60
78
|
resolver_openai_buttonLabel: string;
|
61
79
|
resolver_openai_errorMessage: string;
|
62
80
|
resolver_openai_modalTitle: string;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"i18n-translations.d.ts","sourceRoot":"","sources":["../src/i18n-translations.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY
|
1
|
+
{"version":3,"file":"i18n-translations.d.ts","sourceRoot":"","sources":["../src/i18n-translations.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkGxB,CAAC"}
|
@@ -13,6 +13,12 @@ export const translations = {
|
|
13
13
|
resolver_google_submitButtonLabelEmpty: 'Translate only empty fields',
|
14
14
|
resolver_google_submitButtonLabelFull: 'Translate all',
|
15
15
|
resolver_google_successMessage: 'Successfully translated. Press "Save" to apply the changes.',
|
16
|
+
resolver_libre_buttonLabel: 'Libre Translate',
|
17
|
+
resolver_libre_errorMessage: 'An error occurred when trying to translate the data',
|
18
|
+
resolver_libre_modalTitle: 'Choose the locale to translate from',
|
19
|
+
resolver_libre_submitButtonLabelEmpty: 'Translate only empty fields',
|
20
|
+
resolver_libre_submitButtonLabelFull: 'Translate all',
|
21
|
+
resolver_libre_successMessage: 'Successfully translated. Press "Save" to apply the changes.',
|
16
22
|
resolver_openai_buttonLabel: 'AI Translate',
|
17
23
|
resolver_openai_errorMessage: 'An error occurred when trying to translate the data',
|
18
24
|
resolver_openai_modalTitle: 'Choose the locale to translate from',
|
@@ -35,6 +41,12 @@ export const translations = {
|
|
35
41
|
resolver_google_submitButtonLabelEmpty: 'Перекласти лише порожні поля',
|
36
42
|
resolver_google_submitButtonLabelFull: 'Перекласти все',
|
37
43
|
resolver_google_successMessage: 'Успішно перекладено. Натисніть "Зберегти", щоб застосувати зміни.',
|
44
|
+
resolver_libre_buttonLabel: 'Переклад Libre',
|
45
|
+
resolver_libre_errorMessage: 'Сталася помилка під час спроби перекладу даних',
|
46
|
+
resolver_libre_modalTitle: 'Виберіть локаль для перекладу',
|
47
|
+
resolver_libre_submitButtonLabelEmpty: 'Перекласти лише порожні поля',
|
48
|
+
resolver_libre_submitButtonLabelFull: 'Перекласти все',
|
49
|
+
resolver_libre_successMessage: 'Успішно перекладено. Натисніть "Зберегти", щоб застосувати зміни.',
|
38
50
|
resolver_openai_buttonLabel: 'Переклад AI',
|
39
51
|
resolver_openai_errorMessage: 'Сталася помилка під час спроби перекладу даних',
|
40
52
|
resolver_openai_modalTitle: 'Виберіть локаль для перекладу',
|
@@ -57,6 +69,12 @@ export const translations = {
|
|
57
69
|
resolver_google_submitButtonLabelEmpty: '仅翻译空字段',
|
58
70
|
resolver_google_submitButtonLabelFull: '翻译全部',
|
59
71
|
resolver_google_successMessage: '翻译成功。按下“保存”以应用更改。',
|
72
|
+
resolver_libre_buttonLabel: '自由翻译',
|
73
|
+
resolver_libre_errorMessage: '尝试翻译数据时发生错误',
|
74
|
+
resolver_libre_modalTitle: '选择要翻译的语言',
|
75
|
+
resolver_libre_submitButtonLabelEmpty: '仅翻译空字段',
|
76
|
+
resolver_libre_submitButtonLabelFull: '翻译全部',
|
77
|
+
resolver_libre_successMessage: '翻译成功。按下“保存”以应用更改。',
|
60
78
|
resolver_openai_buttonLabel: 'AI翻译',
|
61
79
|
resolver_openai_errorMessage: '尝试翻译数据时发生错误',
|
62
80
|
resolver_openai_modalTitle: '选择要翻译的语言',
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/i18n-translations.ts"],"sourcesContent":["export const translations = {\n en: {\n 'plugin-translator': {\n resolver_copy_buttonLabel: 'Copy from other locale',\n resolver_copy_errorMessage: 'An error occurred when trying to translate the data',\n resolver_copy_modalTitle: 'Choose the locale to copy from',\n resolver_copy_submitButtonLabelEmpty: 'Copy only empty fields',\n resolver_copy_submitButtonLabelFull: 'Copy all',\n resolver_copy_successMessage: 'Successfully copied. Press \"Save\" to apply the changes.',\n\n resolver_google_buttonLabel: 'Google Translate',\n resolver_google_errorMessage: 'An error occurred when trying to translate the data',\n resolver_google_modalTitle: 'Choose the locale to translate from',\n resolver_google_submitButtonLabelEmpty: 'Translate only empty fields',\n resolver_google_submitButtonLabelFull: 'Translate all',\n resolver_google_successMessage: 'Successfully translated. Press \"Save\" to apply the changes.',\n\n resolver_openai_buttonLabel: 'AI Translate',\n resolver_openai_errorMessage: 'An error occurred when trying to translate the data',\n resolver_openai_modalTitle: 'Choose the locale to translate from',\n resolver_openai_submitButtonLabelEmpty: 'Translate only empty fields',\n resolver_openai_submitButtonLabelFull: 'Translate all',\n resolver_openai_successMessage: 'Successfully translated. Press \"Save\" to apply the changes.',\n },\n },\n uk: {\n 'plugin-translator': {\n resolver_copy_buttonLabel: 'Копіювати з іншої локалі',\n resolver_copy_errorMessage: 'Сталася помилка під час спроби перекладу даних',\n resolver_copy_modalTitle: 'Виберіть локаль для копіювання',\n resolver_copy_submitButtonLabelEmpty: 'Копіювати лише порожні поля',\n resolver_copy_submitButtonLabelFull: 'Копіювати все',\n resolver_copy_successMessage:\n 'Успішно скопійовано. Натисніть \"Зберегти\", щоб застосувати зміни.',\n resolver_google_buttonLabel: 'Переклад Google',\n resolver_google_errorMessage: 'Сталася помилка під час спроби перекладу даних',\n resolver_google_modalTitle: 'Виберіть локаль для перекладу',\n resolver_google_submitButtonLabelEmpty: 'Перекласти лише порожні поля',\n resolver_google_submitButtonLabelFull: 'Перекласти все',\n resolver_google_successMessage:\n 'Успішно перекладено. Натисніть \"Зберегти\", щоб застосувати зміни.',\n resolver_openai_buttonLabel: 'Переклад AI',\n resolver_openai_errorMessage: 'Сталася помилка під час спроби перекладу даних',\n resolver_openai_modalTitle: 'Виберіть локаль для перекладу',\n resolver_openai_submitButtonLabelEmpty: 'Перекласти лише порожні поля',\n resolver_openai_submitButtonLabelFull: 'Перекласти все',\n resolver_openai_successMessage:\n 'Успішно перекладено. Натисніть \"Зберегти\", щоб застосувати зміни.',\n },\n },\n zh: {\n 'plugin-translator': {\n resolver_copy_buttonLabel: '从其他语言复制',\n resolver_copy_errorMessage: '尝试翻译数据时发生错误',\n resolver_copy_modalTitle: '选择要复制的语言',\n resolver_copy_submitButtonLabelEmpty: '仅复制空字段',\n resolver_copy_submitButtonLabelFull: '复制全部',\n resolver_copy_successMessage: '复制成功。按下“保存”以应用更改。',\n\n resolver_google_buttonLabel: '谷歌翻译',\n resolver_google_errorMessage: '尝试翻译数据时发生错误',\n resolver_google_modalTitle: '选择要翻译的语言',\n resolver_google_submitButtonLabelEmpty: '仅翻译空字段',\n resolver_google_submitButtonLabelFull: '翻译全部',\n resolver_google_successMessage: '翻译成功。按下“保存”以应用更改。',\n\n resolver_openai_buttonLabel: 'AI翻译',\n resolver_openai_errorMessage: '尝试翻译数据时发生错误',\n resolver_openai_modalTitle: '选择要翻译的语言',\n resolver_openai_submitButtonLabelEmpty: '仅翻译空字段',\n resolver_openai_submitButtonLabelFull: '翻译全部',\n resolver_openai_successMessage: '翻译成功。按下“保存”以应用更改。',\n },\n },\n};\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","uk","zh"],"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;IACAC,IAAI;QACF,qBAAqB;
|
1
|
+
{"version":3,"sources":["../src/i18n-translations.ts"],"sourcesContent":["export const translations = {\n en: {\n 'plugin-translator': {\n resolver_copy_buttonLabel: 'Copy from other locale',\n resolver_copy_errorMessage: 'An error occurred when trying to translate the data',\n resolver_copy_modalTitle: 'Choose the locale to copy from',\n resolver_copy_submitButtonLabelEmpty: 'Copy only empty fields',\n resolver_copy_submitButtonLabelFull: 'Copy all',\n resolver_copy_successMessage: 'Successfully copied. Press \"Save\" to apply the changes.',\n\n resolver_google_buttonLabel: 'Google Translate',\n resolver_google_errorMessage: 'An error occurred when trying to translate the data',\n resolver_google_modalTitle: 'Choose the locale to translate from',\n resolver_google_submitButtonLabelEmpty: 'Translate only empty fields',\n resolver_google_submitButtonLabelFull: 'Translate all',\n resolver_google_successMessage: 'Successfully translated. Press \"Save\" to apply the changes.',\n\n resolver_libre_buttonLabel: 'Libre Translate',\n resolver_libre_errorMessage: 'An error occurred when trying to translate the data',\n resolver_libre_modalTitle: 'Choose the locale to translate from',\n resolver_libre_submitButtonLabelEmpty: 'Translate only empty fields',\n resolver_libre_submitButtonLabelFull: 'Translate all',\n resolver_libre_successMessage: 'Successfully translated. Press \"Save\" to apply the changes.',\n\n resolver_openai_buttonLabel: 'AI Translate',\n resolver_openai_errorMessage: 'An error occurred when trying to translate the data',\n resolver_openai_modalTitle: 'Choose the locale to translate from',\n resolver_openai_submitButtonLabelEmpty: 'Translate only empty fields',\n resolver_openai_submitButtonLabelFull: 'Translate all',\n resolver_openai_successMessage: 'Successfully translated. Press \"Save\" to apply the changes.',\n },\n },\n uk: {\n 'plugin-translator': {\n resolver_copy_buttonLabel: 'Копіювати з іншої локалі',\n resolver_copy_errorMessage: 'Сталася помилка під час спроби перекладу даних',\n resolver_copy_modalTitle: 'Виберіть локаль для копіювання',\n resolver_copy_submitButtonLabelEmpty: 'Копіювати лише порожні поля',\n resolver_copy_submitButtonLabelFull: 'Копіювати все',\n resolver_copy_successMessage:\n 'Успішно скопійовано. Натисніть \"Зберегти\", щоб застосувати зміни.',\n\n resolver_google_buttonLabel: 'Переклад Google',\n resolver_google_errorMessage: 'Сталася помилка під час спроби перекладу даних',\n resolver_google_modalTitle: 'Виберіть локаль для перекладу',\n resolver_google_submitButtonLabelEmpty: 'Перекласти лише порожні поля',\n resolver_google_submitButtonLabelFull: 'Перекласти все',\n resolver_google_successMessage:\n 'Успішно перекладено. Натисніть \"Зберегти\", щоб застосувати зміни.',\n\n resolver_libre_buttonLabel: 'Переклад Libre',\n resolver_libre_errorMessage: 'Сталася помилка під час спроби перекладу даних',\n resolver_libre_modalTitle: 'Виберіть локаль для перекладу',\n resolver_libre_submitButtonLabelEmpty: 'Перекласти лише порожні поля',\n resolver_libre_submitButtonLabelFull: 'Перекласти все',\n resolver_libre_successMessage:\n 'Успішно перекладено. Натисніть \"Зберегти\", щоб застосувати зміни.',\n\n resolver_openai_buttonLabel: 'Переклад AI',\n resolver_openai_errorMessage: 'Сталася помилка під час спроби перекладу даних',\n resolver_openai_modalTitle: 'Виберіть локаль для перекладу',\n resolver_openai_submitButtonLabelEmpty: 'Перекласти лише порожні поля',\n resolver_openai_submitButtonLabelFull: 'Перекласти все',\n resolver_openai_successMessage:\n 'Успішно перекладено. Натисніть \"Зберегти\", щоб застосувати зміни.',\n },\n },\n zh: {\n 'plugin-translator': {\n resolver_copy_buttonLabel: '从其他语言复制',\n resolver_copy_errorMessage: '尝试翻译数据时发生错误',\n resolver_copy_modalTitle: '选择要复制的语言',\n resolver_copy_submitButtonLabelEmpty: '仅复制空字段',\n resolver_copy_submitButtonLabelFull: '复制全部',\n resolver_copy_successMessage: '复制成功。按下“保存”以应用更改。',\n\n resolver_google_buttonLabel: '谷歌翻译',\n resolver_google_errorMessage: '尝试翻译数据时发生错误',\n resolver_google_modalTitle: '选择要翻译的语言',\n resolver_google_submitButtonLabelEmpty: '仅翻译空字段',\n resolver_google_submitButtonLabelFull: '翻译全部',\n resolver_google_successMessage: '翻译成功。按下“保存”以应用更改。',\n\n resolver_libre_buttonLabel: '自由翻译',\n resolver_libre_errorMessage: '尝试翻译数据时发生错误',\n resolver_libre_modalTitle: '选择要翻译的语言',\n resolver_libre_submitButtonLabelEmpty: '仅翻译空字段',\n resolver_libre_submitButtonLabelFull: '翻译全部',\n resolver_libre_successMessage: '翻译成功。按下“保存”以应用更改。',\n\n resolver_openai_buttonLabel: 'AI翻译',\n resolver_openai_errorMessage: '尝试翻译数据时发生错误',\n resolver_openai_modalTitle: '选择要翻译的语言',\n resolver_openai_submitButtonLabelEmpty: '仅翻译空字段',\n resolver_openai_submitButtonLabelFull: '翻译全部',\n resolver_openai_successMessage: '翻译成功。按下“保存”以应用更改。',\n },\n },\n};\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_libre_buttonLabel","resolver_libre_errorMessage","resolver_libre_modalTitle","resolver_libre_submitButtonLabelEmpty","resolver_libre_submitButtonLabelFull","resolver_libre_successMessage","resolver_openai_buttonLabel","resolver_openai_errorMessage","resolver_openai_modalTitle","resolver_openai_submitButtonLabelEmpty","resolver_openai_submitButtonLabelFull","resolver_openai_successMessage","uk","zh"],"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,4BAA4B;YAC5BC,6BAA6B;YAC7BC,2BAA2B;YAC3BC,uCAAuC;YACvCC,sCAAsC;YACtCC,+BAA+B;YAE/BC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCAAgC;QAClC;IACF;IACAC,IAAI;QACF,qBAAqB;YACnBxB,2BAA2B;YAC3BC,4BAA4B;YAC5BC,0BAA0B;YAC1BC,sCAAsC;YACtCC,qCAAqC;YACrCC,8BACE;YAEFC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCACE;YAEFC,4BAA4B;YAC5BC,6BAA6B;YAC7BC,2BAA2B;YAC3BC,uCAAuC;YACvCC,sCAAsC;YACtCC,+BACE;YAEFC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCACE;QACJ;IACF;IACAE,IAAI;QACF,qBAAqB;YACnBzB,2BAA2B;YAC3BC,4BAA4B;YAC5BC,0BAA0B;YAC1BC,sCAAsC;YACtCC,qCAAqC;YACrCC,8BAA8B;YAE9BC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCAAgC;YAEhCC,4BAA4B;YAC5BC,6BAA6B;YAC7BC,2BAA2B;YAC3BC,uCAAuC;YACvCC,sCAAsC;YACtCC,+BAA+B;YAE/BC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCAAgC;QAClC;IACF;AACF,EAAE"}
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
import type { Plugin } from 'payload';
|
2
2
|
import { translateOperation } from './translate/operation';
|
3
3
|
import type { TranslatorConfig } from './types';
|
4
|
+
export { copyResolver } from './resolvers/copy';
|
5
|
+
export { googleResolver } from './resolvers/google';
|
6
|
+
export { libreResolver } from './resolvers/libreTranslate';
|
7
|
+
export { openAIResolver } from './resolvers/openAI';
|
8
|
+
export * from './resolvers/types';
|
4
9
|
export { translateOperation };
|
5
10
|
export declare const translator: (pluginConfig: TranslatorConfig) => Plugin;
|
6
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsC,MAAM,EAAE,MAAM,SAAS,CAAC;AAM1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,cAAc,mBAAmB,CAAC;AAElC,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,eAAO,MAAM,UAAU,EAAE,CAAC,YAAY,EAAE,gBAAgB,KAAK,MA+E5D,CAAC"}
|
package/dist/index.js
CHANGED
@@ -1,13 +1,18 @@
|
|
1
|
-
|
1
|
+
import { deepMerge } from 'payload/shared';
|
2
2
|
import { CustomButton } from './client/components/CustomButton';
|
3
3
|
import { translations } from './i18n-translations';
|
4
4
|
import { translateEndpoint } from './translate/endpoint';
|
5
5
|
import { translateOperation } from './translate/operation';
|
6
|
+
export { copyResolver } from './resolvers/copy';
|
7
|
+
export { googleResolver } from './resolvers/google';
|
8
|
+
export { libreResolver } from './resolvers/libreTranslate';
|
9
|
+
export { openAIResolver } from './resolvers/openAI';
|
10
|
+
export * from './resolvers/types';
|
6
11
|
export { translateOperation };
|
7
12
|
export const translator = (pluginConfig)=>{
|
8
13
|
return (config)=>{
|
9
14
|
if (pluginConfig.disabled || !config.localization || config.localization.locales.length < 2) return config;
|
10
|
-
|
15
|
+
const updatedConfig = {
|
11
16
|
...config,
|
12
17
|
admin: {
|
13
18
|
...config.admin ?? {},
|
@@ -75,6 +80,7 @@ export const translator = (pluginConfig)=>{
|
|
75
80
|
}
|
76
81
|
}
|
77
82
|
};
|
83
|
+
return updatedConfig;
|
78
84
|
};
|
79
85
|
};
|
80
86
|
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionSlug, Config, GlobalSlug, Plugin } from 'payload';\nimport { deepMerge } from 'payload/shared';\n\nimport { CustomButton } from './client/components/CustomButton';\nimport { translations } from './i18n-translations';\nimport { translateEndpoint } from './translate/endpoint';\nimport { translateOperation } from './translate/operation';\nimport type { TranslatorConfig } from './types';\n\nexport { copyResolver } from './resolvers/copy';\n\nexport { googleResolver } from './resolvers/google';\n\nexport { libreResolver } from './resolvers/libreTranslate';\n\nexport { openAIResolver } from './resolvers/openAI';\nexport * from './resolvers/types';\n\nexport { translateOperation };\n\nexport const translator: (pluginConfig: TranslatorConfig) => Plugin = (pluginConfig) => {\n return (config) => {\n if (pluginConfig.disabled || !config.localization || config.localization.locales.length < 2)\n return config;\n\n const updatedConfig: Config = {\n ...config,\n admin: {\n ...(config.admin ?? {}),\n custom: {\n ...(config.admin?.custom ?? {}),\n translator: {\n resolvers: pluginConfig.resolvers.map(({ key }) => ({ key })),\n },\n },\n },\n collections:\n config.collections?.map((collection) => {\n if (!pluginConfig.collections.includes(collection.slug as CollectionSlug))\n return collection;\n\n return {\n ...collection,\n admin: {\n ...(collection.admin ?? {}),\n components: {\n ...(collection.admin?.components ?? {}),\n edit: {\n ...(collection.admin?.components?.edit ?? {}),\n PublishButton: CustomButton('publish'),\n SaveButton: CustomButton('save'),\n },\n },\n },\n };\n }) ?? [],\n custom: {\n ...(config.custom ?? {}),\n translator: {\n resolvers: pluginConfig.resolvers,\n },\n },\n endpoints: [\n ...(config.endpoints ?? []),\n {\n handler: translateEndpoint,\n method: 'post',\n path: '/translator/translate',\n },\n ],\n globals:\n config.globals?.map((global) => {\n if (!pluginConfig.globals.includes(global.slug as GlobalSlug)) return global;\n\n return {\n ...global,\n admin: {\n ...(global.admin ?? {}),\n components: {\n ...(global.admin?.components ?? {}),\n elements: {\n ...(global.admin?.components?.elements ?? {}),\n PublishButton: CustomButton('publish'),\n SaveButton: CustomButton('save'),\n },\n },\n },\n };\n }) ?? [],\n i18n: {\n ...config.i18n,\n translations: {\n ...deepMerge(config.i18n?.translations ?? {}, translations),\n },\n },\n };\n\n return updatedConfig;\n };\n};\n"],"names":["deepMerge","CustomButton","translations","translateEndpoint","translateOperation","copyResolver","googleResolver","libreResolver","openAIResolver","translator","pluginConfig","config","disabled","localization","locales","length","updatedConfig","admin","custom","resolvers","map","key","collections","collection","includes","slug","components","edit","PublishButton","SaveButton","endpoints","handler","method","path","globals","global","elements","i18n"],"mappings":"AACA,SAASA,SAAS,QAAQ,iBAAiB;AAE3C,SAASC,YAAY,QAAQ,mCAAmC;AAChE,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SAASC,iBAAiB,QAAQ,uBAAuB;AACzD,SAASC,kBAAkB,QAAQ,wBAAwB;AAG3D,SAASC,YAAY,QAAQ,mBAAmB;AAEhD,SAASC,cAAc,QAAQ,qBAAqB;AAEpD,SAASC,aAAa,QAAQ,6BAA6B;AAE3D,SAASC,cAAc,QAAQ,qBAAqB;AACpD,cAAc,oBAAoB;AAElC,SAASJ,kBAAkB,GAAG;AAE9B,OAAO,MAAMK,aAAyD,CAACC;IACrE,OAAO,CAACC;QACN,IAAID,aAAaE,QAAQ,IAAI,CAACD,OAAOE,YAAY,IAAIF,OAAOE,YAAY,CAACC,OAAO,CAACC,MAAM,GAAG,GACxF,OAAOJ;QAET,MAAMK,gBAAwB;YAC5B,GAAGL,MAAM;YACTM,OAAO;gBACL,GAAIN,OAAOM,KAAK,IAAI,CAAC,CAAC;gBACtBC,QAAQ;oBACN,GAAIP,OAAOM,KAAK,EAAEC,UAAU,CAAC,CAAC;oBAC9BT,YAAY;wBACVU,WAAWT,aAAaS,SAAS,CAACC,GAAG,CAAC,CAAC,EAAEC,GAAG,EAAE,GAAM,CAAA;gCAAEA;4BAAI,CAAA;oBAC5D;gBACF;YACF;YACAC,aACEX,OAAOW,WAAW,EAAEF,IAAI,CAACG;gBACvB,IAAI,CAACb,aAAaY,WAAW,CAACE,QAAQ,CAACD,WAAWE,IAAI,GACpD,OAAOF;gBAET,OAAO;oBACL,GAAGA,UAAU;oBACbN,OAAO;wBACL,GAAIM,WAAWN,KAAK,IAAI,CAAC,CAAC;wBAC1BS,YAAY;4BACV,GAAIH,WAAWN,KAAK,EAAES,cAAc,CAAC,CAAC;4BACtCC,MAAM;gCACJ,GAAIJ,WAAWN,KAAK,EAAES,YAAYC,QAAQ,CAAC,CAAC;gCAC5CC,eAAe3B,aAAa;gCAC5B4B,YAAY5B,aAAa;4BAC3B;wBACF;oBACF;gBACF;YACF,MAAM,EAAE;YACViB,QAAQ;gBACN,GAAIP,OAAOO,MAAM,IAAI,CAAC,CAAC;gBACvBT,YAAY;oBACVU,WAAWT,aAAaS,SAAS;gBACnC;YACF;YACAW,WAAW;mBACLnB,OAAOmB,SAAS,IAAI,EAAE;gBAC1B;oBACEC,SAAS5B;oBACT6B,QAAQ;oBACRC,MAAM;gBACR;aACD;YACDC,SACEvB,OAAOuB,OAAO,EAAEd,IAAI,CAACe;gBACnB,IAAI,CAACzB,aAAawB,OAAO,CAACV,QAAQ,CAACW,OAAOV,IAAI,GAAiB,OAAOU;gBAEtE,OAAO;oBACL,GAAGA,MAAM;oBACTlB,OAAO;wBACL,GAAIkB,OAAOlB,KAAK,IAAI,CAAC,CAAC;wBACtBS,YAAY;4BACV,GAAIS,OAAOlB,KAAK,EAAES,cAAc,CAAC,CAAC;4BAClCU,UAAU;gCACR,GAAID,OAAOlB,KAAK,EAAES,YAAYU,YAAY,CAAC,CAAC;gCAC5CR,eAAe3B,aAAa;gCAC5B4B,YAAY5B,aAAa;4BAC3B;wBACF;oBACF;gBACF;YACF,MAAM,EAAE;YACVoC,MAAM;gBACJ,GAAG1B,OAAO0B,IAAI;gBACdnC,cAAc;oBACZ,GAAGF,UAAUW,OAAO0B,IAAI,EAAEnC,gBAAgB,CAAC,GAAGA,aAAa;gBAC7D;YACF;QACF;QAEA,OAAOc;IACT;AACF,EAAE"}
|
package/dist/resolvers/google.js
CHANGED
@@ -23,7 +23,7 @@ export const googleResolver = ({ apiKey, chunkLength = 100 })=>{
|
|
23
23
|
const data = await res.json();
|
24
24
|
if (!res.ok) req.payload.logger.info({
|
25
25
|
googleResponse: data,
|
26
|
-
message:
|
26
|
+
message: 'An error occurred when trying to translate the data using Google API'
|
27
27
|
});
|
28
28
|
return {
|
29
29
|
data,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/resolvers/google.ts"],"sourcesContent":["import { chunkArray } from '../utils/chunkArray';\nimport type { TranslateResolver } from './types';\n\ntype GoogleResponse = {\n data: {\n data: {\n translations: {\n detectedSourceLanguage: string;\n model: string;\n translatedText: string;\n }[];\n };\n };\n success: boolean;\n};\n\nconst localeToCountryCodeMapper = {\n ua: 'uk',\n};\n\nconst mapLocale = (incoming: string) =>\n incoming in localeToCountryCodeMapper\n ? localeToCountryCodeMapper[incoming as keyof typeof localeToCountryCodeMapper]\n : incoming;\n\nexport type GoogleResolverConfig = {\n apiKey: string;\n /**\n * How many texts to include into 1 request\n * @default 100\n */\n chunkLength?: number;\n};\n\nexport const googleResolver = ({\n apiKey,\n chunkLength = 100,\n}: GoogleResolverConfig): TranslateResolver => {\n return {\n key: 'google',\n resolve: async (args) => {\n const { localeFrom, localeTo, req, texts } = args;\n\n const apiUrl = `https://translation.googleapis.com/language/translate/v2?key=${apiKey}`;\n\n const responses: GoogleResponse[] = await Promise.all(\n chunkArray(texts, chunkLength).map((q) =>\n fetch(apiUrl, {\n body: JSON.stringify({\n q,\n source: mapLocale(localeFrom),\n target: mapLocale(localeTo),\n }),\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n }).then(async (res) => {\n const data = await res.json();\n\n if (!res.ok)\n req.payload.logger.info({\n googleResponse: data,\n message:
|
1
|
+
{"version":3,"sources":["../../src/resolvers/google.ts"],"sourcesContent":["import { chunkArray } from '../utils/chunkArray';\nimport type { TranslateResolver } from './types';\n\ntype GoogleResponse = {\n data: {\n data: {\n translations: {\n detectedSourceLanguage: string;\n model: string;\n translatedText: string;\n }[];\n };\n };\n success: boolean;\n};\n\nconst localeToCountryCodeMapper = {\n ua: 'uk',\n};\n\nconst mapLocale = (incoming: string) =>\n incoming in localeToCountryCodeMapper\n ? localeToCountryCodeMapper[incoming as keyof typeof localeToCountryCodeMapper]\n : incoming;\n\nexport type GoogleResolverConfig = {\n apiKey: string;\n /**\n * How many texts to include into 1 request\n * @default 100\n */\n chunkLength?: number;\n};\n\nexport const googleResolver = ({\n apiKey,\n chunkLength = 100,\n}: GoogleResolverConfig): TranslateResolver => {\n return {\n key: 'google',\n resolve: async (args) => {\n const { localeFrom, localeTo, req, texts } = args;\n\n const apiUrl = `https://translation.googleapis.com/language/translate/v2?key=${apiKey}`;\n\n const responses: GoogleResponse[] = await Promise.all(\n chunkArray(texts, chunkLength).map((q) =>\n fetch(apiUrl, {\n body: JSON.stringify({\n q,\n source: mapLocale(localeFrom),\n target: mapLocale(localeTo),\n }),\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n }).then(async (res) => {\n const data = await res.json();\n\n if (!res.ok)\n req.payload.logger.info({\n googleResponse: data,\n message: 'An error occurred when trying to translate the data using Google API',\n });\n\n return {\n data,\n success: res.ok,\n };\n }),\n ),\n );\n\n if (responses.some((res) => !res.success)) {\n return {\n success: false,\n };\n }\n\n const translatedTexts = responses\n .flatMap((chunk) => chunk.data.data.translations)\n .map((translation) => translation.translatedText);\n\n return {\n success: true,\n translatedTexts,\n };\n },\n };\n};\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"],"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,QAAQ;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;oBACX;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"}
|