@littlebox/strapi-suite 1.0.51 → 1.0.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/_chunks/{App-C7RgdLC-.js → App-C-h--Kv_.js} +557 -35
  2. package/dist/_chunks/{App-b_1MuDrk.mjs → App-C1HyspTk.mjs} +550 -28
  3. package/dist/_chunks/{SlugInput-DvQWzpBu.js → SlugInput-3gkr6B0t.js} +3 -4
  4. package/dist/_chunks/{SlugInput-DlOanbzA.mjs → SlugInput-CU9_b0dd.mjs} +1 -2
  5. package/dist/_chunks/{en-CGJcJfk1.js → en-CLNZnNeq.js} +30 -0
  6. package/dist/_chunks/{en-CRSiVe4w.mjs → en-F6RYx79c.mjs} +30 -0
  7. package/dist/_chunks/{index-UZTUyNY3.js → index-60sq8G6p.js} +667 -20
  8. package/dist/_chunks/{index-C3MUddO-.mjs → index-DQ3vX9So.mjs} +639 -9
  9. package/dist/admin/index.js +1 -1
  10. package/dist/admin/index.mjs +2 -2
  11. package/dist/admin/src/components/DocumentTranslateBox.d.ts +5 -0
  12. package/dist/admin/src/components/DocumentTranslateModal.d.ts +11 -0
  13. package/dist/admin/src/components/TranslationAiModal.d.ts +8 -0
  14. package/dist/admin/src/components/TranslationSettingsModal.d.ts +6 -0
  15. package/dist/admin/src/contexts/settings.d.ts +1 -0
  16. package/dist/admin/src/core/config.d.ts +1 -0
  17. package/dist/admin/src/core/gateways/aiGateway.d.ts +19 -0
  18. package/dist/admin/src/core/gateways/documentGateway.d.ts +15 -0
  19. package/dist/admin/src/core/gateways/translationGateway.d.ts +13 -0
  20. package/dist/admin/src/core/usecases/translateDocument.d.ts +33 -0
  21. package/dist/admin/src/core/usecases/translateWithAi.d.ts +17 -0
  22. package/dist/admin/src/core/utils/documentFields.d.ts +23 -0
  23. package/dist/server/index.js +386 -79
  24. package/dist/server/index.mjs +386 -79
  25. package/dist/server/src/config/index.d.ts +4 -0
  26. package/dist/server/src/controllers/index.d.ts +6 -0
  27. package/dist/server/src/controllers/modules/ai-translation.d.ts +7 -0
  28. package/dist/server/src/controllers/modules/translation.d.ts +1 -0
  29. package/dist/server/src/index.d.ts +22 -1
  30. package/dist/server/src/services/app/setting.d.ts +3 -1
  31. package/dist/server/src/services/index.d.ts +16 -1
  32. package/dist/server/src/services/modules/ai-translation.d.ts +35 -0
  33. package/package.json +1 -1
  34. package/dist/_chunks/convertToSlug-DmgViUjP.mjs +0 -84
  35. package/dist/_chunks/convertToSlug-DqHa9ej4.js +0 -83
@@ -1,10 +1,12 @@
1
1
  import { getFetchClient, unstable_useContentManagerContext } from "@strapi/strapi/admin";
2
+ import * as React from "react";
2
3
  import React__default, { useRef, useEffect, useState } from "react";
3
4
  import { jsx, Fragment, jsxs } from "react/jsx-runtime";
4
5
  import { useLocation } from "react-router-dom";
5
- import { Dialog, Button, Box, Typography, SingleSelect, SingleSelectOption } from "@strapi/design-system";
6
+ import { Dialog, Button, Box, Typography, SingleSelect, SingleSelectOption, Flex, IconButton, Toggle, Card, Loader } from "@strapi/design-system";
6
7
  import { useIntl } from "react-intl";
7
- import { WarningCircle } from "@strapi/icons";
8
+ import { WarningCircle, Cross, Sparkle } from "@strapi/icons";
9
+ import styled from "styled-components";
8
10
  const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
9
11
  const v = glob[path];
