@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
@@ -6,8 +6,27 @@ const reactRouterDom = require("react-router-dom");
6
6
  const designSystem = require("@strapi/design-system");
7
7
  const reactIntl = require("react-intl");
8
8
  const icons = require("@strapi/icons");
9
+ const styled = require("styled-components");
9
10
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
10
- const React__default = /* @__PURE__ */ _interopDefault(React);
11
+ function _interopNamespace(e) {
12
+ if (e && e.__esModule) return e;
13
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
14
+ if (e) {
15
+ for (const k in e) {
16
+ if (k !== "default") {
17
+ const d = Object.getOwnPropertyDescriptor(e, k);
18
+ Object.defineProperty(n, k, d.get ? d : {
19
+ enumerable: true,
20
+ get: () => e[k]
21
+ });
22
+ }
23
+ }
24
+ }
25
+ n.default = e;
26
+ return Object.freeze(n);
27
+ }
28
+ const React__namespace = /* @__PURE__ */ _interopNamespace(React);
29
+ const styled__default = /* @__PURE__ */ _interopDefault(styled);
11
30
  const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
12
31
  const v = glob[path];
13
32
  if (v) {
@@ -2602,6 +2621,7 @@ function makeNodesHash(arr) {
2602
2621
  const PLUGIN_ID = "littlebox-strapi-suite";
2603
2622
  const SLUG_LANGUAGE_STRATEGY = "language";
2604
2623
  const SLUG_CONTENT_STRATEGY = "content";
2624
+ const AI_TRANSLATION_DEFAULT_MODEL = "gpt-4o";
2605
2625
  const config = {
2606
2626
  pluginId: PLUGIN_ID,
2607
2627
  uuid: {
@@ -2894,6 +2914,32 @@ class TranslationGatewayHttp {
2894
2914
  async edit(uid, params) {
2895
2915
  return this.httpClient.put(`/${config.pluginId}/admin/translations/${uid}`, params);
2896
2916
  }
2917
+ async aiTranslate(params) {
2918
+ return this.httpClient.post(
2919
+ `/${config.pluginId}/admin/translations/actions/ai-translate`,
2920
+ params
2921
+ );
2922
+ }
2923
+ }
2924
+ class DocumentGatewayHttp {
2925
+ httpClient;
2926
+ constructor() {
2927
+ this.httpClient = Registry.getInstance().inject("httpClient");
2928
+ }
2929
+ async fetch({ collectionType, model, documentId, params }) {
2930
+ const path = documentId ? `/content-manager/${collectionType}/${model}/${documentId}` : `/content-manager/${collectionType}/${model}`;
2931
+ const response = await this.httpClient.get(`${path}${objectToQueryString(params)}`);
2932
+ return response ? response.data : null;
2933
+ }
2934
+ }
2935
+ class AiGatewayHttp {
2936
+ httpClient;
2937
+ constructor() {
2938
+ this.httpClient = Registry.getInstance().inject("httpClient");
2939
+ }
2940
+ async translateStrings(input) {
2941
+ return this.httpClient.post(`/${config.pluginId}/admin/ai/strings`, input);
2942
+ }
2897
2943
  }
2898
2944
  class Mediator {
2899
2945
  handlers;
@@ -3023,17 +3069,17 @@ const PageAttributesBox = ({ document }) => {
3023
3069
  const { formatMessage } = reactIntl.useIntl();
3024
3070
  const location = reactRouterDom.useLocation();
3025
3071
  const { form } = admin.unstable_useContentManagerContext();
3026
- const [selectedParent, setSelectedParent] = React__default.default.useState(-1);
3027
- const [selectedTemplate, setSelectedTemplate] = React__default.default.useState(-1);
3028
- const [selectedPriority, setSelectedPriority] = React__default.default.useState("no-priority");
3029
- const [selectedFrequency, setSelectedFrequency] = React__default.default.useState("no-frequency");
3030
- const [parents, setParents] = React__default.default.useState([]);
3031
- const [templates, setTemplates] = React__default.default.useState([]);
3032
- const [attributes, setAttributes] = React__default.default.useState();
3033
- const [appSettings, setAppSettings] = React__default.default.useState();
3034
- const [showDangerModal, setShowDangerModal] = React__default.default.useState(false);
3035
- const [showBox, setShowBox] = React__default.default.useState(false);
3036
- const [currentLocale, setCurrentLocale] = React__default.default.useState(getCurrentLocate());
3072
+ const [selectedParent, setSelectedParent] = React__namespace.default.useState(-1);
3073
+ const [selectedTemplate, setSelectedTemplate] = React__namespace.default.useState(-1);
3074
+ const [selectedPriority, setSelectedPriority] = React__namespace.default.useState("no-priority");
3075
+ const [selectedFrequency, setSelectedFrequency] = React__namespace.default.useState("no-frequency");
3076
+ const [parents, setParents] = React__namespace.default.useState([]);
3077
+ const [templates, setTemplates] = React__namespace.default.useState([]);
3078
+ const [attributes, setAttributes] = React__namespace.default.useState();
3079
+ const [appSettings, setAppSettings] = React__namespace.default.useState();
3080
+ const [showDangerModal, setShowDangerModal] = React__namespace.default.useState(false);
3081
+ const [showBox, setShowBox] = React__namespace.default.useState(false);
3082
+ const [currentLocale, setCurrentLocale] = React__namespace.default.useState(getCurrentLocate());
3037
3083
  function getCurrentLocate() {
3038
3084
  const queryString = window.location.search.split("?")[1];
3039
3085
  const searchParams = new URLSearchParams(queryString);
@@ -3118,7 +3164,7 @@ const PageAttributesBox = ({ document }) => {
3118
3164
  const settings = await fetchModuleSettings.execute("attribute");
3119
3165
  setAppSettings(settings);
3120
3166
  }
3121
- React__default.default.useEffect(() => {
3167
+ React__namespace.default.useEffect(() => {
3122
3168
  if (attributes) {
3123
3169
  if (parents) {
3124
3170
  const index2 = parents.findIndex(
@@ -3138,19 +3184,19 @@ const PageAttributesBox = ({ document }) => {
3138
3184
  setSelectedFrequency(attributes.frequency || "no-frequency");
3139
3185
  }
3140
3186
  }, [templates, parents, attributes]);
3141
- React__default.default.useEffect(() => {
3187
+ React__namespace.default.useEffect(() => {
3142
3188
  if (parents.length > 0) {
3143
3189
  const value = selectedParent === -1 ? "" : buildPath(selectedParent);
3144
3190
  const mediator = Registry.getInstance().inject("mediator");
3145
3191
  mediator.notify(new PageAttributeUpdated({ parentSlug: value }));
3146
3192
  }
3147
3193
  }, [selectedParent, parents]);
3148
- React__default.default.useEffect(() => {
3194
+ React__namespace.default.useEffect(() => {
3149
3195
  fectchAttributes();
3150
3196
  fetchTemplates$1();
3151
3197
  fetchParents();
3152
3198
  }, [location]);
3153
- React__default.default.useEffect(() => {
3199
+ React__namespace.default.useEffect(() => {
3154
3200
  const subscription = Registry.getInstance().inject("mediator").subscribe(DocumentCustomFieldStarted.id, () => {
3155
3201
  setShowBox(true);
3156
3202
  });
@@ -3296,6 +3342,599 @@ const PageAttributesBox = ({ document }) => {
3296
3342
  ] })
3297
3343
  };
3298
3344
  };
3345
+ class FetchLocales {
3346
+ localeGateway;
3347
+ constructor() {
3348
+ this.localeGateway = Registry.getInstance().inject("localeGateway");
3349
+ }
3350
+ async execute() {
3351
+ const result = await this.localeGateway.fetch();
3352
+ const output = result.map((data) => ({
3353
+ id: data.id,
3354
+ code: data.code,
3355
+ name: data.name,
3356
+ isDefault: data.isDefault
3357
+ }));
3358
+ return output;
3359
+ }
3360
+ }
3361
+ class AbstractSlugHandler {
3362
+ nextHandler = null;
3363
+ setNext(handler) {
3364
+ this.nextHandler = handler;
3365
+ return handler;
3366
+ }
3367
+ handle(text) {
3368
+ if (this.nextHandler) {
3369
+ return this.nextHandler.handle(this.process(text));
3370
+ }
3371
+ return this.process(text);
3372
+ }
3373
+ }
3374
+ class LowercaseHandler extends AbstractSlugHandler {
3375
+ process(text) {
3376
+ return text.toLowerCase();
3377
+ }
3378
+ }
3379
+ class AccentRemovalHandler extends AbstractSlugHandler {
3380
+ process(text) {
3381
+ return text.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
3382
+ }
3383
+ }
3384
+ class SpecialCharsHandler extends AbstractSlugHandler {
3385
+ process(text) {
3386
+ return text.replace(/[^a-z0-9-]+/g, "-");
3387
+ }
3388
+ }
3389
+ class TrimHyphensHandler extends AbstractSlugHandler {
3390
+ process(text) {
3391
+ return text.replace(/^-+|-+$/g, "");
3392
+ }
3393
+ }
3394
+ class MultipleHyphensHandler extends AbstractSlugHandler {
3395
+ process(text) {
3396
+ return text.replace(/-+/g, "-");
3397
+ }
3398
+ }
3399
+ class LengthLimitHandler extends AbstractSlugHandler {
3400
+ maxLength;
3401
+ constructor(maxLength = 100) {
3402
+ super();
3403
+ this.maxLength = maxLength;
3404
+ }
3405
+ process(text) {
3406
+ if (text.length > this.maxLength) {
3407
+ const truncated = text.substring(0, this.maxLength);
3408
+ return truncated.replace(/-+$/g, "");
3409
+ }
3410
+ return text;
3411
+ }
3412
+ }
3413
+ const convertToSlug = (text, maxLength = 100) => {
3414
+ if (!text) return "";
3415
+ const chain = new LowercaseHandler();
3416
+ const accentHandler = new AccentRemovalHandler();
3417
+ const specialCharsHandler = new SpecialCharsHandler();
3418
+ const trimHandler = new TrimHyphensHandler();
3419
+ const multipleHyphensHandler = new MultipleHyphensHandler();
3420
+ const lengthHandler = new LengthLimitHandler(maxLength);
3421
+ chain.setNext(accentHandler).setNext(specialCharsHandler).setNext(trimHandler).setNext(multipleHyphensHandler).setNext(lengthHandler);
3422
+ return chain.handle(text);
3423
+ };
3424
+ const SLUG_CUSTOM_FIELD = "plugin::littlebox-strapi-suite.ltbslug";
3425
+ const TEXT_TYPES = ["string", "text", "richtext"];
3426
+ const URL_PATTERN = /^(https?:\/\/|\/|mailto:|tel:)\S*$/i;
3427
+ function isFilled(value) {
3428
+ return typeof value === "string" && value.trim().length > 0;
3429
+ }
3430
+ function isTranslatableText(value) {
3431
+ return isFilled(value) && !URL_PATTERN.test(value.trim());
3432
+ }
3433
+ function isLocalized(attribute) {
3434
+ return attribute?.pluginOptions?.i18n?.localized !== false;
3435
+ }
3436
+ function isSlug(attribute) {
3437
+ return attribute?.customField === SLUG_CUSTOM_FIELD || attribute?.type === "uid";
3438
+ }
3439
+ function join(path, segment) {
3440
+ return path ? `${path}.${segment}` : String(segment);
3441
+ }
3442
+ function collectBlocks(nodes, source, path, fields) {
3443
+ if (!Array.isArray(nodes) || !Array.isArray(source)) return;
3444
+ nodes.forEach((node, index2) => {
3445
+ const sourceNode = source[index2];
3446
+ if (!node || !sourceNode) return;
3447
+ if (isTranslatableText(sourceNode.text) && typeof node.text === "string") {
3448
+ fields.push({
3449
+ path: join(path, `${index2}.text`),
3450
+ value: sourceNode.text,
3451
+ current: node.text,
3452
+ kind: "text"
3453
+ });
3454
+ }
3455
+ collectBlocks(node.children, sourceNode.children, join(path, `${index2}.children`), fields);
3456
+ });
3457
+ }
3458
+ function collectTranslatableFields(attributes, components, target, source, basePath = "") {
3459
+ const fields = [];
3460
+ if (!attributes || !target || !source) return fields;
3461
+ for (const [name, attribute] of Object.entries(attributes)) {
3462
+ if (!isLocalized(attribute)) continue;
3463
+ const path = join(basePath, name);
3464
+ const targetValue = target[name];
3465
+ const sourceValue = source[name];
3466
+ if (isSlug(attribute)) {
3467
+ if (isFilled(sourceValue) && typeof targetValue === "string") {
3468
+ fields.push({ path, value: sourceValue, current: targetValue, kind: "slug" });
3469
+ }
3470
+ continue;
3471
+ }
3472
+ if (TEXT_TYPES.includes(attribute.type)) {
3473
+ if (isTranslatableText(sourceValue) && typeof targetValue === "string") {
3474
+ fields.push({ path, value: sourceValue, current: targetValue, kind: "text" });
3475
+ }
3476
+ continue;
3477
+ }
3478
+ if (attribute.type === "blocks") {
3479
+ collectBlocks(targetValue, sourceValue, path, fields);
3480
+ continue;
3481
+ }
3482
+ if (attribute.type === "component") {
3483
+ const schema = components[attribute.component];
3484
+ if (!schema) continue;
3485
+ if (attribute.repeatable) {
3486
+ if (!Array.isArray(targetValue) || !Array.isArray(sourceValue)) continue;
3487
+ targetValue.forEach((entry, index2) => {
3488
+ fields.push(
3489
+ ...collectTranslatableFields(
3490
+ schema.attributes,
3491
+ components,
3492
+ entry,
3493
+ sourceValue[index2],
3494
+ join(path, index2)
3495
+ )
3496
+ );
3497
+ });
3498
+ continue;
3499
+ }
3500
+ fields.push(
3501
+ ...collectTranslatableFields(schema.attributes, components, targetValue, sourceValue, path)
3502
+ );
3503
+ continue;
3504
+ }
3505
+ if (attribute.type === "dynamiczone") {
3506
+ if (!Array.isArray(targetValue) || !Array.isArray(sourceValue)) continue;
3507
+ targetValue.forEach((entry, index2) => {
3508
+ const sourceEntry = sourceValue[index2];
3509
+ if (!entry || !sourceEntry) return;
3510
+ if (entry.__component !== sourceEntry.__component) return;
3511
+ const schema = components[entry.__component];
3512
+ if (!schema) return;
3513
+ fields.push(
3514
+ ...collectTranslatableFields(
3515
+ schema.attributes,
3516
+ components,
3517
+ entry,
3518
+ sourceEntry,
3519
+ join(path, index2)
3520
+ )
3521
+ );
3522
+ });
3523
+ }
3524
+ }
3525
+ return fields;
3526
+ }
3527
+ function countTranslatableFields(attributes, components, source) {
3528
+ return collectTranslatableFields(attributes, components, source, source).length;
3529
+ }
3530
+ class TranslateDocument {
3531
+ documentGateway;
3532
+ aiGateway;
3533
+ constructor() {
3534
+ this.documentGateway = Registry.getInstance().inject("documentGateway");
3535
+ this.aiGateway = Registry.getInstance().inject("aiGateway");
3536
+ }
3537
+ async execute(input) {
3538
+ const source = await this.documentGateway.fetch({
3539
+ collectionType: input.collectionType,
3540
+ model: input.model,
3541
+ documentId: input.documentId,
3542
+ params: { locale: input.sourceLocale, status: input.status }
3543
+ });
3544
+ const total = source ? countTranslatableFields(input.attributes, input.components, source) : 0;
3545
+ if (total === 0) {
3546
+ return {
3547
+ results: [],
3548
+ translated: 0,
3549
+ skipped: 0,
3550
+ unmatched: 0,
3551
+ failed: 0,
3552
+ errors: ["no-source"]
3553
+ };
3554
+ }
3555
+ const matched = collectTranslatableFields(
3556
+ input.attributes,
3557
+ input.components,
3558
+ input.values,
3559
+ source
3560
+ );
3561
+ const unmatched = Math.max(0, total - matched.length);
3562
+ const pending = input.overwrite ? matched : matched.filter((field) => field.current.trim().length === 0);
3563
+ const skipped = matched.length - pending.length;
3564
+ if (pending.length === 0) {
3565
+ return { results: [], translated: 0, skipped, unmatched, failed: 0, errors: [] };
3566
+ }
3567
+ const strings = pending.reduce((acc, field, index2) => {
3568
+ acc[String(index2)] = field.kind === "slug" ? field.value.replace(/-/g, " ") : field.value;
3569
+ return acc;
3570
+ }, {});
3571
+ const output = await this.aiGateway.translateStrings({
3572
+ sourceLocale: input.sourceLocale,
3573
+ targetLocale: input.targetLocale,
3574
+ strings
3575
+ });
3576
+ const results = [];
3577
+ pending.forEach((field, index2) => {
3578
+ const translation = output.translations[String(index2)];
3579
+ if (typeof translation !== "string" || translation.trim().length === 0) return;
3580
+ results.push({
3581
+ path: field.path,
3582
+ value: field.kind === "slug" ? convertToSlug(translation) : translation,
3583
+ kind: field.kind
3584
+ });
3585
+ });
3586
+ return {
3587
+ results,
3588
+ translated: results.length,
3589
+ skipped,
3590
+ unmatched,
3591
+ failed: output.failed,
3592
+ errors: output.errors
3593
+ };
3594
+ }
3595
+ }
3596
+ const BoxInput = styled__default.default(designSystem.Box)`
3597
+ flex: 1;
3598
+ display: flex;
3599
+ width: 100%;
3600
+ flex-direction: column;
3601
+ & > div {
3602
+ width: 100%;
3603
+ }
3604
+ `;
3605
+ const DocumentTranslateModal = ({ open, locales, targetLocale, translate, close }) => {
3606
+ const [module2] = React.useState(config.uuid.modules.translation);
3607
+ const [hidden, setHidden] = React.useState(true);
3608
+ const [sourceLocale, setSourceLocale] = React.useState();
3609
+ const [overwrite, setOverwrite] = React.useState(true);
3610
+ const [translateInProgress, setTranslateInProgress] = React.useState(false);
3611
+ const [result, setResult] = React.useState();
3612
+ const [error, setError] = React.useState("");
3613
+ const { formatMessage } = reactIntl.useIntl();
3614
+ const sources = locales.filter(
3615
+ (locale) => locale.code !== targetLocale?.code
3616
+ );
3617
+ async function run() {
3618
+ if (translateInProgress || !sourceLocale) return;
3619
+ setTranslateInProgress(true);
3620
+ setResult(void 0);
3621
+ setError("");
3622
+ try {
3623
+ const output = await translate(sourceLocale, overwrite);
3624
+ if (output.errors.includes("no-source")) {
3625
+ setError(
3626
+ formatMessage({
3627
+ id: getTranslation(`module.${module2}.panel.ai.error.no-source`),
3628
+ defaultMessage: "This entry does not exist yet in the language you picked as the base"
3629
+ })
3630
+ );
3631
+ } else {
3632
+ setResult(output);
3633
+ }
3634
+ } catch (e) {
3635
+ setError(
3636
+ e?.response?.data?.error?.message || e?.message || formatMessage({
3637
+ id: getTranslation(`module.${module2}.modal.ai.error`),
3638
+ defaultMessage: "The translation request failed"
3639
+ })
3640
+ );
3641
+ }
3642
+ setTranslateInProgress(false);
3643
+ }
3644
+ function handleClose() {
3645
+ if (translateInProgress) return;
3646
+ setResult(void 0);
3647
+ setError("");
3648
+ close();
3649
+ }
3650
+ React.useEffect(() => {
3651
+ if (!open) {
3652
+ setHidden(true);
3653
+ return;
3654
+ }
3655
+ setSourceLocale(sources[0]?.code);
3656
+ setOverwrite(true);
3657
+ setResult(void 0);
3658
+ setError("");
3659
+ setHidden(false);
3660
+ }, [open]);
3661
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: !hidden && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Root, { defaultOpen: true, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Content, { children: [
3662
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Header, { style: { textAlign: "left" }, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { style: { width: "100%", justifyContent: "space-between" }, children: [
3663
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", children: formatMessage({
3664
+ id: getTranslation(`module.${module2}.panel.ai.title`),
3665
+ defaultMessage: "Translate with AI"
3666
+ }) }),
3667
+ !translateInProgress && /* @__PURE__ */ jsxRuntime.jsx(
3668
+ designSystem.IconButton,
3669
+ {
3670
+ variant: "tertiary",
3671
+ onClick: handleClose,
3672
+ label: "Close",
3673
+ borderWidth: 0,
3674
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, {})
3675
+ }
3676
+ )
3677
+ ] }) }),
3678
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { display: "flex", flexDirection: "column", width: "100%" }, children: [
3679
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", style: { paddingBottom: "5px" }, children: formatMessage({
3680
+ id: getTranslation(`module.${module2}.modal.ai.input.source.title`),
3681
+ defaultMessage: "Base language"
3682
+ }) }),
3683
+ /* @__PURE__ */ jsxRuntime.jsx(
3684
+ designSystem.Typography,
3685
+ {
3686
+ variant: "pi",
3687
+ style: { paddingBottom: "5px", color: "#a5a5ba", display: "flex" },
3688
+ children: formatMessage(
3689
+ {
3690
+ id: getTranslation(`module.${module2}.panel.ai.input.source.description`),
3691
+ defaultMessage: "This entry is translated into {target} from the language you pick here"
3692
+ },
3693
+ { target: targetLocale?.name || "" }
3694
+ )
3695
+ }
3696
+ ),
3697
+ /* @__PURE__ */ jsxRuntime.jsx(BoxInput, { children: /* @__PURE__ */ jsxRuntime.jsx(
3698
+ designSystem.SingleSelect,
3699
+ {
3700
+ onChange: (value) => setSourceLocale(value),
3701
+ value: sourceLocale,
3702
+ disabled: translateInProgress,
3703
+ children: sources.map((locale, index2) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: locale.code, children: locale.name }, index2))
3704
+ }
3705
+ ) }),
3706
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", style: { paddingBottom: "5px", paddingTop: "24px" }, children: formatMessage({
3707
+ id: getTranslation(`module.${module2}.panel.ai.input.overwrite.title`),
3708
+ defaultMessage: "Overwrite fields that already have content"
3709
+ }) }),
3710
+ /* @__PURE__ */ jsxRuntime.jsx(
3711
+ designSystem.Typography,
3712
+ {
3713
+ variant: "pi",
3714
+ style: { paddingBottom: "5px", color: "#a5a5ba", display: "flex" },
3715
+ children: formatMessage({
3716
+ id: getTranslation(`module.${module2}.panel.ai.input.overwrite.description`),
3717
+ defaultMessage: "When disabled only the empty fields are filled in"
3718
+ })
3719
+ }
3720
+ ),
3721
+ /* @__PURE__ */ jsxRuntime.jsx(
3722
+ designSystem.Toggle,
3723
+ {
3724
+ onLabel: "True",
3725
+ offLabel: "False",
3726
+ checked: overwrite,
3727
+ disabled: translateInProgress,
3728
+ onChange: (e) => setOverwrite(e.target.checked)
3729
+ }
3730
+ ),
3731
+ translateInProgress && /* @__PURE__ */ jsxRuntime.jsxs(
3732
+ designSystem.Card,
3733
+ {
3734
+ shadow: false,
3735
+ style: {
3736
+ marginTop: "20px",
3737
+ padding: "10px",
3738
+ display: "flex",
3739
+ alignItems: "center"
3740
+ },
3741
+ children: [
3742
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { small: true }),
3743
+ /* @__PURE__ */ jsxRuntime.jsx(
3744
+ designSystem.Typography,
3745
+ {
3746
+ variant: "pi",
3747
+ style: { color: "#a5a5ba", display: "flex", marginLeft: "10px" },
3748
+ children: formatMessage({
3749
+ id: getTranslation(`module.${module2}.modal.ai.progress`),
3750
+ defaultMessage: "Translating. This can take a few minutes, please keep this window open"
3751
+ })
3752
+ }
3753
+ )
3754
+ ]
3755
+ }
3756
+ ),
3757
+ result && !translateInProgress && /* @__PURE__ */ jsxRuntime.jsxs(
3758
+ designSystem.Card,
3759
+ {
3760
+ shadow: false,
3761
+ style: {
3762
+ marginTop: "20px",
3763
+ padding: "10px",
3764
+ display: "flex",
3765
+ flexDirection: "column",
3766
+ alignItems: "start",
3767
+ gap: "5px"
3768
+ },
3769
+ children: [
3770
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", style: { display: "flex" }, children: formatMessage(
3771
+ {
3772
+ id: getTranslation(`module.${module2}.modal.ai.result`),
3773
+ defaultMessage: "{translated} translated, {skipped} skipped, {failed} failed"
3774
+ },
3775
+ {
3776
+ translated: result.translated,
3777
+ skipped: result.skipped,
3778
+ failed: result.failed
3779
+ }
3780
+ ) }),
3781
+ result.translated > 0 && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", style: { color: "#a5a5ba", display: "flex" }, children: formatMessage({
3782
+ id: getTranslation(`module.${module2}.panel.ai.result.save`),
3783
+ defaultMessage: "Review the fields and save the entry to keep them"
3784
+ }) }),
3785
+ result.unmatched > 0 && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", style: { color: "#ee5e52", display: "flex" }, children: formatMessage(
3786
+ {
3787
+ id: getTranslation(`module.${module2}.panel.ai.result.unmatched`),
3788
+ defaultMessage: "{unmatched} fields of the base language have no match here, the two entries have a different structure"
3789
+ },
3790
+ { unmatched: result.unmatched }
3791
+ ) }),
3792
+ result.errors.map((message, index2) => /* @__PURE__ */ jsxRuntime.jsx(
3793
+ designSystem.Typography,
3794
+ {
3795
+ variant: "pi",
3796
+ style: { color: "#ee5e52", display: "flex" },
3797
+ children: message
3798
+ },
3799
+ index2
3800
+ ))
3801
+ ]
3802
+ }
3803
+ ),
3804
+ error && !translateInProgress && /* @__PURE__ */ jsxRuntime.jsx(
3805
+ designSystem.Card,
3806
+ {
3807
+ shadow: false,
3808
+ style: {
3809
+ marginTop: "20px",
3810
+ padding: "10px",
3811
+ display: "flex",
3812
+ alignItems: "center"
3813
+ },
3814
+ children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", style: { color: "#ee5e52", display: "flex" }, children: error })
3815
+ }
3816
+ )
3817
+ ] }) }),
3818
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Footer, { style: { justifyContent: "end", gap: "5px" }, children: [
3819
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", onClick: handleClose, disabled: translateInProgress, children: formatMessage({
3820
+ id: getTranslation(`app.modal.confirm.button.cancel`),
3821
+ defaultMessage: "Cancel"
3822
+ }) }),
3823
+ /* @__PURE__ */ jsxRuntime.jsx(
3824
+ designSystem.Button,
3825
+ {
3826
+ style: { marginRight: "5px" },
3827
+ onClick: run,
3828
+ disabled: translateInProgress || !sourceLocale,
3829
+ children: formatMessage({
3830
+ id: getTranslation(`module.${module2}.modal.ai.button.translate`),
3831
+ defaultMessage: "Translate"
3832
+ })
3833
+ }
3834
+ )
3835
+ ] })
3836
+ ] }) }) });
3837
+ };
3838
+ const DocumentTranslateBox = ({ document }) => {
3839
+ const { formatMessage } = reactIntl.useIntl();
3840
+ const context = admin.unstable_useContentManagerContext();
3841
+ const [appSettings, setAppSettings] = React__namespace.useState();
3842
+ const [i18nLocales, setI18nLocales] = React__namespace.useState([]);
3843
+ const [showModal, setShowModal] = React__namespace.useState(false);
3844
+ const module2 = config.uuid.modules.translation;
3845
+ function getCurrentLocale() {
3846
+ const queryString = window.location.search.split("?")[1];
3847
+ const searchParams = new URLSearchParams(queryString);
3848
+ return searchParams.get("plugins[i18n][locale]");
3849
+ }
3850
+ function getCurrentStatus() {
3851
+ const queryString = window.location.search.split("?")[1];
3852
+ const searchParams = new URLSearchParams(queryString);
3853
+ return searchParams.get("status") || void 0;
3854
+ }
3855
+ async function fetchSettings() {
3856
+ const fetchModuleSettings = new FetchModuleSettings();
3857
+ setAppSettings(await fetchModuleSettings.execute(module2));
3858
+ }
3859
+ async function fetchLocales() {
3860
+ const fetchLocales2 = new FetchLocales();
3861
+ setI18nLocales(await fetchLocales2.execute());
3862
+ }
3863
+ function applyResults(results) {
3864
+ results.forEach((result) => {
3865
+ context.form.onChange(result.path, result.value);
3866
+ if (result.kind === "slug") {
3867
+ context.form.onChange("ltb_slug", result.value);
3868
+ }
3869
+ });
3870
+ }
3871
+ function getDocumentId() {
3872
+ const documentId = document?.documentId || context.id;
3873
+ return documentId && documentId !== "create" ? documentId : void 0;
3874
+ }
3875
+ async function translate(sourceLocale, overwrite) {
3876
+ const translateDocument = new TranslateDocument();
3877
+ const output = await translateDocument.execute({
3878
+ collectionType: context.collectionType,
3879
+ model: context.model,
3880
+ documentId: context.isSingleType ? void 0 : getDocumentId(),
3881
+ sourceLocale,
3882
+ targetLocale: getCurrentLocale(),
3883
+ status: getCurrentStatus(),
3884
+ attributes: context.contentType?.attributes,
3885
+ components: context.components,
3886
+ values: context.form.values,
3887
+ overwrite
3888
+ });
3889
+ applyResults(output.results);
3890
+ return output;
3891
+ }
3892
+ React__namespace.useEffect(() => {
3893
+ fetchSettings();
3894
+ fetchLocales();
3895
+ }, []);
3896
+ const currentLocale = getCurrentLocale();
3897
+ const targetLocale = i18nLocales.find(
3898
+ (locale) => locale.code === currentLocale
3899
+ );
3900
+ const isLocalized2 = context.contentType?.pluginOptions?.i18n?.localized === true;
3901
+ if (!appSettings || !appSettings.active || !appSettings.aiEnabled) return null;
3902
+ if (!isLocalized2 || !currentLocale || i18nLocales.length < 2) return null;
3903
+ if (!context.contentType) return null;
3904
+ if (!context.isSingleType && !getDocumentId()) return null;
3905
+ return {
3906
+ title: formatMessage({
3907
+ id: getTranslation(`module.${module2}.panel.title`),
3908
+ defaultMessage: "Translation"
3909
+ }),
3910
+ content: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3911
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { display: "flex", style: { flexDirection: "column", width: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx(
3912
+ designSystem.Button,
3913
+ {
3914
+ variant: "secondary",
3915
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Sparkle, {}),
3916
+ onClick: () => setShowModal(true),
3917
+ disabled: context.form.isSubmitting || context.form.disabled,
3918
+ fullWidth: true,
3919
+ children: formatMessage({
3920
+ id: getTranslation(`module.${module2}.button.translate-with-ai`),
3921
+ defaultMessage: "Translate with AI"
3922
+ })
3923
+ }
3924
+ ) }),
3925
+ /* @__PURE__ */ jsxRuntime.jsx(
3926
+ DocumentTranslateModal,
3927
+ {
3928
+ open: showModal,
3929
+ locales: i18nLocales,
3930
+ targetLocale,
3931
+ translate,
3932
+ close: () => setShowModal(false)
3933
+ }
3934
+ )
3935
+ ] })
3936
+ };
3937
+ };
3299
3938
  const index = {
3300
3939
  async register(app) {
3301
3940
  app.addMenuLink({
@@ -3306,7 +3945,7 @@ const index = {
3306
3945
  defaultMessage: config.pluginId
3307
3946
  },
3308
3947
  position: 999,
3309
- Component: () => Promise.resolve().then(() => require("./App-C7RgdLC-.js"))
3948
+ Component: () => Promise.resolve().then(() => require("./App-C-h--Kv_.js"))
3310
3949
  });
3311
3950
  app.customFields.register({
3312
3951
  name: "ltbslug",
@@ -3324,7 +3963,7 @@ const index = {
3324
3963
  components: {
3325
3964
  Input: async () => Promise.resolve().then(() => require(
3326
3965
  /* webpackChunkName: "input-slug-component" */
3327
- "./SlugInput-DvQWzpBu.js"
3966
+ "./SlugInput-3gkr6B0t.js"
3328
3967
  ))
3329
3968
  },
3330
3969
  options: {
@@ -3376,7 +4015,7 @@ const index = {
3376
4015
  return Promise.all(
3377
4016
  locales.map(async (locale) => {
3378
4017
  try {
3379
- const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./core/translations/en.json": () => Promise.resolve().then(() => require("./en-CGJcJfk1.js")) }), `./core/translations/${locale}.json`, 4);
4018
+ const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./core/translations/en.json": () => Promise.resolve().then(() => require("./en-CLNZnNeq.js")) }), `./core/translations/${locale}.json`, 4);
3380
4019
  return { data, locale };
3381
4020
  } catch {
3382
4021
  return { data: {}, locale };
@@ -3395,10 +4034,17 @@ const index = {
3395
4034
  Registry.getInstance().provide("menuGateway", new MenuGatewayHttp());
3396
4035
  Registry.getInstance().provide("parameterGateway", new ParameterGatewayHttp());
3397
4036
  Registry.getInstance().provide("translationGateway", new TranslationGatewayHttp());
3398
- app.getPlugin("content-manager").apis.addEditViewSidePanel([PageAttributesBox]);
4037
+ Registry.getInstance().provide("documentGateway", new DocumentGatewayHttp());
4038
+ Registry.getInstance().provide("aiGateway", new AiGatewayHttp());
4039
+ app.getPlugin("content-manager").apis.addEditViewSidePanel([
4040
+ PageAttributesBox,
4041
+ DocumentTranslateBox
4042
+ ]);
3399
4043
  }
3400
4044
  };
4045
+ exports.AI_TRANSLATION_DEFAULT_MODEL = AI_TRANSLATION_DEFAULT_MODEL;
3401
4046
  exports.DocumentCustomFieldStarted = DocumentCustomFieldStarted;
4047
+ exports.FetchLocales = FetchLocales;
3402
4048
  exports.FetchModuleSettings = FetchModuleSettings;
3403
4049
  exports.FetchSettings = FetchSettings;
3404
4050
  exports.FetchSlugs = FetchSlugs;
@@ -3408,6 +4054,7 @@ exports.Registry = Registry;
3408
4054
  exports.SLUG_CONTENT_STRATEGY = SLUG_CONTENT_STRATEGY;
3409
4055
  exports.SLUG_LANGUAGE_STRATEGY = SLUG_LANGUAGE_STRATEGY;
3410
4056
  exports.config = config;
4057
+ exports.convertToSlug = convertToSlug;
3411
4058
  exports.fetchTemplates = fetchTemplates;
3412
4059
  exports.getTranslation = getTranslation;
3413
4060
  exports.index = index;