@payload-enchants/translator 1.3.0-pre.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. package/README.md +4 -0
  2. package/dist/client/api/index.js.map +1 -1
  3. package/dist/client/components/CustomButton/CustomButtonWithTranslator.d.ts.map +1 -1
  4. package/dist/client/components/CustomButton/CustomButtonWithTranslator.js +2 -4
  5. package/dist/client/components/CustomButton/CustomButtonWithTranslator.js.map +1 -1
  6. package/dist/client/components/CustomButton/index.d.ts +2 -2
  7. package/dist/client/components/CustomButton/index.d.ts.map +1 -1
  8. package/dist/client/components/CustomButton/index.js +2 -2
  9. package/dist/client/components/CustomButton/index.js.map +1 -1
  10. package/dist/client/components/LocaleLabel/LocaleLabel.js.map +1 -1
  11. package/dist/client/components/ResolverButton/ResolverButton.js +0 -1
  12. package/dist/client/components/ResolverButton/ResolverButton.js.map +1 -1
  13. package/dist/client/components/TranslatorModal/TranslatorModal.d.ts.map +1 -1
  14. package/dist/client/components/TranslatorModal/TranslatorModal.js +2 -3
  15. package/dist/client/components/TranslatorModal/TranslatorModal.js.map +1 -1
  16. package/dist/client/providers/Translator/TranslatorProvider.d.ts.map +1 -1
  17. package/dist/client/providers/Translator/TranslatorProvider.js +24 -18
  18. package/dist/client/providers/Translator/TranslatorProvider.js.map +1 -1
  19. package/dist/i18n-translations.d.ts +18 -0
  20. package/dist/i18n-translations.d.ts.map +1 -1
  21. package/dist/i18n-translations.js +18 -0
  22. package/dist/i18n-translations.js.map +1 -1
  23. package/dist/index.d.ts +5 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +6 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/resolvers/google.js +1 -1
  28. package/dist/resolvers/google.js.map +1 -1
  29. package/dist/resolvers/libreTranslate.d.ts +16 -0
  30. package/dist/resolvers/libreTranslate.d.ts.map +1 -0
  31. package/dist/resolvers/libreTranslate.js +48 -0
  32. package/dist/resolvers/libreTranslate.js.map +1 -0
  33. package/dist/resolvers/openAI.d.ts +2 -2
  34. package/dist/resolvers/openAI.d.ts.map +1 -1
  35. package/dist/resolvers/openAI.js +10 -10
  36. package/dist/resolvers/openAI.js.map +1 -1
  37. package/dist/translate/findEntityWithConfig.d.ts.map +1 -1
  38. package/dist/translate/findEntityWithConfig.js +4 -4
  39. package/dist/translate/findEntityWithConfig.js.map +1 -1
  40. package/dist/translate/operation.d.ts.map +1 -1
  41. package/dist/translate/operation.js +3 -1
  42. package/dist/translate/operation.js.map +1 -1
  43. package/dist/translate/traverseFields.d.ts.map +1 -1
  44. package/dist/translate/traverseFields.js +94 -86
  45. package/dist/translate/traverseFields.js.map +1 -1
  46. package/dist/translate/traverseRichText.js +3 -3
  47. package/dist/translate/traverseRichText.js.map +1 -1
  48. package/dist/translate/updateEntity.d.ts.map +1 -1
  49. package/dist/translate/updateEntity.js +2 -2
  50. package/dist/translate/updateEntity.js.map +1 -1
  51. package/package.json +12 -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,CAAC,EAAEJ,UAAU,EAAED,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