10
12
  if (v) {
@@ -2599,6 +2601,7 @@ function makeNodesHash(arr) {
2599
2601
  const PLUGIN_ID = "littlebox-strapi-suite";
2600
2602
  const SLUG_LANGUAGE_STRATEGY = "language";
2601
2603
  const SLUG_CONTENT_STRATEGY = "content";
2604
+ const AI_TRANSLATION_DEFAULT_MODEL = "gpt-4o";
2602
2605
  const config = {
2603
2606
  pluginId: PLUGIN_ID,
2604
2607
  uuid: {
@@ -2891,6 +2894,32 @@ class TranslationGatewayHttp {
2891
2894
  async edit(uid, params) {
2892
2895
  return this.httpClient.put(`/${config.pluginId}/admin/translations/${uid}`, params);
2893
2896
  }
2897
+ async aiTranslate(params) {
2898
+ return this.httpClient.post(
2899
+ `/${config.pluginId}/admin/translations/actions/ai-translate`,
2900
+ params
2901
+ );
2902
+ }
2903
+ }
2904
+ class DocumentGatewayHttp {
2905
+ httpClient;
2906
+ constructor() {
2907
+ this.httpClient = Registry.getInstance().inject("httpClient");
2908
+ }
2909
+ async fetch({ collectionType, model, documentId, params }) {
2910
+ const path = documentId ? `/content-manager/${collectionType}/${model}/${documentId}` : `/content-manager/${collectionType}/${model}`;
2911
+ const response = await this.httpClient.get(`${path}${objectToQueryString(params)}`);
2912
+ return response ? response.data : null;
2913
+ }
2914
+ }
2915
+ class AiGatewayHttp {
2916
+ httpClient;
2917
+ constructor() {
2918
+ this.httpClient = Registry.getInstance().inject("httpClient");
2919
+ }
2920
+ async translateStrings(input) {
2921
+ return this.httpClient.post(`/${config.pluginId}/admin/ai/strings`, input);
2922
+ }
2894
2923
  }
2895
2924
  class Mediator {
2896
2925
  handlers;
@@ -3293,6 +3322,599 @@ const PageAttributesBox = ({ document }) => {
3293
3322
  ] })
3294
3323
  };
3295
3324
  };
3325
+ class FetchLocales {
3326
+ localeGateway;
3327
+ constructor() {
3328
+ this.localeGateway = Registry.getInstance().inject("localeGateway");
3329
+ }
3330
+ async execute() {
3331
+ const result = await this.localeGateway.fetch();
3332
+ const output = result.map((data) => ({
3333
+ id: data.id,
3334
+ code: data.code,
3335
+ name: data.name,
3336
+ isDefault: data.isDefault
3337
+ }));
3338
+ return output;
3339
+ }
3340
+ }
3341
+ class AbstractSlugHandler {
3342
+ nextHandler = null;
3343
+ setNext(handler) {
3344
+ this.nextHandler = handler;
3345
+ return handler;
3346
+ }
3347
+ handle(text) {
3348
+ if (this.nextHandler) {
3349
+ return this.nextHandler.handle(this.process(text));
3350
+ }
3351
+ return this.process(text);
3352
+ }
3353
+ }
3354
+ class LowercaseHandler extends AbstractSlugHandler {
3355
+ process(text) {
3356
+ return text.toLowerCase();
3357
+ }
3358
+ }
3359
+ class AccentRemovalHandler extends AbstractSlugHandler {
3360
+ process(text) {
3361
+ return text.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
3362
+ }
3363
+ }
3364
+ class SpecialCharsHandler extends AbstractSlugHandler {
3365
+ process(text) {
3366
+ return text.replace(/[^a-z0-9-]+/g, "-");
3367
+ }
3368
+ }
3369
+ class TrimHyphensHandler extends AbstractSlugHandler {
3370
+ process(text) {
3371
+ return text.replace(/^-+|-+$/g, "");
3372
+ }
3373
+ }
3374
+ class MultipleHyphensHandler extends AbstractSlugHandler {
3375
+ process(text) {
3376
+ return text.replace(/-+/g, "-");
3377
+ }
3378
+ }
3379
+ class LengthLimitHandler extends AbstractSlugHandler {
3380
+ maxLength;
3381
+ constructor(maxLength = 100) {
3382
+ super();
3383
+ this.maxLength = maxLength;
3384
+ }
3385
+ process(text) {
3386
+ if (text.length > this.maxLength) {
3387
+ const truncated = text.substring(0, this.maxLength);
3388
+ return truncated.replace(/-+$/g, "");
3389
+ }
3390
+ return text;
3391
+ }
3392
+ }
3393
+ const convertToSlug = (text, maxLength = 100) => {
3394
+ if (!text) return "";
3395
+ const chain = new LowercaseHandler();
3396
+ const accentHandler = new AccentRemovalHandler();
3397
+ const specialCharsHandler = new SpecialCharsHandler();
3398
+ const trimHandler = new TrimHyphensHandler();
3399
+ const multipleHyphensHandler = new MultipleHyphensHandler();
3400
+ const lengthHandler = new LengthLimitHandler(maxLength);
3401
+ chain.setNext(accentHandler).setNext(specialCharsHandler).setNext(trimHandler).setNext(multipleHyphensHandler).setNext(lengthHandler);
3402
+ return chain.handle(text);
3403
+ };
3404
+ const SLUG_CUSTOM_FIELD = "plugin::littlebox-strapi-suite.ltbslug";
3405
+ const TEXT_TYPES = ["string", "text", "richtext"];
3406
+ const URL_PATTERN = /^(https?:\/\/|\/|mailto:|tel:)\S*$/i;
3407
+ function isFilled(value) {
3408
+ return typeof value === "string" && value.trim().length > 0;
3409
+ }
3410
+ function isTranslatableText(value) {
3411
+ return isFilled(value) && !URL_PATTERN.test(value.trim());
3412
+ }
3413
+ function isLocalized(attribute) {
3414
+ return attribute?.pluginOptions?.i18n?.localized !== false;
3415
+ }
3416
+ function isSlug(attribute) {
3417
+ return attribute?.customField === SLUG_CUSTOM_FIELD || attribute?.type === "uid";
3418
+ }
3419
+ function join(path, segment) {
3420
+ return path ? `${path}.${segment}` : String(segment);
3421
+ }
3422
+ function collectBlocks(nodes, source, path, fields) {
3423
+ if (!Array.isArray(nodes) || !Array.isArray(source)) return;
3424
+ nodes.forEach((node, index2) => {
3425
+ const sourceNode = source[index2];
3426
+ if (!node || !sourceNode) return;
3427
+ if (isTranslatableText(sourceNode.text) && typeof node.text === "string") {
3428
+ fields.push({
3429
+ path: join(path, `${index2}.text`),
3430
+ value: sourceNode.text,
3431
+ current: node.text,
3432
+ kind: "text"
3433
+ });
3434
+ }
3435
+ collectBlocks(node.children, sourceNode.children, join(path, `${index2}.children`), fields);
3436
+ });
3437
+ }
3438
+ function collectTranslatableFields(attributes, components, target, source, basePath = "") {
3439
+ const fields = [];
3440
+ if (!attributes || !target || !source) return fields;
3441
+ for (const [name, attribute] of Object.entries(attributes)) {
3442
+ if (!isLocalized(attribute)) continue;
3443
+ const path = join(basePath, name);
3444
+ const targetValue = target[name];
3445
+ const sourceValue = source[name];
3446
+ if (isSlug(attribute)) {
3447
+ if (isFilled(sourceValue) && typeof targetValue === "string") {
3448
+ fields.push({ path, value: sourceValue, current: targetValue, kind: "slug" });
3449
+ }
3450
+ continue;
3451
+ }
3452
+ if (TEXT_TYPES.includes(attribute.type)) {
3453
+ if (isTranslatableText(sourceValue) && typeof targetValue === "string") {
3454
+ fields.push({ path, value: sourceValue, current: targetValue, kind: "text" });
3455
+ }
3456
+ continue;
3457
+ }
3458
+ if (attribute.type === "blocks") {
3459
+ collectBlocks(targetValue, sourceValue, path, fields);
3460
+ continue;
3461
+ }
3462
+ if (attribute.type === "component") {
3463
+ const schema = components[attribute.component];
3464
+ if (!schema) continue;
3465
+ if (attribute.repeatable) {
3466
+ if (!Array.isArray(targetValue) || !Array.isArray(sourceValue)) continue;
3467
+ targetValue.forEach((entry, index2) => {
3468
+ fields.push(
3469
+ ...collectTranslatableFields(
3470
+ schema.attributes,
3471
+ components,
3472
+ entry,
3473
+ sourceValue[index2],
3474
+ join(path, index2)
3475
+ )
3476
+ );
3477
+ });
3478
+ continue;
3479
+ }
3480
+ fields.push(
3481
+ ...collectTranslatableFields(schema.attributes, components, targetValue, sourceValue, path)
3482
+ );
3483
+ continue;
3484
+ }
3485
+ if (attribute.type === "dynamiczone") {
3486
+ if (!Array.isArray(targetValue) || !Array.isArray(sourceValue)) continue;
3487
+ targetValue.forEach((entry, index2) => {
3488
+ const sourceEntry = sourceValue[index2];
3489
+ if (!entry || !sourceEntry) return;
3490
+ if (entry.__component !== sourceEntry.__component) return;
3491
+ const schema = components[entry.__component];
3492
+ if (!schema) return;
3493
+ fields.push(
3494
+ ...collectTranslatableFields(
3495
+ schema.attributes,
3496
+ components,
3497
+ entry,
3498
+ sourceEntry,
3499
+ join(path, index2)
3500
+ )
3501
+ );
3502
+ });
3503
+ }
3504
+ }
3505
+ return fields;
3506
+ }
3507
+ function countTranslatableFields(attributes, components, source) {
3508
+ return collectTranslatableFields(attributes, components, source, source).length;
3509
+ }
3510
+ class TranslateDocument {
3511
+ documentGateway;
3512
+ aiGateway;
3513
+ constructor() {
3514
+ this.documentGateway = Registry.getInstance().inject("documentGateway");
3515
+ this.aiGateway = Registry.getInstance().inject("aiGateway");
3516
+ }
3517
+ async execute(input) {
3518
+ const source = await this.documentGateway.fetch({
3519
+ collectionType: input.collectionType,
3520
+ model: input.model,
3521
+ documentId: input.documentId,
3522
+ params: { locale: input.sourceLocale, status: input.status }
3523
+ });
3524
+ const total = source ? countTranslatableFields(input.attributes, input.components, source) : 0;
3525
+ if (total === 0) {
3526
+ return {
3527
+ results: [],
3528
+ translated: 0,
3529
+ skipped: 0,
3530
+ unmatched: 0,
3531
+ failed: 0,
3532
+ errors: ["no-source"]
3533
+ };
3534
+ }
3535
+ const matched = collectTranslatableFields(
3536
+ input.attributes,
3537
+ input.components,
3538
+ input.values,
3539
+ source
3540
+ );
3541
+ const unmatched = Math.max(0, total - matched.length);
3542
+ const pending = input.overwrite ? matched : matched.filter((field) => field.current.trim().length === 0);
3543
+ const skipped = matched.length - pending.length;
3544
+ if (pending.length === 0) {
3545
+ return { results: [], translated: 0, skipped, unmatched, failed: 0, errors: [] };
3546
+ }
3547
+ const strings = pending.reduce((acc, field, index2) => {
3548
+ acc[String(index2)] = field.kind === "slug" ? field.value.replace(/-/g, " ") : field.value;
3549
+ return acc;
3550
+ }, {});
3551
+ const output = await this.aiGateway.translateStrings({
3552
+ sourceLocale: input.sourceLocale,
3553
+ targetLocale: input.targetLocale,
3554
+ strings
3555
+ });
3556
+ const results = [];
3557
+ pending.forEach((field, index2) => {
3558
+ const translation = output.translations[String(index2)];
3559
+ if (typeof translation !== "string" || translation.trim().length === 0) return;
3560
+ results.push({
3561
+ path: field.path,
3562
+ value: field.kind === "slug" ? convertToSlug(translation) : translation,
3563
+ kind: field.kind
3564
+ });
3565
+ });
3566
+ return {
3567
+ results,
3568
+ translated: results.length,
3569
+ skipped,
3570
+ unmatched,
3571
+ failed: output.failed,
3572
+ errors: output.errors
3573
+ };
3574
+ }
3575
+ }
3576
+ const BoxInput = styled(Box)`
3577
+ flex: 1;
3578
+ display: flex;
3579
+ width: 100%;
3580
+ flex-direction: column;
3581
+ & > div {
3582
+ width: 100%;
3583
+ }
3584
+ `;
3585
+ const DocumentTranslateModal = ({ open, locales, targetLocale, translate, close }) => {
3586
+ const [module] = useState(config.uuid.modules.translation);
3587
+ const [hidden, setHidden] = useState(true);
3588
+ const [sourceLocale, setSourceLocale] = useState();
3589
+ const [overwrite, setOverwrite] = useState(true);
3590
+ const [translateInProgress, setTranslateInProgress] = useState(false);
3591
+ const [result, setResult] = useState();
3592
+ const [error, setError] = useState("");
3593
+ const { formatMessage } = useIntl();
3594
+ const sources = locales.filter(
3595
+ (locale) => locale.code !== targetLocale?.code
3596
+ );
3597
+ async function run() {
3598
+ if (translateInProgress || !sourceLocale) return;
3599
+ setTranslateInProgress(true);
3600
+ setResult(void 0);
3601
+ setError("");
3602
+ try {
3603
+ const output = await translate(sourceLocale, overwrite);
3604
+ if (output.errors.includes("no-source")) {
3605
+ setError(
3606
+ formatMessage({
3607
+ id: getTranslation(`module.${module}.panel.ai.error.no-source`),
3608
+ defaultMessage: "This entry does not exist yet in the language you picked as the base"
3609
+ })
3610
+ );
3611
+ } else {
3612
+ setResult(output);
3613
+ }
3614
+ } catch (e) {
3615
+ setError(
3616
+ e?.response?.data?.error?.message || e?.message || formatMessage({
3617
+ id: getTranslation(`module.${module}.modal.ai.error`),
3618
+ defaultMessage: "The translation request failed"
3619
+ })
3620
+ );
3621
+ }
3622
+ setTranslateInProgress(false);
3623
+ }
3624
+ function handleClose() {
3625
+ if (translateInProgress) return;
3626
+ setResult(void 0);
3627
+ setError("");
3628
+ close();
3629
+ }
3630
+ useEffect(() => {
3631
+ if (!open) {
3632
+ setHidden(true);
3633
+ return;
3634
+ }
3635
+ setSourceLocale(sources[0]?.code);
3636
+ setOverwrite(true);
3637
+ setResult(void 0);
3638
+ setError("");
3639
+ setHidden(false);
3640
+ }, [open]);
3641
+ return /* @__PURE__ */ jsx(Fragment, { children: !hidden && /* @__PURE__ */ jsx(Dialog.Root, { defaultOpen: true, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
3642
+ /* @__PURE__ */ jsx(Dialog.Header, { style: { textAlign: "left" }, children: /* @__PURE__ */ jsxs(Flex, { style: { width: "100%", justifyContent: "space-between" }, children: [
3643
+ /* @__PURE__ */ jsx(Typography, { variant: "omega", children: formatMessage({
3644
+ id: getTranslation(`module.${module}.panel.ai.title`),
3645
+ defaultMessage: "Translate with AI"
3646
+ }) }),
3647
+ !translateInProgress && /* @__PURE__ */ jsx(
3648
+ IconButton,
3649
+ {
3650
+ variant: "tertiary",
3651
+ onClick: handleClose,
3652
+ label: "Close",
3653
+ borderWidth: 0,
3654
+ children: /* @__PURE__ */ jsx(Cross, {})
3655
+ }
3656
+ )
3657
+ ] }) }),
3658
+ /* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs(Box, { style: { display: "flex", flexDirection: "column", width: "100%" }, children: [
3659
+ /* @__PURE__ */ jsx(Typography, { variant: "sigma", style: { paddingBottom: "5px" }, children: formatMessage({
3660
+ id: getTranslation(`module.${module}.modal.ai.input.source.title`),
3661
+ defaultMessage: "Base language"
3662
+ }) }),
3663
+ /* @__PURE__ */ jsx(
3664
+ Typography,
3665
+ {
3666
+ variant: "pi",
3667
+ style: { paddingBottom: "5px", color: "#a5a5ba", display: "flex" },
3668
+ children: formatMessage(
3669
+ {
3670
+ id: getTranslation(`module.${module}.panel.ai.input.source.description`),
3671
+ defaultMessage: "This entry is translated into {target} from the language you pick here"
3672
+ },
3673
+ { target: targetLocale?.name || "" }
3674
+ )
3675
+ }
3676
+ ),
3677
+ /* @__PURE__ */ jsx(BoxInput, { children: /* @__PURE__ */ jsx(
3678
+ SingleSelect,
3679
+ {
3680
+ onChange: (value) => setSourceLocale(value),
3681
+ value: sourceLocale,
3682
+ disabled: translateInProgress,
3683
+ children: sources.map((locale, index2) => /* @__PURE__ */ jsx(SingleSelectOption, { value: locale.code, children: locale.name }, index2))
3684
+ }
3685
+ ) }),
3686
+ /* @__PURE__ */ jsx(Typography, { variant: "sigma", style: { paddingBottom: "5px", paddingTop: "24px" }, children: formatMessage({
3687
+ id: getTranslation(`module.${module}.panel.ai.input.overwrite.title`),
3688
+ defaultMessage: "Overwrite fields that already have content"
3689
+ }) }),
3690
+ /* @__PURE__ */ jsx(
3691
+ Typography,
3692
+ {
3693
+ variant: "pi",
3694
+ style: { paddingBottom: "5px", color: "#a5a5ba", display: "flex" },
3695
+ children: formatMessage({
3696
+ id: getTranslation(`module.${module}.panel.ai.input.overwrite.description`),
3697
+ defaultMessage: "When disabled only the empty fields are filled in"
3698
+ })
3699
+ }
3700
+ ),
3701
+ /* @__PURE__ */ jsx(
3702
+ Toggle,
3703
+ {
3704
+ onLabel: "True",
3705
+ offLabel: "False",
3706
+ checked: overwrite,
3707
+ disabled: translateInProgress,
3708
+ onChange: (e) => setOverwrite(e.target.checked)
3709
+ }
3710
+ ),
3711
+ translateInProgress && /* @__PURE__ */ jsxs(
3712
+ Card,
3713
+ {
3714
+ shadow: false,
3715
+ style: {
3716
+ marginTop: "20px",
3717
+ padding: "10px",
3718
+ display: "flex",
3719
+ alignItems: "center"
3720
+ },
3721
+ children: [
3722
+ /* @__PURE__ */ jsx(Loader, { small: true }),
3723
+ /* @__PURE__ */ jsx(
3724
+ Typography,
3725
+ {
3726
+ variant: "pi",
3727
+ style: { color: "#a5a5ba", display: "flex", marginLeft: "10px" },
3728
+ children: formatMessage({
3729
+ id: getTranslation(`module.${module}.modal.ai.progress`),
3730
+ defaultMessage: "Translating. This can take a few minutes, please keep this window open"
3731
+ })
3732
+ }
3733
+ )
3734
+ ]
3735
+ }
3736
+ ),
3737
+ result && !translateInProgress && /* @__PURE__ */ jsxs(
3738
+ Card,
3739
+ {
3740
+ shadow: false,
3741
+ style: {
3742
+ marginTop: "20px",
3743
+ padding: "10px",
3744
+ display: "flex",
3745
+ flexDirection: "column",
3746
+ alignItems: "start",
3747
+ gap: "5px"
3748
+ },
3749
+ children: [
3750
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", style: { display: "flex" }, children: formatMessage(
3751
+ {
3752
+ id: getTranslation(`module.${module}.modal.ai.result`),
3753
+ defaultMessage: "{translated} translated, {skipped} skipped, {failed} failed"
3754
+ },
3755
+ {
3756
+ translated: result.translated,
3757
+ skipped: result.skipped,
3758
+ failed: result.failed
3759
+ }
3760
+ ) }),
3761
+ result.translated > 0 && /* @__PURE__ */ jsx(Typography, { variant: "pi", style: { color: "#a5a5ba", display: "flex" }, children: formatMessage({
3762
+ id: getTranslation(`module.${module}.panel.ai.result.save`),
3763
+ defaultMessage: "Review the fields and save the entry to keep them"
3764
+ }) }),
3765
+ result.unmatched > 0 && /* @__PURE__ */ jsx(Typography, { variant: "pi", style: { color: "#ee5e52", display: "flex" }, children: formatMessage(
3766
+ {
3767
+ id: getTranslation(`module.${module}.panel.ai.result.unmatched`),
3768
+ defaultMessage: "{unmatched} fields of the base language have no match here, the two entries have a different structure"
3769
+ },
3770
+ { unmatched: result.unmatched }
3771
+ ) }),
3772
+ result.errors.map((message, index2) => /* @__PURE__ */ jsx(
3773
+ Typography,
3774
+ {
3775
+ variant: "pi",
3776
+ style: { color: "#ee5e52", display: "flex" },
3777
+ children: message
3778
+ },
3779
+ index2
3780
+ ))
3781
+ ]
3782
+ }
3783
+ ),
3784
+ error && !translateInProgress && /* @__PURE__ */ jsx(
3785
+ Card,
3786
+ {
3787
+ shadow: false,
3788
+ style: {
3789
+ marginTop: "20px",
3790
+ padding: "10px",
3791
+ display: "flex",
3792
+ alignItems: "center"
3793
+ },
3794
+ children: /* @__PURE__ */ jsx(Typography, { variant: "pi", style: { color: "#ee5e52", display: "flex" }, children: error })
3795
+ }
3796
+ )
3797
+ ] }) }),
3798
+ /* @__PURE__ */ jsxs(Dialog.Footer, { style: { justifyContent: "end", gap: "5px" }, children: [
3799
+ /* @__PURE__ */ jsx(Button, { variant: "tertiary", onClick: handleClose, disabled: translateInProgress, children: formatMessage({
3800
+ id: getTranslation(`app.modal.confirm.button.cancel`),
3801
+ defaultMessage: "Cancel"
3802
+ }) }),
3803
+ /* @__PURE__ */ jsx(
3804
+ Button,
3805
+ {
3806
+ style: { marginRight: "5px" },
3807
+ onClick: run,
3808
+ disabled: translateInProgress || !sourceLocale,
3809
+ children: formatMessage({
3810
+ id: getTranslation(`module.${module}.modal.ai.button.translate`),
3811
+ defaultMessage: "Translate"
3812
+ })
3813
+ }
3814
+ )
3815
+ ] })
3816
+ ] }) }) });
3817
+ };
3818
+ const DocumentTranslateBox = ({ document }) => {
3819
+ const { formatMessage } = useIntl();
3820
+ const context = unstable_useContentManagerContext();
3821
+ const [appSettings, setAppSettings] = React.useState();
3822
+ const [i18nLocales, setI18nLocales] = React.useState([]);
3823
+ const [showModal, setShowModal] = React.useState(false);
3824
+ const module = config.uuid.modules.translation;
3825
+ function getCurrentLocale() {
3826
+ const queryString = window.location.search.split("?")[1];
3827
+ const searchParams = new URLSearchParams(queryString);
3828
+ return searchParams.get("plugins[i18n][locale]");
3829
+ }
3830
+ function getCurrentStatus() {
3831
+ const queryString = window.location.search.split("?")[1];
3832
+ const searchParams = new URLSearchParams(queryString);
3833
+ return searchParams.get("status") || void 0;
3834
+ }
3835
+ async function fetchSettings() {
3836
+ const fetchModuleSettings = new FetchModuleSettings();
3837
+ setAppSettings(await fetchModuleSettings.execute(module));
3838
+ }
3839
+ async function fetchLocales() {
3840
+ const fetchLocales2 = new FetchLocales();
3841
+ setI18nLocales(await fetchLocales2.execute());
3842
+ }
3843
+ function applyResults(results) {
3844
+ results.forEach((result) => {
3845
+ context.form.onChange(result.path, result.value);
3846
+ if (result.kind === "slug") {
3847
+ context.form.onChange("ltb_slug", result.value);
3848
+ }
3849
+ });
3850
+ }
3851
+ function getDocumentId() {
3852
+ const documentId = document?.documentId || context.id;
3853
+ return documentId && documentId !== "create" ? documentId : void 0;
3854
+ }
3855
+ async function translate(sourceLocale, overwrite) {
3856
+ const translateDocument = new TranslateDocument();
3857
+ const output = await translateDocument.execute({
3858
+ collectionType: context.collectionType,
3859
+ model: context.model,
3860
+ documentId: context.isSingleType ? void 0 : getDocumentId(),
3861
+ sourceLocale,
3862
+ targetLocale: getCurrentLocale(),
3863
+ status: getCurrentStatus(),
3864
+ attributes: context.contentType?.attributes,
3865
+ components: context.components,
3866
+ values: context.form.values,
3867
+ overwrite
3868
+ });
3869
+ applyResults(output.results);
3870
+ return output;
3871
+ }
3872
+ React.useEffect(() => {
3873
+ fetchSettings();
3874
+ fetchLocales();
3875
+ }, []);
3876
+ const currentLocale = getCurrentLocale();
3877
+ const targetLocale = i18nLocales.find(
3878
+ (locale) => locale.code === currentLocale
3879
+ );
3880
+ const isLocalized2 = context.contentType?.pluginOptions?.i18n?.localized === true;
3881
+ if (!appSettings || !appSettings.active || !appSettings.aiEnabled) return null;
3882
+ if (!isLocalized2 || !currentLocale || i18nLocales.length < 2) return null;
3883
+ if (!context.contentType) return null;
3884
+ if (!context.isSingleType && !getDocumentId()) return null;
3885
+ return {
3886
+ title: formatMessage({
3887
+ id: getTranslation(`module.${module}.panel.title`),
3888
+ defaultMessage: "Translation"
3889
+ }),
3890
+ content: /* @__PURE__ */ jsxs(Fragment, { children: [
3891
+ /* @__PURE__ */ jsx(Box, { display: "flex", style: { flexDirection: "column", width: "100%" }, children: /* @__PURE__ */ jsx(
3892
+ Button,
3893
+ {
3894
+ variant: "secondary",
3895
+ startIcon: /* @__PURE__ */ jsx(Sparkle, {}),
3896
+ onClick: () => setShowModal(true),
3897
+ disabled: context.form.isSubmitting || context.form.disabled,
3898
+ fullWidth: true,
3899
+ children: formatMessage({
3900
+ id: getTranslation(`module.${module}.button.translate-with-ai`),
3901
+ defaultMessage: "Translate with AI"
3902
+ })
3903
+ }
3904
+ ) }),
3905
+ /* @__PURE__ */ jsx(
3906
+ DocumentTranslateModal,
3907
+ {
3908
+ open: showModal,
3909
+ locales: i18nLocales,
3910
+ targetLocale,
3911
+ translate,
3912
+ close: () => setShowModal(false)
3913
+ }
3914
+ )
3915
+ ] })
3916
+ };
3917
+ };
3296
3918
  const index = {
3297
3919
  async register(app) {
3298
3920
  app.addMenuLink({
@@ -3303,7 +3925,7 @@ const index = {
3303
3925
  defaultMessage: config.pluginId
3304
3926
  },
3305
3927
  position: 999,
3306
- Component: () => import("./App-b_1MuDrk.mjs")
3928
+ Component: () => import("./App-C1HyspTk.mjs")
3307
3929
  });
3308
3930
  app.customFields.register({
3309
3931
  name: "ltbslug",
@@ -3321,7 +3943,7 @@ const index = {
3321
3943
  components: {
3322
3944
  Input: async () => import(
3323
3945
  /* webpackChunkName: "input-slug-component" */
3324
- "./SlugInput-DlOanbzA.mjs"
3946
+ "./SlugInput-CU9_b0dd.mjs"
3325
3947
  )
3326
3948
  },
3327
3949
  options: {
@@ -3373,7 +3995,7 @@ const index = {
3373
3995
  return Promise.all(
3374
3996
  locales.map(async (locale) => {
3375
3997
  try {
3376
- const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./core/translations/en.json": () => import("./en-CRSiVe4w.mjs") }), `./core/translations/${locale}.json`, 4);
3998
+ const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./core/translations/en.json": () => import("./en-F6RYx79c.mjs") }), `./core/translations/${locale}.json`, 4);
3377
3999
  return { data, locale };
3378
4000
  } catch {
3379
4001
  return { data: {}, locale };
@@ -3392,10 +4014,16 @@ const index = {
3392
4014
  Registry.getInstance().provide("menuGateway", new MenuGatewayHttp());
3393
4015
  Registry.getInstance().provide("parameterGateway", new ParameterGatewayHttp());
3394
4016
  Registry.getInstance().provide("translationGateway", new TranslationGatewayHttp());
3395
- app.getPlugin("content-manager").apis.addEditViewSidePanel([PageAttributesBox]);
4017
+ Registry.getInstance().provide("documentGateway", new DocumentGatewayHttp());
4018
+ Registry.getInstance().provide("aiGateway", new AiGatewayHttp());
4019
+ app.getPlugin("content-manager").apis.addEditViewSidePanel([
4020
+ PageAttributesBox,
4021
+ DocumentTranslateBox
4022
+ ]);
3396
4023
  }
3397
4024
  };
3398
4025
  export {
4026
+ AI_TRANSLATION_DEFAULT_MODEL as A,
3399
4027
  DocumentCustomFieldStarted as D,
3400
4028
  FetchSettings as F,
3401
4029
  PageAttributeUpdated as P,
@@ -3404,9 +4032,11 @@ export {
3404
4032
  SLUG_CONTENT_STRATEGY as a,
3405
4033
  FetchSlugs as b,
3406
4034
  config as c,
3407
- PluginIcon as d,
3408
- FetchModuleSettings as e,
4035
+ FetchLocales as d,
4036
+ convertToSlug as e,
3409
4037
  fetchTemplates as f,
3410
4038
  getTranslation as g,
3411
- index as i
4039
+ PluginIcon as h,
4040
+ FetchModuleSettings as i,
4041
+ index as j
3412
4042
  };