+ {"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 +1 @@
1
- {"version":3,"file":"CustomButtonWithTranslator.d.ts","sourceRoot":"","sources":["../../../../src/client/components/CustomButton/CustomButtonWithTranslator.tsx"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC;AAWvB,eAAO,MAAM,0BAA0B,aAAc;IAAE,IAAI,EAAE,SAAS,GAAG,MAAM,CAAA;CAAE,gCAsBhF,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,13 @@
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
- import { DefaultPublishButton } from '@payloadcms/ui';
9
- import { DefaultSaveButton } from '@payloadcms/ui';
10
8
  export const CustomButtonWithTranslator = ({ type })=>{
11
9
  const { config } = useConfig();
12
- const DefaultButton = type === 'publish' ? DefaultPublishButton : DefaultSaveButton;
10
+ const DefaultButton = type === 'publish' ? PublishButton : SaveButton;
13
11
  const { globalSlug, id } = useDocumentInfo();
14
12
  const resolvers = config.admin?.custom?.translator?.resolvers ?? [];
15
13
  if (!id && !globalSlug) return /*#__PURE__*/ _jsx(DefaultButton, {});
@@ -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';\n\nimport type { TranslateResolver } from '../../../resolvers/types';\nimport { TranslatorProvider } from '../../providers/Translator/TranslatorProvider';\nimport { ResolverButton } from '../ResolverButton';\nimport { TranslatorModal } from '../TranslatorModal';\nimport { DefaultPublishButton } from '@payloadcms/ui';\nimport { DefaultSaveButton } from '@payloadcms/ui';\n\nexport const CustomButtonWithTranslator = ({ type }: { type: 'publish' | 'save' }) => {\n const { config } = useConfig();\n\n const DefaultButton = type === 'publish' ? DefaultPublishButton : DefaultSaveButton;\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":["useConfig","useDocumentInfo","TranslatorProvider","ResolverButton","TranslatorModal","DefaultPublishButton","DefaultSaveButton","CustomButtonWithTranslator","type","config","DefaultButton","globalSlug","id","resolvers","admin","custom","translator","div","className","map","resolver","key"],"mappings":"AAAA;;AAEA,OAAO,gBAAgB;AAEvB,SAASA,SAAS,EAAEC,eAAe,QAAQ,iBAAiB;AAG5D,SAASC,kBAAkB,QAAQ,gDAAgD;AACnF,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,oBAAoB,QAAQ,iBAAiB;AACtD,SAASC,iBAAiB,QAAQ,iBAAiB;AAEnD,OAAO,MAAMC,6BAA6B,CAAC,EAAEC,IAAI,EAAgC;IAC/E,MAAM,EAAEC,MAAM,EAAE,GAAGT;IAEnB,MAAMU,gBAAgBF,SAAS,YAAYH,uBAAuBC;IAElE,MAAM,EAAEK,UAAU,EAAEC,EAAE,EAAE,GAAGX;IAE3B,MAAMY,YAAY,AAACJ,OAAOK,KAAK,EAAEC,QAAQC,YAAYH,aAAqC,EAAE;IAE5F,IAAI,CAACD,MAAM,CAACD,YAAY,qBAAO,KAACD;IAEhC,qBACE,KAACR;kBACC,cAAA,MAACe;YAAIC,WAAW;;8BACd,KAACd;gBACAS,UAAUM,GAAG,CAAC,CAACC,yBACd,KAACjB;wBAAkCiB,UAAUA;uBAAxBA,SAASC,GAAG;8BAElC,KAACX;;;;AAIV,EAAE"}
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,3 +1,3 @@
1
- import { CustomPublishButton, CustomSaveButton } from 'payload';
2
- export declare const CustomButton: (type: "publish" | "save") => CustomSaveButton | CustomPublishButton;
1
+ import type { CustomPublishButton, CustomSaveButton } from 'payload';
2
+ export declare const CustomButton: (type: "publish" | "save") => CustomPublishButton | CustomSaveButton;
3
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":"AAAA,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhE,eAAO,MAAM,YAAY,SAAU,SAAS,GAAG,MAAM,KAAG,gBAAgB,GAAG,mBAO1E,CAAC"}
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,9 +1,9 @@
1
1
  export const CustomButton = (type)=>{
2
2
  return {
3
- path: `@payload-enchants/translator/client#CustomButtonWithTranslator`,
4
3
  clientProps: {
5
4
  type
6
- }
5
+ },
6
+ path: '@payload-enchants/translator/client#CustomButtonWithTranslator'
7
7
  };
8
8
  };
9
9
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/client/components/CustomButton/index.tsx"],"sourcesContent":["import { CustomPublishButton, CustomSaveButton } from 'payload';\n\nexport const CustomButton = (type: 'publish' | 'save'): CustomSaveButton | CustomPublishButton => {\n return {\n path: `@payload-enchants/translator/client#CustomButtonWithTranslator`,\n clientProps: {\n type,\n },\n };\n};\n"],"names":["CustomButton","type","path","clientProps"],"mappings":"AAEA,OAAO,MAAMA,eAAe,CAACC;IAC3B,OAAO;QACLC,MAAM,CAAC,8DAA8D,CAAC;QACtEC,aAAa;YACXF;QACF;IACF;AACF,EAAE"}
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 &nbsp;&nbsp;\n <span className={`${baseClass}__current-label`}>\n {`${getTranslation(locale.label, i18n)}`}\n </span>\n &nbsp;\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,CAAC,EAAEP,UAAU,OAAO,CAAC;0BAAG,CAAC,EAAEI,EAAE,kBAAkB,CAAC,CAAC;;YAAO;0BAExE,KAACI;gBAAKD,WAAW,CAAC,EAAEP,UAAU,eAAe,CAAC;0BAC3C,CAAC,EAAEH,eAAeK,OAAOO,KAAK,EAAEN,MAAM,CAAC;;YACnC;0BAEP,KAACL;gBAAYS,WAAW,CAAC,EAAEP,UAAU,SAAS,CAAC;;;;AAGrD,EAAE"}
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 &nbsp;&nbsp;\n <span className={`${baseClass}__current-label`}>\n {`${getTranslation(locale.label, i18n)}`}\n </span>\n &nbsp;\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"}
@@ -9,7 +9,6 @@ export const ResolverButton = ({ resolver: { key: resolverKey } })=>{
9
9
  });
10
10
  return /*#__PURE__*/ _jsx(Button, {
11
11
  onClick: handleClick,
12
- size: "small",
13
12
  children: t(`plugin-translator:resolver_${resolverKey}_buttonLabel`)
14
13
  });
15
14
  };
@@ -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} size='small'>\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","size"],"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;QAAaE,MAAK;kBAChCH,EAAE,CAAC,2BAA2B,EAAEF,YAAY,YAAY,CAAC;;AAGhE,EAAE"}
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,+CAkB3B,CAAC"}
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("span", {
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 <span\n aria-label='Close'\n className={'translator__close'}\n onClick={closeTranslator}\n role='button'\n />\n <Content />\n </div>\n </Modal>\n );\n};\n"],"names":["Modal","useTranslator","Content","TranslatorModal","closeTranslator","modalSlug","resolver","className","slug","div","span","aria-label","onClick","role"],"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;oBACCC,cAAW;oBACXJ,WAAW;oBACXK,SAASR;oBACTS,MAAK;;8BAEP,KAACX;;;;AAIT,EAAE"}
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,gCAsIvE,CAAC"}
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 { collectionSlug, globalSlug, id } = useDocumentInfo();
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();
@@ -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
- dispatch({
65
- state: await getFormState({
66
- apiRoute: api,
67
- body: {
68
- collectionSlug,
69
- data: result.translatedData,
70
- globalSlug,
71
- locale: locale.code,
72
- schemaPath: collectionSlug || globalSlug || ''
73
- },
74
- serverURL
75
- }),
76
- type: 'REPLACE_STATE'
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 (resolverConfig) {
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 { getFormState } from '@payloadcms/ui/shared';\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 { collectionSlug, 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]);\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 dispatch({\n state: await getFormState({\n apiRoute: api,\n body: {\n collectionSlug,\n data: result.translatedData,\n globalSlug,\n locale: locale.code,\n schemaPath: collectionSlug || globalSlug || '',\n },\n serverURL,\n }),\n type: 'REPLACE_STATE',\n });\n\n if (resolverConfig) {\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","useTranslation","getFormState","reduceFieldsToValues","useEffect","useMemo","useState","createClient","TranslatorContext","modalSlug","TranslatorProvider","children","resolver","setResolver","data","dispatch","collectionSlug","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","apiRoute","body","translatedData","schemaPath","type","Provider","value","openTranslator","resolverKey","openModal"],"mappings":";AAAA,SACEA,KAAK,EACLC,gBAAgB,EAChBC,SAAS,EACTC,eAAe,EACfC,OAAO,EACPC,SAAS,EACTC,QAAQ,EACRC,cAAc,QACT,iBAAiB;AACxB,SAASC,YAAY,QAAQ,wBAAwB;AACrD,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,cAAc,EAAEC,UAAU,EAAEC,EAAE,EAAE,GAAGrB;IAE3C,MAAM,EAAEsB,WAAW,EAAE,GAAGrB;IAExB,MAAMsB,QAAQpB;IAEd,MAAM,EAAEqB,CAAC,EAAE,GAAGpB;IAEd,MAAMqB,YAAY,CAChBC;QAQA,IAAI,CAACX,UAAU,OAAO;QAEtB,OAAOS,EAAE,CAAC,2BAA2B,EAAET,SAAS,CAAC,EAAEW,IAAI,CAAC;IAC1D;IAEA,MAAMC,SAASzB;IAEf,MAAM,EACJ0B,QAAQ,EACNC,OAAO,EAAEC,MAAM,EAAE,EACjBC,YAAY,EACZC,QAAQ,EAAEC,GAAG,EAAE,EACfC,SAAS,EACV,EACF,GAAGnC;IAEJ,MAAMoC,YAAYzB,aAAa;QAAEuB;QA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F,MAAMwC,OAAOO,cAAc;oBAC3B5C;oBACAO,QAAQA,OAAOmB,IAAI;oBACnBmB,YAAY9C,kBAAkBC,cAAc;gBAC9C;gBACAc;YACF;YACAgC,MAAM;QACR;QAEA,IAAI9B,gBAAgB;YAClBd,YAAY;YACZzB,MAAM8D,OAAO,CAAClC,UAAU;QAC1B;QACA0B;IACF;IAEA,qBACE,KAACxC,kBAAkBwD,QAAQ;QACzBC,OAAO;YACLjB;YACAJ;YACAJ;YACA/B;YACAyD,gBAAgB,CAAC,EAAEC,WAAW,EAAE;gBAC9BtD,YAAYsD;gBACZ/C,MAAMgD,SAAS,CAAC3D;YAClB;YACAG,UAAUqB;YACVX;YACAuB;YACAK;QACF;kBAECvC;;AAGP,EAAE"}
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,WAA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,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"}
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0ExB,CAAC"}
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;YACnBlB,2BAA2B;YAC3BC,4BAA4B;YAC5BC,0BAA0B;YAC1BC,sCAAsC;YACtCC,qCAAqC;YACrCC,8BACE;YACFC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCACE;YACFC,6BAA6B;YAC7BC,8BAA8B;YAC9BC,4BAA4B;YAC5BC,wCAAwC;YACxCC,uCAAuC;YACvCC,gCACE;QACJ;IACF;IACAE,IAAI;QACF,qBAAqB;YACnBnB,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"}
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,8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 '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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,SAAS,CAAC;AAM9C,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,MA8E5D,CAAC"}
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,8 +1,13 @@
1
- /* eslint-disable perfectionist/sort-named-exports */ import { deepMerge } from 'payload/shared';
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)=>{
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable perfectionist/sort-named-exports */\nimport type { Config, 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 { 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)) 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)) 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","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":"AAAA,mDAAmD,GAEnD,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,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,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,GA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,GAAGF,UAAUO,OAAO0B,IAAI,EAAE/B,gBAAgB,CAAC,GAAGA,aAAa;gBAC7D;YACF;QACF;QAEA,OAAOU;IACT;AACF,EAAE"}
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,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0B,IAAI,EAAEnC,gBAAgB,CAAC,GAAGA,aAAa;gBAC7D;YACF;QACF;QAEA,OAAOc;IACT;AACF,EAAE"}
@@ -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: `An error occurred when trying to translate the data using Google API`
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: `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,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"}
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"}
@@ -0,0 +1,16 @@
1
+ import type { TranslateResolver } from './types';
2
+ export type LibreResolverConfig = {
3
+ apiKey: string;
4
+ /**
5
+ * How many texts to include into 1 request
6
+ * @default 100
7
+ */
8
+ chunkLength?: number;
9
+ /**
10
+ * Custom url for the libre translate instance
11
+ * @default "https://libretranslate.com/translate"
12
+ */
13
+ url?: string;
14
+ };
15
+ export declare const libreResolver: ({ apiKey, chunkLength, url, }: LibreResolverConfig) => TranslateResolver;
16
+ //# sourceMappingURL=libreTranslate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libreTranslate.d.ts","sourceRoot":"","sources":["../../src/resolvers/libreTranslate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAkBjD,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,aAAa,kCAIvB,mBAAmB,KAAG,iBAqDxB,CAAC"}
@@ -0,0 +1,48 @@
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 libreResolver = ({ apiKey, chunkLength = 100, url = 'https://libretranslate.com/translate' })=>{
7
+ return {
8
+ key: 'libre',
9
+ resolve: async (args)=>{
10
+ const { localeFrom, localeTo, req, texts } = args;
11
+ const apiUrl = url;
12
+ const responses = await Promise.all(chunkArray(texts, chunkLength).map((q)=>fetch(apiUrl, {
13
+ body: JSON.stringify({
14
+ api_key: apiKey,
15
+ q,
16
+ source: mapLocale(localeFrom),
17
+ target: mapLocale(localeTo)
18
+ }),
19
+ headers: {
20
+ 'Content-Type': 'application/json'
21
+ },
22
+ method: 'POST'
23
+ }).then(async (res)=>{
24
+ const data = await res.json();
25
+ if (!res.ok) req.payload.logger.info({
26
+ libreResponse: data,
27
+ message: 'An error occurred when trying to translate the data using LibreTranslate API'
28
+ });
29
+ return {
30
+ data,
31
+ success: res.ok
32
+ };
33
+ })));
34
+ if (responses.some((res)=>!res.success)) {
35
+ return {
36
+ success: false
37
+ };
38
+ }
39
+ const translatedTexts = responses.flatMap((chunk)=>chunk.data.translatedText);
40
+ return {
41
+ success: true,
42
+ translatedTexts
43
+ };
44
+ }
45
+ };
46
+ };
47
+
48
+ //# sourceMappingURL=libreTranslate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/resolvers/libreTranslate.ts"],"sourcesContent":["import { chunkArray } from '../utils/chunkArray';\nimport type { TranslateResolver } from './types';\n\ntype LibreResponse = {\n data: {\n translatedText: string[];\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 LibreResolverConfig = {\n apiKey: string;\n /**\n * How many texts to include into 1 request\n * @default 100\n */\n chunkLength?: number;\n /**\n * Custom url for the libre translate instance\n * @default \"https://libretranslate.com/translate\"\n */\n url?: string;\n};\n\nexport const libreResolver = ({\n apiKey,\n chunkLength = 100,\n url = 'https://libretranslate.com/translate',\n}: LibreResolverConfig): TranslateResolver => {\n return {\n key: 'libre',\n resolve: async (args) => {\n const { localeFrom, localeTo, req, texts } = args;\n\n const apiUrl = url;\n\n const responses: LibreResponse[] = await Promise.all(\n chunkArray(texts, chunkLength).map((q) =>\n fetch(apiUrl, {\n body: JSON.stringify({\n api_key: apiKey,\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 libreResponse: data,\n message:\n 'An error occurred when trying to translate the data using LibreTranslate 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.flatMap((chunk) => chunk.data.translatedText);\n\n return {\n success: true,\n translatedTexts,\n };\n },\n };\n};\n"],"names":["chunkArray","localeToCountryCodeMapper","ua","mapLocale","incoming","libreResolver","apiKey","chunkLength","url","key","resolve","args","localeFrom","localeTo","req","texts","apiUrl","responses","Promise","all","map","q","fetch","body","JSON","stringify","api_key","source","target","headers","method","then","res","data","json","ok","payload","logger","info","libreResponse","message","success","some","translatedTexts","flatMap","chunk","translatedText"],"mappings":"AAAA,SAASA,UAAU,QAAQ,sBAAsB;AAUjD,MAAMC,4BAA4B;IAChCC,IAAI;AACN;AAEA,MAAMC,YAAY,CAACC,WACjBA,YAAYH,4BACRA,yBAAyB,CAACG,SAAmD,GAC7EA;AAgBN,OAAO,MAAMC,gBAAgB,CAAC,EAC5BC,MAAM,EACNC,cAAc,GAAG,EACjBC,MAAM,sCAAsC,EACxB;IACpB,OAAO;QACLC,KAAK;QACLC,SAAS,OAAOC;YACd,MAAM,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,KAAK,EAAE,GAAGJ;YAE7C,MAAMK,SAASR;YAEf,MAAMS,YAA6B,MAAMC,QAAQC,GAAG,CAClDnB,WAAWe,OAAOR,aAAaa,GAAG,CAAC,CAACC,IAClCC,MAAMN,QAAQ;oBACZO,MAAMC,KAAKC,SAAS,CAAC;wBACnBC,SAASpB;wBACTe;wBACAM,QAAQxB,UAAUS;wBAClBgB,QAAQzB,UAAUU;oBACpB;oBACAgB,SAAS;wBACP,gBAAgB;oBAClB;oBACAC,QAAQ;gBACV,GAAGC,IAAI,CAAC,OAAOC;oBACb,MAAMC,OAAO,MAAMD,IAAIE,IAAI;oBAE3B,IAAI,CAACF,IAAIG,EAAE,EACTrB,IAAIsB,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;wBACtBC,eAAeN;wBACfO,SACE;oBACJ;oBAEF,OAAO;wBACLP;wBACAQ,SAAST,IAAIG,EAAE;oBACjB;gBACF;YAIJ,IAAIlB,UAAUyB,IAAI,CAAC,CAACV,MAAQ,CAACA,IAAIS,OAAO,GAAG;gBACzC,OAAO;oBACLA,SAAS;gBACX;YACF;YAEA,MAAME,kBAAkB1B,UAAU2B,OAAO,CAAC,CAACC,QAAUA,MAAMZ,IAAI,CAACa,cAAc;YAE9E,OAAO;gBACLL,SAAS;gBACTE;YACF;QACF;IACF;AACF,EAAE"}