@strapi/i18n 5.9.0 → 5.10.1

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 (126) hide show
  1. package/dist/admin/chunks/SettingsPage-B6ikxVOg.js +820 -0
  2. package/dist/admin/chunks/SettingsPage-B6ikxVOg.js.map +1 -0
  3. package/dist/admin/chunks/SettingsPage-DydtYvMJ.mjs +797 -0
  4. package/dist/admin/chunks/SettingsPage-DydtYvMJ.mjs.map +1 -0
  5. package/dist/admin/chunks/de-Cm8mYdaO.mjs +64 -0
  6. package/dist/admin/chunks/de-Cm8mYdaO.mjs.map +1 -0
  7. package/dist/admin/chunks/de-nEMWvIiY.js +66 -0
  8. package/dist/admin/chunks/de-nEMWvIiY.js.map +1 -0
  9. package/dist/admin/chunks/dk-BeUFOegB.mjs +64 -0
  10. package/dist/admin/chunks/dk-BeUFOegB.mjs.map +1 -0
  11. package/dist/admin/chunks/dk-CYATLPVe.js +66 -0
  12. package/dist/admin/chunks/dk-CYATLPVe.js.map +1 -0
  13. package/dist/admin/chunks/en-CG5cUCbD.js +81 -0
  14. package/dist/admin/chunks/en-CG5cUCbD.js.map +1 -0
  15. package/dist/admin/chunks/en-eWSaCeOb.mjs +79 -0
  16. package/dist/admin/chunks/en-eWSaCeOb.mjs.map +1 -0
  17. package/dist/admin/chunks/es-CWsogTGm.js +66 -0
  18. package/dist/admin/chunks/es-CWsogTGm.js.map +1 -0
  19. package/dist/admin/chunks/es-DqF_IdAc.mjs +64 -0
  20. package/dist/admin/chunks/es-DqF_IdAc.mjs.map +1 -0
  21. package/dist/admin/chunks/fr-CC7UFcYd.js +66 -0
  22. package/dist/admin/chunks/fr-CC7UFcYd.js.map +1 -0
  23. package/dist/admin/chunks/fr-CyARbZ3c.mjs +64 -0
  24. package/dist/admin/chunks/fr-CyARbZ3c.mjs.map +1 -0
  25. package/dist/admin/chunks/index-Dch-2xao.js +2035 -0
  26. package/dist/admin/chunks/index-Dch-2xao.js.map +1 -0
  27. package/dist/admin/chunks/index-k3BHSNs0.mjs +2006 -0
  28. package/dist/admin/chunks/index-k3BHSNs0.mjs.map +1 -0
  29. package/dist/admin/chunks/ko-Ax4NSedM.mjs +63 -0
  30. package/dist/admin/chunks/ko-Ax4NSedM.mjs.map +1 -0
  31. package/dist/admin/chunks/ko-XwGmfhoq.js +65 -0
  32. package/dist/admin/chunks/ko-XwGmfhoq.js.map +1 -0
  33. package/dist/admin/chunks/pl-B-aqvMqL.mjs +64 -0
  34. package/dist/admin/chunks/pl-B-aqvMqL.mjs.map +1 -0
  35. package/dist/admin/chunks/pl-B_vzY_ZB.js +66 -0
  36. package/dist/admin/chunks/pl-B_vzY_ZB.js.map +1 -0
  37. package/dist/admin/chunks/ru-VkPjQ-Sk.mjs +66 -0
  38. package/dist/admin/chunks/ru-VkPjQ-Sk.mjs.map +1 -0
  39. package/dist/admin/chunks/ru-WzHcJV1f.js +68 -0
  40. package/dist/admin/chunks/ru-WzHcJV1f.js.map +1 -0
  41. package/dist/admin/chunks/tr-CcWp6u3w.js +66 -0
  42. package/dist/admin/chunks/tr-CcWp6u3w.js.map +1 -0
  43. package/dist/admin/chunks/tr-DcTR88c9.mjs +64 -0
  44. package/dist/admin/chunks/tr-DcTR88c9.mjs.map +1 -0
  45. package/dist/admin/chunks/zh-C9So4SGq.js +66 -0
  46. package/dist/admin/chunks/zh-C9So4SGq.js.map +1 -0
  47. package/dist/admin/chunks/zh-Hans-DnU2bhri.js +57 -0
  48. package/dist/admin/chunks/zh-Hans-DnU2bhri.js.map +1 -0
  49. package/dist/admin/chunks/zh-Hans-L3wsRegj.mjs +55 -0
  50. package/dist/admin/chunks/zh-Hans-L3wsRegj.mjs.map +1 -0
  51. package/dist/admin/chunks/zh-RZyMiPIs.mjs +64 -0
  52. package/dist/admin/chunks/zh-RZyMiPIs.mjs.map +1 -0
  53. package/dist/admin/index.js +20 -4
  54. package/dist/admin/index.js.map +1 -1
  55. package/dist/admin/index.mjs +15 -6
  56. package/dist/admin/index.mjs.map +1 -1
  57. package/dist/admin/src/components/CMHeaderActions.d.ts +1 -1
  58. package/dist/admin/src/components/tests/CreateLocale.test.d.ts +1 -0
  59. package/dist/admin/src/components/tests/DeleteLocale.test.d.ts +1 -0
  60. package/dist/admin/src/components/tests/EditLocale.test.d.ts +1 -0
  61. package/dist/admin/src/components/tests/LocaleListCell.test.d.ts +1 -0
  62. package/dist/admin/src/contentReleasesHooks/releaseDetailsView.d.ts +1 -1
  63. package/dist/admin/src/pages/tests/SettingsPage.test.d.ts +1 -0
  64. package/dist/admin/tests/server.d.ts +1 -0
  65. package/dist/admin/tests/utils.d.ts +6 -0
  66. package/dist/server/index.js +3650 -3390
  67. package/dist/server/index.js.map +1 -1
  68. package/dist/server/index.mjs +3632 -3374
  69. package/dist/server/index.mjs.map +1 -1
  70. package/dist/server/src/services/localizations.d.ts +1 -1
  71. package/dist/server/src/services/localizations.d.ts.map +1 -1
  72. package/dist/shared/contracts/content-manager.d.ts +1 -1
  73. package/dist/shared/contracts/shared.d.ts +1 -1
  74. package/package.json +14 -11
  75. package/dist/_chunks/SettingsPage-B-KzAqT3.mjs +0 -554
  76. package/dist/_chunks/SettingsPage-B-KzAqT3.mjs.map +0 -1
  77. package/dist/_chunks/SettingsPage-hyOi94O9.js +0 -573
  78. package/dist/_chunks/SettingsPage-hyOi94O9.js.map +0 -1
  79. package/dist/_chunks/de-BOhNX_-5.js +0 -65
  80. package/dist/_chunks/de-BOhNX_-5.js.map +0 -1
  81. package/dist/_chunks/de-D80IRBP9.mjs +0 -65
  82. package/dist/_chunks/de-D80IRBP9.mjs.map +0 -1
  83. package/dist/_chunks/dk-CJ6Zzz78.mjs +0 -65
  84. package/dist/_chunks/dk-CJ6Zzz78.mjs.map +0 -1
  85. package/dist/_chunks/dk-cjXm0p3m.js +0 -65
  86. package/dist/_chunks/dk-cjXm0p3m.js.map +0 -1
  87. package/dist/_chunks/en-BTyF7WVW.mjs +0 -80
  88. package/dist/_chunks/en-BTyF7WVW.mjs.map +0 -1
  89. package/dist/_chunks/en-UlC0jh2t.js +0 -80
  90. package/dist/_chunks/en-UlC0jh2t.js.map +0 -1
  91. package/dist/_chunks/es-V8WnPN7w.mjs +0 -65
  92. package/dist/_chunks/es-V8WnPN7w.mjs.map +0 -1
  93. package/dist/_chunks/es-hr9b_HLp.js +0 -65
  94. package/dist/_chunks/es-hr9b_HLp.js.map +0 -1
  95. package/dist/_chunks/fr-BFmBbE0H.js +0 -65
  96. package/dist/_chunks/fr-BFmBbE0H.js.map +0 -1
  97. package/dist/_chunks/fr-F94noFiV.mjs +0 -65
  98. package/dist/_chunks/fr-F94noFiV.mjs.map +0 -1
  99. package/dist/_chunks/index-BcYj5jo9.mjs +0 -1589
  100. package/dist/_chunks/index-BcYj5jo9.mjs.map +0 -1
  101. package/dist/_chunks/index-C8NzsAKp.js +0 -1610
  102. package/dist/_chunks/index-C8NzsAKp.js.map +0 -1
  103. package/dist/_chunks/ko-C40pNQ9b.js +0 -64
  104. package/dist/_chunks/ko-C40pNQ9b.js.map +0 -1
  105. package/dist/_chunks/ko-CF-P3Car.mjs +0 -64
  106. package/dist/_chunks/ko-CF-P3Car.mjs.map +0 -1
  107. package/dist/_chunks/pl-Dxr9RUmD.mjs +0 -65
  108. package/dist/_chunks/pl-Dxr9RUmD.mjs.map +0 -1
  109. package/dist/_chunks/pl-JtWBy-JQ.js +0 -65
  110. package/dist/_chunks/pl-JtWBy-JQ.js.map +0 -1
  111. package/dist/_chunks/ru-B-4sVwXN.mjs +0 -67
  112. package/dist/_chunks/ru-B-4sVwXN.mjs.map +0 -1
  113. package/dist/_chunks/ru-COSWt3Nu.js +0 -67
  114. package/dist/_chunks/ru-COSWt3Nu.js.map +0 -1
  115. package/dist/_chunks/tr-BVj1O5ch.js +0 -65
  116. package/dist/_chunks/tr-BVj1O5ch.js.map +0 -1
  117. package/dist/_chunks/tr-Ccu6Yj11.mjs +0 -65
  118. package/dist/_chunks/tr-Ccu6Yj11.mjs.map +0 -1
  119. package/dist/_chunks/zh-BIz395Ms.mjs +0 -65
  120. package/dist/_chunks/zh-BIz395Ms.mjs.map +0 -1
  121. package/dist/_chunks/zh-Hans-Bfo6_TCM.mjs +0 -56
  122. package/dist/_chunks/zh-Hans-Bfo6_TCM.mjs.map +0 -1
  123. package/dist/_chunks/zh-Hans-DIEm_EMC.js +0 -56
  124. package/dist/_chunks/zh-Hans-DIEm_EMC.js.map +0 -1
  125. package/dist/_chunks/zh-wkBPBkhc.js +0 -65
  126. package/dist/_chunks/zh-wkBPBkhc.js.map +0 -1
@@ -1,1589 +0,0 @@
1
- import get from "lodash/get";
2
- import * as yup from "yup";
3
- import { jsxs, jsx, Fragment } from "react/jsx-runtime";
4
- import * as React from "react";
5
- import { Typography, Dialog, Field, Checkbox, Flex, Button, Modal, Box, Status, IconButton, Tooltip, SingleSelect, SingleSelectOption, VisuallyHidden, useCollator, Popover } from "@strapi/design-system";
6
- import { WarningCircle, Pencil, CrossCircle, CheckCircle, ArrowsCounterClockwise, Trash, Plus, Download, ListPlus, Cross, Earth, EarthStriked, CaretDown } from "@strapi/icons";
7
- import { useIntl } from "react-intl";
8
- import { styled } from "styled-components";
9
- import { skipToken } from "@reduxjs/toolkit/query";
10
- import { useAuth, adminApi, useTable, Table, useQueryParams, useForm, useNotification, useAPIErrorHandler } from "@strapi/admin/strapi-admin";
11
- import { unstable_useDocument, unstable_useDocumentActions, buildValidParams } from "@strapi/content-manager/strapi-admin";
12
- import { useParams, Link, useNavigate, matchPath } from "react-router-dom";
13
- import * as qs from "qs";
14
- import { stringify } from "qs";
15
- import omit from "lodash/omit";
16
- const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
17
- const v = glob[path];
18
- if (v) {
19
- return typeof v === "function" ? v() : Promise.resolve(v);
20
- }
21
- return new Promise((_, reject) => {
22
- (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
23
- reject.bind(
24
- null,
25
- new Error(
26
- "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
27
- )
28
- )
29
- );
30
- });
31
- };
32
- const pluginId = "i18n";
33
- const getTranslation = (id) => `${pluginId}.${id}`;
34
- const TextAlignTypography = styled(Typography)`
35
- text-align: center;
36
- `;
37
- const CheckboxConfirmation = ({
38
- description,
39
- isCreating = false,
40
- intlLabel,
41
- name,
42
- onChange,
43
- value
44
- }) => {
45
- const { formatMessage } = useIntl();
46
- const [isOpen, setIsOpen] = React.useState(false);
47
- const handleChange = (value2) => {
48
- if (isCreating || value2) {
49
- return onChange({ target: { name, value: value2, type: "checkbox" } });
50
- }
51
- if (!value2) {
52
- return setIsOpen(true);
53
- }
54
- return null;
55
- };
56
- const handleConfirm = () => {
57
- onChange({ target: { name, value: false, type: "checkbox" } });
58
- };
59
- const label = intlLabel.id ? formatMessage(
60
- { id: intlLabel.id, defaultMessage: intlLabel.defaultMessage },
61
- { ...intlLabel.values }
62
- ) : name;
63
- const hint = description ? formatMessage(
64
- { id: description.id, defaultMessage: description.defaultMessage },
65
- { ...description.values }
66
- ) : "";
67
- return /* @__PURE__ */ jsxs(Dialog.Root, { open: isOpen, onOpenChange: setIsOpen, children: [
68
- /* @__PURE__ */ jsxs(Field.Root, { hint, name, children: [
69
- /* @__PURE__ */ jsx(Checkbox, { onCheckedChange: handleChange, checked: value, children: label }),
70
- /* @__PURE__ */ jsx(Field.Hint, {})
71
- ] }),
72
- /* @__PURE__ */ jsxs(Dialog.Content, { children: [
73
- /* @__PURE__ */ jsx(Dialog.Header, { children: formatMessage({
74
- id: getTranslation("CheckboxConfirmation.Modal.title"),
75
- defaultMessage: "Disable localization"
76
- }) }),
77
- /* @__PURE__ */ jsx(Dialog.Body, { icon: /* @__PURE__ */ jsx(WarningCircle, {}), children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
78
- /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(TextAlignTypography, { children: formatMessage({
79
- id: getTranslation("CheckboxConfirmation.Modal.content"),
80
- defaultMessage: "Disabling localization will engender the deletion of all your content but the one associated to your default locale (if existing)."
81
- }) }) }),
82
- /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(Typography, { fontWeight: "semiBold", children: formatMessage({
83
- id: getTranslation("CheckboxConfirmation.Modal.body"),
84
- defaultMessage: "Do you want to disable it?"
85
- }) }) })
86
- ] }) }),
87
- /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
88
- /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: formatMessage({
89
- id: "components.popUpWarning.button.cancel",
90
- defaultMessage: "No, cancel"
91
- }) }) }),
92
- /* @__PURE__ */ jsx(Dialog.Action, { children: /* @__PURE__ */ jsx(Button, { variant: "danger-light", onClick: handleConfirm, children: formatMessage({
93
- id: getTranslation("CheckboxConfirmation.Modal.button-confirm"),
94
- defaultMessage: "Yes, disable"
95
- }) }) })
96
- ] })
97
- ] })
98
- ] });
99
- };
100
- const LOCALIZED_FIELDS = [
101
- "biginteger",
102
- "boolean",
103
- "component",
104
- "date",
105
- "datetime",
106
- "decimal",
107
- "dynamiczone",
108
- "email",
109
- "enumeration",
110
- "float",
111
- "integer",
112
- "json",
113
- "media",
114
- "number",
115
- "password",
116
- "richtext",
117
- "blocks",
118
- "string",
119
- "text",
120
- "time"
121
- ];
122
- const doesPluginOptionsHaveI18nLocalized = (opts) => typeof opts === "object" && opts !== null && "i18n" in opts && typeof opts.i18n === "object" && opts.i18n !== null && "localized" in opts.i18n && typeof opts.i18n.localized === "boolean";
123
- const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
124
- const useI18n = () => {
125
- const params = useParams();
126
- const userPermissions = useAuth("useI18n", (state) => state.permissions);
127
- const actions = React.useMemo(() => {
128
- const permissions = userPermissions.filter((permission) => permission.subject === params.slug);
129
- return permissions.reduce(
130
- (acc, permission) => {
131
- const [actionShorthand] = permission.action.split(".").slice(-1);
132
- return {
133
- ...acc,
134
- [`can${capitalize(actionShorthand)}`]: permission.properties?.locales ?? []
135
- };
136
- },
137
- { canCreate: [], canRead: [], canUpdate: [], canDelete: [], canPublish: [] }
138
- );
139
- }, [params.slug, userPermissions]);
140
- const { schema } = unstable_useDocument(
141
- {
142
- // We can non-null assert these because below we skip the query if they are not present
143
- collectionType: params.collectionType,
144
- model: params.slug
145
- },
146
- {
147
- skip: true
148
- }
149
- );
150
- if (doesPluginOptionsHaveI18nLocalized(schema?.pluginOptions)) {
151
- return {
152
- hasI18n: schema.pluginOptions.i18n.localized,
153
- ...actions
154
- };
155
- }
156
- return {
157
- hasI18n: false,
158
- ...actions
159
- };
160
- };
161
- const i18nApi = adminApi.enhanceEndpoints({
162
- addTagTypes: ["Locale"]
163
- });
164
- const localesApi = i18nApi.injectEndpoints({
165
- endpoints: (builder) => ({
166
- createLocale: builder.mutation({
167
- query: (data) => ({
168
- url: "/i18n/locales",
169
- method: "POST",
170
- data
171
- }),
172
- invalidatesTags: [{ type: "Locale", id: "LIST" }]
173
- }),
174
- deleteLocale: builder.mutation({
175
- query: (id) => ({
176
- url: `/i18n/locales/${id}`,
177
- method: "DELETE"
178
- }),
179
- invalidatesTags: (result, error, id) => [{ type: "Locale", id }]
180
- }),
181
- getLocales: builder.query({
182
- query: () => "/i18n/locales",
183
- providesTags: (res) => [
184
- { type: "Locale", id: "LIST" },
185
- ...Array.isArray(res) ? res.map((locale) => ({
186
- type: "Locale",
187
- id: locale.id
188
- })) : []
189
- ]
190
- }),
191
- getDefaultLocales: builder.query({
192
- query: () => "/i18n/iso-locales"
193
- }),
194
- updateLocale: builder.mutation({
195
- query: ({ id, ...data }) => ({
196
- url: `/i18n/locales/${id}`,
197
- method: "PUT",
198
- data
199
- }),
200
- invalidatesTags: (result, error, { id }) => [{ type: "Locale", id }]
201
- })
202
- })
203
- });
204
- const {
205
- useCreateLocaleMutation,
206
- useDeleteLocaleMutation,
207
- useGetLocalesQuery,
208
- useGetDefaultLocalesQuery,
209
- useUpdateLocaleMutation
210
- } = localesApi;
211
- const relationsApi = i18nApi.injectEndpoints({
212
- overrideExisting: true,
213
- endpoints: (builder) => ({
214
- getManyDraftRelationCount: builder.query({
215
- query: ({ model, ...params }) => ({
216
- url: `/content-manager/collection-types/${model}/actions/countManyEntriesDraftRelations`,
217
- method: "GET",
218
- config: {
219
- params
220
- }
221
- }),
222
- transformResponse: (response) => response.data
223
- })
224
- })
225
- });
226
- const { useGetManyDraftRelationCountQuery } = relationsApi;
227
- const cleanData = (data, schema, components) => {
228
- const cleanedData = removeFields(data, [
229
- "createdAt",
230
- "createdBy",
231
- "updatedAt",
232
- "updatedBy",
233
- "id",
234
- "documentId",
235
- "publishedAt",
236
- "strapi_stage",
237
- "strapi_assignee",
238
- "locale",
239
- "status"
240
- ]);
241
- const cleanedDataWithoutPasswordAndRelation = recursiveRemoveFieldTypes(
242
- cleanedData,
243
- schema,
244
- components,
245
- ["relation", "password"]
246
- );
247
- return cleanedDataWithoutPasswordAndRelation;
248
- };
249
- const removeFields = (data, fields) => {
250
- return Object.keys(data).reduce((acc, current) => {
251
- if (fields.includes(current)) {
252
- return acc;
253
- }
254
- acc[current] = data[current];
255
- return acc;
256
- }, {});
257
- };
258
- const recursiveRemoveFieldTypes = (data, schema, components, fields) => {
259
- return Object.keys(data).reduce((acc, current) => {
260
- const attribute = schema.attributes[current] ?? { type: void 0 };
261
- if (fields.includes(attribute.type)) {
262
- return acc;
263
- }
264
- if (attribute.type === "dynamiczone") {
265
- acc[current] = data[current].map((componentValue, index2) => {
266
- const { id: _, ...rest } = recursiveRemoveFieldTypes(
267
- componentValue,
268
- components[componentValue.__component],
269
- components,
270
- fields
271
- );
272
- return {
273
- ...rest,
274
- __temp_key__: index2 + 1
275
- };
276
- });
277
- } else if (attribute.type === "component") {
278
- const { repeatable, component } = attribute;
279
- if (repeatable) {
280
- acc[current] = (data[current] ?? []).map((compoData, index2) => {
281
- const { id: _, ...rest } = recursiveRemoveFieldTypes(
282
- compoData,
283
- components[component],
284
- components,
285
- fields
286
- );
287
- return {
288
- ...rest,
289
- __temp_key__: index2 + 1
290
- };
291
- });
292
- } else {
293
- const { id: _, ...rest } = recursiveRemoveFieldTypes(
294
- data[current] ?? {},
295
- components[component],
296
- components,
297
- fields
298
- );
299
- acc[current] = rest;
300
- }
301
- } else {
302
- acc[current] = data[current];
303
- }
304
- return acc;
305
- }, {});
306
- };
307
- const isErrorMessageDescriptor = (object) => {
308
- return typeof object === "object" && object !== null && "id" in object && "defaultMessage" in object;
309
- };
310
- const EntryValidationText = ({
311
- status = "draft",
312
- validationErrors,
313
- action
314
- }) => {
315
- const { formatMessage } = useIntl();
316
- const getErrorStr = (key, value) => {
317
- if (typeof value === "string") {
318
- return `${key}: ${value}`;
319
- } else if (isErrorMessageDescriptor(value)) {
320
- return `${key}: ${formatMessage(value)}`;
321
- } else if (Array.isArray(value)) {
322
- return value.map((v) => getErrorStr(key, v)).join(" ");
323
- } else if (typeof value === "object" && !Array.isArray(value)) {
324
- return Object.entries(value).map(([k, v]) => getErrorStr(k, v)).join(" ");
325
- } else {
326
- return "";
327
- }
328
- };
329
- if (validationErrors) {
330
- const validationErrorsMessages = Object.entries(validationErrors).map(([key, value]) => {
331
- return getErrorStr(key, value);
332
- }).join(" ");
333
- return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
334
- /* @__PURE__ */ jsx(CrossCircle, { fill: "danger600" }),
335
- /* @__PURE__ */ jsx(Tooltip, { label: validationErrorsMessages, children: /* @__PURE__ */ jsx(
336
- Typography,
337
- {
338
- maxWidth: "30rem",
339
- textColor: "danger600",
340
- variant: "omega",
341
- fontWeight: "semiBold",
342
- ellipsis: true,
343
- children: validationErrorsMessages
344
- }
345
- ) })
346
- ] });
347
- }
348
- const getStatusMessage = () => {
349
- if (action === "bulk-publish") {
350
- if (status === "published") {
351
- return {
352
- icon: /* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
353
- text: formatMessage({
354
- id: "content-manager.bulk-publish.already-published",
355
- defaultMessage: "Already Published"
356
- }),
357
- textColor: "success600",
358
- fontWeight: "bold"
359
- };
360
- } else if (status === "modified") {
361
- return {
362
- icon: /* @__PURE__ */ jsx(ArrowsCounterClockwise, { fill: "alternative600" }),
363
- text: formatMessage({
364
- id: "app.utils.ready-to-publish-changes",
365
- defaultMessage: "Ready to publish changes"
366
- })
367
- };
368
- } else {
369
- return {
370
- icon: /* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
371
- text: formatMessage({
372
- id: "app.utils.ready-to-publish",
373
- defaultMessage: "Ready to publish"
374
- })
375
- };
376
- }
377
- } else {
378
- if (status === "draft") {
379
- return {
380
- icon: /* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
381
- text: formatMessage({
382
- id: "content-manager.bulk-unpublish.already-unpublished",
383
- defaultMessage: "Already Unpublished"
384
- }),
385
- textColor: "success600",
386
- fontWeight: "bold"
387
- };
388
- } else {
389
- return {
390
- icon: /* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
391
- text: formatMessage({
392
- id: "app.utils.ready-to-unpublish-changes",
393
- defaultMessage: "Ready to unpublish"
394
- }),
395
- textColor: "success600",
396
- fontWeight: "bold"
397
- };
398
- }
399
- }
400
- };
401
- const { icon, text, textColor = "success600", fontWeight = "normal" } = getStatusMessage();
402
- return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
403
- icon,
404
- /* @__PURE__ */ jsx(Typography, { textColor, fontWeight, children: text })
405
- ] });
406
- };
407
- const BoldChunk = (chunks) => /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: chunks });
408
- const BulkLocaleActionModal = ({
409
- headers,
410
- rows,
411
- localesMetadata,
412
- validationErrors = {},
413
- action
414
- }) => {
415
- const { formatMessage } = useIntl();
416
- const selectedRows = useTable(
417
- "BulkLocaleActionModal",
418
- (state) => state.selectedRows
419
- );
420
- const getFormattedCountMessage = () => {
421
- const currentStatusByLocale = rows.reduce((acc, { locale, status }) => {
422
- acc[locale] = status;
423
- return acc;
424
- }, {});
425
- const localesWithErrors = Object.keys(validationErrors);
426
- const publishedCount = selectedRows.filter(
427
- ({ locale }) => currentStatusByLocale[locale] === "published"
428
- ).length;
429
- const draftCount = selectedRows.filter(
430
- ({ locale }) => (currentStatusByLocale[locale] === "draft" || currentStatusByLocale[locale] === "modified") && !localesWithErrors.includes(locale)
431
- ).length;
432
- const withErrorsCount = localesWithErrors.length;
433
- const messageId = action === "bulk-publish" ? "content-manager.containers.list.selectedEntriesModal.selectedCount.publish" : "content-manager.containers.list.selectedEntriesModal.selectedCount.unpublish";
434
- const defaultMessage = action === "bulk-publish" ? "<b>{publishedCount}</b> {publishedCount, plural, =0 {entries} one {entry} other {entries}} already published. <b>{draftCount}</b> {draftCount, plural, =0 {entries} one {entry} other {entries}} ready to publish. <b>{withErrorsCount}</b> {withErrorsCount, plural, =0 {entries} one {entry} other {entries}} waiting for action." : "<b>{draftCount}</b> {draftCount, plural, =0 {entries} one {entry} other {entries}} already unpublished. <b>{publishedCount}</b> {publishedCount, plural, =0 {entries} one {entry} other {entries}} ready to unpublish.";
435
- return formatMessage(
436
- {
437
- id: messageId,
438
- defaultMessage
439
- },
440
- {
441
- withErrorsCount,
442
- draftCount,
443
- publishedCount,
444
- b: BoldChunk
445
- }
446
- );
447
- };
448
- return /* @__PURE__ */ jsxs(Modal.Body, { children: [
449
- /* @__PURE__ */ jsx(Typography, { children: getFormattedCountMessage() }),
450
- /* @__PURE__ */ jsx(Box, { marginTop: 5, children: /* @__PURE__ */ jsxs(Table.Content, { children: [
451
- /* @__PURE__ */ jsxs(Table.Head, { children: [
452
- /* @__PURE__ */ jsx(Table.HeaderCheckboxCell, {}),
453
- headers.map((head) => /* @__PURE__ */ jsx(Table.HeaderCell, { ...head }, head.name))
454
- ] }),
455
- /* @__PURE__ */ jsx(Table.Body, { children: rows.map(({ locale, status }, index2) => {
456
- const error = validationErrors?.[locale] ?? null;
457
- const statusVariant = status === "draft" ? "primary" : status === "published" ? "success" : "alternative";
458
- return /* @__PURE__ */ jsxs(Table.Row, { children: [
459
- /* @__PURE__ */ jsx(Table.CheckboxCell, { id: locale, "aria-label": `Select ${locale}` }),
460
- /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: Array.isArray(localesMetadata) ? localesMetadata.find((localeEntry) => localeEntry.code === locale)?.name : locale }) }),
461
- /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Box, { display: "flex", children: /* @__PURE__ */ jsx(
462
- Status,
463
- {
464
- display: "flex",
465
- paddingLeft: "6px",
466
- paddingRight: "6px",
467
- paddingTop: "2px",
468
- paddingBottom: "2px",
469
- size: "S",
470
- variant: statusVariant,
471
- children: /* @__PURE__ */ jsx(Typography, { tag: "span", variant: "pi", fontWeight: "bold", children: capitalize(status) })
472
- }
473
- ) }) }),
474
- /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(EntryValidationText, { validationErrors: error, status, action }) }),
475
- /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(
476
- IconButton,
477
- {
478
- tag: Link,
479
- to: {
480
- search: stringify({ plugins: { i18n: { locale } } })
481
- },
482
- label: formatMessage(
483
- {
484
- id: getTranslation("Settings.list.actions.edit"),
485
- defaultMessage: "Edit {name} locale"
486
- },
487
- {
488
- name: locale
489
- }
490
- ),
491
- variant: "ghost",
492
- children: /* @__PURE__ */ jsx(Pencil, {})
493
- }
494
- ) })
495
- ] }, index2);
496
- }) })
497
- ] }) })
498
- ] });
499
- };
500
- const statusVariants = {
501
- draft: "secondary",
502
- published: "success",
503
- modified: "alternative"
504
- };
505
- const LocaleOption = ({
506
- isDraftAndPublishEnabled,
507
- locale,
508
- status,
509
- entryExists
510
- }) => {
511
- const { formatMessage } = useIntl();
512
- if (!entryExists) {
513
- return formatMessage(
514
- {
515
- id: getTranslation("CMEditViewLocalePicker.locale.create"),
516
- defaultMessage: "Create <bold>{locale}</bold> locale"
517
- },
518
- {
519
- bold: (locale2) => /* @__PURE__ */ jsx("b", { children: locale2 }),
520
- locale: locale.name
521
- }
522
- );
523
- }
524
- return /* @__PURE__ */ jsxs(Flex, { width: "100%", gap: 1, justifyContent: "space-between", children: [
525
- /* @__PURE__ */ jsx(Typography, { children: locale.name }),
526
- isDraftAndPublishEnabled ? /* @__PURE__ */ jsx(
527
- Status,
528
- {
529
- display: "flex",
530
- paddingLeft: "6px",
531
- paddingRight: "6px",
532
- paddingTop: "2px",
533
- paddingBottom: "2px",
534
- size: "S",
535
- variant: statusVariants[status],
536
- children: /* @__PURE__ */ jsx(Typography, { tag: "span", variant: "pi", fontWeight: "bold", children: capitalize(status) })
537
- }
538
- ) : null
539
- ] });
540
- };
541
- const LocalePickerAction = ({
542
- document,
543
- meta,
544
- model,
545
- collectionType,
546
- documentId
547
- }) => {
548
- const { formatMessage } = useIntl();
549
- const [{ query }, setQuery] = useQueryParams();
550
- const { hasI18n, canCreate, canRead } = useI18n();
551
- const { data: locales = [] } = useGetLocalesQuery();
552
- const currentDesiredLocale = query.plugins?.i18n?.locale;
553
- const { schema } = unstable_useDocument({
554
- model,
555
- collectionType,
556
- documentId,
557
- params: { locale: currentDesiredLocale }
558
- });
559
- const handleSelect = React.useCallback(
560
- (value) => {
561
- setQuery({
562
- plugins: {
563
- ...query.plugins,
564
- i18n: {
565
- locale: value
566
- }
567
- }
568
- });
569
- },
570
- [query.plugins, setQuery]
571
- );
572
- React.useEffect(() => {
573
- if (!Array.isArray(locales) || !hasI18n) {
574
- return;
575
- }
576
- const doesLocaleExist = locales.find((loc) => loc.code === currentDesiredLocale);
577
- const defaultLocale = locales.find((locale) => locale.isDefault);
578
- if (!doesLocaleExist && defaultLocale?.code) {
579
- handleSelect(defaultLocale.code);
580
- }
581
- }, [handleSelect, hasI18n, locales, currentDesiredLocale]);
582
- const currentLocale = Array.isArray(locales) ? locales.find((locale) => locale.code === currentDesiredLocale) : void 0;
583
- const allCurrentLocales = [
584
- { status: getDocumentStatus(document, meta), locale: currentLocale?.code },
585
- ...document?.localizations ?? []
586
- ];
587
- if (!hasI18n || !Array.isArray(locales) || locales.length === 0) {
588
- return null;
589
- }
590
- const displayedLocales = locales.filter((locale) => {
591
- return canRead.includes(locale.code);
592
- });
593
- return {
594
- label: formatMessage({
595
- id: getTranslation("Settings.locales.modal.locales.label"),
596
- defaultMessage: "Locales"
597
- }),
598
- options: displayedLocales.map((locale) => {
599
- const entryWithLocaleExists = allCurrentLocales.some((doc) => doc.locale === locale.code);
600
- const currentLocaleDoc = allCurrentLocales.find(
601
- (doc) => "locale" in doc ? doc.locale === locale.code : false
602
- );
603
- const permissionsToCheck = currentLocaleDoc ? canRead : canCreate;
604
- return {
605
- disabled: !permissionsToCheck.includes(locale.code),
606
- value: locale.code,
607
- label: /* @__PURE__ */ jsx(
608
- LocaleOption,
609
- {
610
- isDraftAndPublishEnabled: !!schema?.options?.draftAndPublish,
611
- locale,
612
- status: currentLocaleDoc?.status,
613
- entryExists: entryWithLocaleExists
614
- }
615
- ),
616
- startIcon: !entryWithLocaleExists ? /* @__PURE__ */ jsx(Plus, {}) : null
617
- };
618
- }),
619
- customizeContent: () => currentLocale?.name,
620
- onSelect: handleSelect,
621
- value: currentLocale
622
- };
623
- };
624
- const getDocumentStatus = (document, meta) => {
625
- const docStatus = document?.status;
626
- const statuses = meta?.availableStatus ?? [];
627
- if (!docStatus) {
628
- return "draft";
629
- }
630
- if (docStatus === "draft" && statuses.find((doc) => doc.publishedAt !== null)) {
631
- return "published";
632
- }
633
- return docStatus;
634
- };
635
- const FillFromAnotherLocaleAction = ({
636
- documentId,
637
- meta,
638
- model,
639
- collectionType
640
- }) => {
641
- const { formatMessage } = useIntl();
642
- const [{ query }] = useQueryParams();
643
- const { hasI18n } = useI18n();
644
- const currentDesiredLocale = query.plugins?.i18n?.locale;
645
- const [localeSelected, setLocaleSelected] = React.useState(null);
646
- const setValues = useForm("FillFromAnotherLocale", (state) => state.setValues);
647
- const { getDocument } = unstable_useDocumentActions();
648
- const { schema, components } = unstable_useDocument({
649
- model,
650
- documentId,
651
- collectionType,
652
- params: { locale: currentDesiredLocale }
653
- });
654
- const { data: locales = [] } = useGetLocalesQuery();
655
- const availableLocales = Array.isArray(locales) ? locales.filter((locale) => meta?.availableLocales.some((l) => l.locale === locale.code)) : [];
656
- const fillFromLocale = (onClose) => async () => {
657
- const response = await getDocument({
658
- collectionType,
659
- model,
660
- documentId,
661
- params: { locale: localeSelected }
662
- });
663
- if (!response || !schema) {
664
- return;
665
- }
666
- const { data } = response;
667
- const cleanedData = cleanData(data, schema, components);
668
- setValues(cleanedData);
669
- onClose();
670
- };
671
- if (!hasI18n) {
672
- return null;
673
- }
674
- return {
675
- type: "icon",
676
- icon: /* @__PURE__ */ jsx(Download, {}),
677
- disabled: availableLocales.length === 0,
678
- label: formatMessage({
679
- id: getTranslation("CMEditViewCopyLocale.copy-text"),
680
- defaultMessage: "Fill in from another locale"
681
- }),
682
- dialog: {
683
- type: "dialog",
684
- title: formatMessage({
685
- id: getTranslation("CMEditViewCopyLocale.dialog.title"),
686
- defaultMessage: "Confirmation"
687
- }),
688
- content: ({ onClose }) => /* @__PURE__ */ jsxs(Fragment, { children: [
689
- /* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 3, children: [
690
- /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
691
- /* @__PURE__ */ jsx(Typography, { textAlign: "center", children: formatMessage({
692
- id: getTranslation("CMEditViewCopyLocale.dialog.body"),
693
- defaultMessage: "Your current content will be erased and filled by the content of the selected locale:"
694
- }) }),
695
- /* @__PURE__ */ jsxs(Field.Root, { width: "100%", children: [
696
- /* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
697
- id: getTranslation("CMEditViewCopyLocale.dialog.field.label"),
698
- defaultMessage: "Locale"
699
- }) }),
700
- /* @__PURE__ */ jsx(
701
- SingleSelect,
702
- {
703
- value: localeSelected,
704
- placeholder: formatMessage({
705
- id: getTranslation("CMEditViewCopyLocale.dialog.field.placeholder"),
706
- defaultMessage: "Select one locale..."
707
- }),
708
- onChange: (value) => setLocaleSelected(value),
709
- children: availableLocales.map((locale) => /* @__PURE__ */ jsx(SingleSelectOption, { value: locale.code, children: locale.name }, locale.code))
710
- }
711
- )
712
- ] })
713
- ] }) }),
714
- /* @__PURE__ */ jsx(Dialog.Footer, { children: /* @__PURE__ */ jsxs(Flex, { gap: 2, width: "100%", children: [
715
- /* @__PURE__ */ jsx(Button, { flex: "auto", variant: "tertiary", onClick: onClose, children: formatMessage({
716
- id: getTranslation("CMEditViewCopyLocale.cancel-text"),
717
- defaultMessage: "No, cancel"
718
- }) }),
719
- /* @__PURE__ */ jsx(Button, { flex: "auto", variant: "success", onClick: fillFromLocale(onClose), children: formatMessage({
720
- id: getTranslation("CMEditViewCopyLocale.submit-text"),
721
- defaultMessage: "Yes, fill in"
722
- }) })
723
- ] }) })
724
- ] })
725
- }
726
- };
727
- };
728
- const DeleteLocaleAction = ({
729
- document,
730
- documentId,
731
- model,
732
- collectionType
733
- }) => {
734
- const { formatMessage } = useIntl();
735
- const navigate = useNavigate();
736
- const { toggleNotification } = useNotification();
737
- const { delete: deleteAction } = unstable_useDocumentActions();
738
- const { hasI18n, canDelete } = useI18n();
739
- const [{ query }] = useQueryParams();
740
- const { data: locales = [] } = useGetLocalesQuery();
741
- const currentDesiredLocale = query.plugins?.i18n?.locale;
742
- const locale = !("error" in locales) && locales.find((loc) => loc.code === currentDesiredLocale);
743
- if (!hasI18n) {
744
- return null;
745
- }
746
- return {
747
- disabled: document?.locale && !canDelete.includes(document.locale) || !document || !document.id,
748
- position: ["header", "table-row"],
749
- label: formatMessage(
750
- {
751
- id: getTranslation("actions.delete.label"),
752
- defaultMessage: "Delete entry ({locale})"
753
- },
754
- { locale: locale && locale.name }
755
- ),
756
- icon: /* @__PURE__ */ jsx(StyledTrash, {}),
757
- variant: "danger",
758
- dialog: {
759
- type: "dialog",
760
- title: formatMessage({
761
- id: getTranslation("actions.delete.dialog.title"),
762
- defaultMessage: "Confirmation"
763
- }),
764
- content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
765
- /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
766
- /* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
767
- id: getTranslation("actions.delete.dialog.body"),
768
- defaultMessage: "Are you sure?"
769
- }) })
770
- ] }),
771
- onConfirm: async () => {
772
- const unableToDelete = (
773
- // We are unable to delete a collection type without a document ID
774
- // & unable to delete generally if there is no document locale
775
- collectionType !== "single-types" && !documentId || !document?.locale
776
- );
777
- if (unableToDelete) {
778
- console.error(
779
- "You're trying to delete a document without an id or locale, this is likely a bug with Strapi. Please open an issue."
780
- );
781
- toggleNotification({
782
- message: formatMessage({
783
- id: getTranslation("actions.delete.error"),
784
- defaultMessage: "An error occurred while trying to delete the document locale."
785
- }),
786
- type: "danger"
787
- });
788
- return;
789
- }
790
- const res = await deleteAction({
791
- documentId,
792
- model,
793
- collectionType,
794
- params: { locale: document.locale }
795
- });
796
- if (!("error" in res)) {
797
- navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
798
- }
799
- }
800
- }
801
- };
802
- };
803
- const BulkLocaleAction = ({
804
- document,
805
- documentId,
806
- model,
807
- collectionType,
808
- action
809
- }) => {
810
- const locale = document?.locale ?? null;
811
- const [{ query }] = useQueryParams();
812
- const params = React.useMemo(() => buildValidParams(query), [query]);
813
- const isOnPublishedTab = query.status === "published";
814
- const { formatMessage } = useIntl();
815
- const { hasI18n, canPublish } = useI18n();
816
- const { toggleNotification } = useNotification();
817
- const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
818
- const [selectedRows, setSelectedRows] = React.useState([]);
819
- const [isDraftRelationConfirmationOpen, setIsDraftRelationConfirmationOpen] = React.useState(false);
820
- const { publishMany: publishManyAction, unpublishMany: unpublishManyAction } = unstable_useDocumentActions();
821
- const { schema, validate } = unstable_useDocument(
822
- {
823
- model,
824
- collectionType,
825
- documentId,
826
- params: {
827
- locale
828
- }
829
- },
830
- {
831
- // No need to fetch the document, the data is already available in the `document` prop
832
- skip: true
833
- }
834
- );
835
- const { data: localesMetadata = [] } = useGetLocalesQuery(hasI18n ? void 0 : skipToken);
836
- const headers = [
837
- {
838
- label: formatMessage({
839
- id: "global.name",
840
- defaultMessage: "Name"
841
- }),
842
- name: "name"
843
- },
844
- {
845
- label: formatMessage({
846
- id: getTranslation("CMEditViewBulkLocale.status"),
847
- defaultMessage: "Status"
848
- }),
849
- name: "status"
850
- },
851
- {
852
- label: formatMessage({
853
- id: getTranslation("CMEditViewBulkLocale.publication-status"),
854
- defaultMessage: "Publication Status"
855
- }),
856
- name: "publication-status"
857
- }
858
- ];
859
- const [rows, validationErrors] = React.useMemo(() => {
860
- if (!document) {
861
- return [[], {}];
862
- }
863
- const localizations = document.localizations ?? [];
864
- const locales = localizations.map((doc) => {
865
- const { locale: locale2, status } = doc;
866
- return { locale: locale2, status };
867
- });
868
- locales.unshift({
869
- locale: document.locale,
870
- status: document.status
871
- });
872
- const allDocuments = [document, ...localizations];
873
- const errors = allDocuments.reduce((errs, document2) => {
874
- if (!document2) {
875
- return errs;
876
- }
877
- const validation = validate(document2);
878
- if (validation !== null) {
879
- errs[document2.locale] = validation;
880
- }
881
- return errs;
882
- }, {});
883
- return [locales, errors];
884
- }, [document, validate]);
885
- const isBulkPublish = action === "bulk-publish";
886
- const localesForAction = selectedRows.reduce((acc, selectedRow) => {
887
- const isValidLocale = (
888
- // Validation errors are irrelevant if we are trying to unpublish
889
- !isBulkPublish || !Object.keys(validationErrors).includes(selectedRow.locale)
890
- );
891
- const shouldAddLocale = isBulkPublish ? selectedRow.status !== "published" && isValidLocale : selectedRow.status !== "draft" && isValidLocale;
892
- if (shouldAddLocale) {
893
- acc.push(selectedRow.locale);
894
- }
895
- return acc;
896
- }, []);
897
- const enableDraftRelationsCount = false;
898
- const {
899
- data: draftRelationsCount = 0,
900
- isLoading: isDraftRelationsLoading,
901
- error: isDraftRelationsError
902
- } = useGetManyDraftRelationCountQuery(
903
- {
904
- model,
905
- documentIds: [documentId],
906
- locale: localesForAction
907
- },
908
- {
909
- skip: !enableDraftRelationsCount
910
- }
911
- );
912
- React.useEffect(() => {
913
- if (isDraftRelationsError) {
914
- toggleNotification({
915
- type: "danger",
916
- message: formatAPIError(isDraftRelationsError)
917
- });
918
- }
919
- }, [isDraftRelationsError, toggleNotification, formatAPIError]);
920
- if (!schema?.options?.draftAndPublish) {
921
- return null;
922
- }
923
- if (!hasI18n) {
924
- return null;
925
- }
926
- if (!documentId) {
927
- return null;
928
- }
929
- const publish = async () => {
930
- await publishManyAction({
931
- model,
932
- documentIds: [documentId],
933
- params: {
934
- ...params,
935
- locale: localesForAction
936
- }
937
- });
938
- setSelectedRows([]);
939
- };
940
- const unpublish = async () => {
941
- await unpublishManyAction({
942
- model,
943
- documentIds: [documentId],
944
- params: {
945
- ...params,
946
- locale: localesForAction
947
- }
948
- });
949
- setSelectedRows([]);
950
- };
951
- const handleAction = async () => {
952
- if (draftRelationsCount > 0) {
953
- setIsDraftRelationConfirmationOpen(true);
954
- } else if (isBulkPublish) {
955
- await publish();
956
- } else {
957
- await unpublish();
958
- }
959
- };
960
- if (isDraftRelationConfirmationOpen) {
961
- return {
962
- label: formatMessage({
963
- id: "app.components.ConfirmDialog.title",
964
- defaultMessage: "Confirmation"
965
- }),
966
- variant: "danger",
967
- dialog: {
968
- onCancel: () => {
969
- setIsDraftRelationConfirmationOpen(false);
970
- },
971
- onConfirm: async () => {
972
- await publish();
973
- setIsDraftRelationConfirmationOpen(false);
974
- },
975
- type: "dialog",
976
- title: formatMessage({
977
- id: getTranslation("actions.publish.dialog.title"),
978
- defaultMessage: "Confirmation"
979
- }),
980
- content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "center", gap: 2, children: [
981
- /* @__PURE__ */ jsx(WarningCircle, { width: "2.4rem", height: "2.4rem", fill: "danger600" }),
982
- /* @__PURE__ */ jsx(Typography, { textAlign: "center", children: formatMessage({
983
- id: getTranslation("CMEditViewBulkLocale.draft-relation-warning"),
984
- defaultMessage: "Some locales are related to draft entries. Publishing them could leave broken links in your app."
985
- }) }),
986
- /* @__PURE__ */ jsx(Typography, { textAlign: "center", children: formatMessage({
987
- id: getTranslation("CMEditViewBulkLocale.continue-confirmation"),
988
- defaultMessage: "Are you sure you want to continue?"
989
- }) })
990
- ] })
991
- }
992
- };
993
- }
994
- const hasPermission = selectedRows.map(({ locale: locale2 }) => locale2).every((locale2) => canPublish.includes(locale2));
995
- return {
996
- label: formatMessage({
997
- id: getTranslation(`CMEditViewBulkLocale.${isBulkPublish ? "publish" : "unpublish"}-title`),
998
- defaultMessage: `${isBulkPublish ? "Publish" : "Unpublish"} Multiple Locales`
999
- }),
1000
- variant: isBulkPublish ? "secondary" : "danger",
1001
- icon: isBulkPublish ? /* @__PURE__ */ jsx(ListPlus, {}) : /* @__PURE__ */ jsx(Cross, {}),
1002
- disabled: isOnPublishedTab || canPublish.length === 0,
1003
- position: ["panel"],
1004
- dialog: {
1005
- type: "modal",
1006
- title: formatMessage({
1007
- id: getTranslation(`CMEditViewBulkLocale.${isBulkPublish ? "publish" : "unpublish"}-title`),
1008
- defaultMessage: `${isBulkPublish ? "Publish" : "Unpublish"} Multiple Locales`
1009
- }),
1010
- content: () => {
1011
- return /* @__PURE__ */ jsx(
1012
- Table.Root,
1013
- {
1014
- headers,
1015
- rows: rows.map((row) => ({
1016
- ...row,
1017
- id: row.locale
1018
- })),
1019
- selectedRows,
1020
- onSelectedRowsChange: (tableSelectedRows) => setSelectedRows(tableSelectedRows),
1021
- children: /* @__PURE__ */ jsx(
1022
- BulkLocaleActionModal,
1023
- {
1024
- validationErrors,
1025
- headers,
1026
- rows,
1027
- localesMetadata,
1028
- action: action ?? "bulk-publish"
1029
- }
1030
- )
1031
- }
1032
- );
1033
- },
1034
- footer: () => /* @__PURE__ */ jsx(Modal.Footer, { justifyContent: "flex-end", children: /* @__PURE__ */ jsx(
1035
- Button,
1036
- {
1037
- loading: isDraftRelationsLoading,
1038
- disabled: !hasPermission || localesForAction.length === 0,
1039
- variant: "default",
1040
- onClick: handleAction,
1041
- children: formatMessage({
1042
- id: isBulkPublish ? "app.utils.publish" : "app.utils.unpublish",
1043
- defaultMessage: isBulkPublish ? "Publish" : "Unpublish"
1044
- })
1045
- }
1046
- ) })
1047
- }
1048
- };
1049
- };
1050
- const BulkLocalePublishAction = (props) => {
1051
- return BulkLocaleAction({ action: "bulk-publish", ...props });
1052
- };
1053
- const BulkLocaleUnpublishAction = (props) => {
1054
- return BulkLocaleAction({ action: "bulk-unpublish", ...props });
1055
- };
1056
- const StyledTrash = styled(Trash)`
1057
- path {
1058
- fill: currentColor;
1059
- }
1060
- `;
1061
- const Emphasis = (chunks) => {
1062
- return /* @__PURE__ */ jsx(Typography, { fontWeight: "semiBold", textColor: "danger500", children: chunks });
1063
- };
1064
- const DeleteModalAdditionalInfo = () => {
1065
- const { hasI18n } = useI18n();
1066
- const { formatMessage } = useIntl();
1067
- if (!hasI18n) {
1068
- return null;
1069
- }
1070
- return /* @__PURE__ */ jsx(Typography, { textColor: "danger500", children: formatMessage(
1071
- {
1072
- id: getTranslation("Settings.list.actions.deleteAdditionalInfos"),
1073
- defaultMessage: "This will delete the active locale versions <em>(from Internationalization)</em>"
1074
- },
1075
- {
1076
- em: Emphasis
1077
- }
1078
- ) });
1079
- };
1080
- const PublishModalAdditionalInfo = () => {
1081
- const { hasI18n } = useI18n();
1082
- const { formatMessage } = useIntl();
1083
- if (!hasI18n) {
1084
- return null;
1085
- }
1086
- return /* @__PURE__ */ jsx(Typography, { textColor: "danger500", children: formatMessage(
1087
- {
1088
- id: getTranslation("Settings.list.actions.publishAdditionalInfos"),
1089
- defaultMessage: "This will publish the active locale versions <em>(from Internationalization)</em>"
1090
- },
1091
- {
1092
- em: Emphasis
1093
- }
1094
- ) });
1095
- };
1096
- const UnpublishModalAdditionalInfo = () => {
1097
- const { hasI18n } = useI18n();
1098
- const { formatMessage } = useIntl();
1099
- if (!hasI18n) {
1100
- return null;
1101
- }
1102
- return /* @__PURE__ */ jsx(Typography, { textColor: "danger500", children: formatMessage(
1103
- {
1104
- id: getTranslation("Settings.list.actions.unpublishAdditionalInfos"),
1105
- defaultMessage: "This will unpublish the active locale versions <em>(from Internationalization)</em>"
1106
- },
1107
- {
1108
- em: Emphasis
1109
- }
1110
- ) });
1111
- };
1112
- const LocalePicker = () => {
1113
- const { formatMessage } = useIntl();
1114
- const [{ query }, setQuery] = useQueryParams();
1115
- const { hasI18n, canRead, canCreate } = useI18n();
1116
- const { data: locales = [] } = useGetLocalesQuery(void 0, {
1117
- skip: !hasI18n
1118
- });
1119
- const handleChange = React.useCallback(
1120
- (code, replace = false) => {
1121
- setQuery(
1122
- {
1123
- page: 1,
1124
- plugins: { ...query.plugins, i18n: { locale: code } }
1125
- },
1126
- "push",
1127
- replace
1128
- );
1129
- },
1130
- [query.plugins, setQuery]
1131
- );
1132
- React.useEffect(() => {
1133
- if (!Array.isArray(locales) || !hasI18n) {
1134
- return;
1135
- }
1136
- const currentDesiredLocale = query.plugins?.i18n?.locale;
1137
- const doesLocaleExist = locales.find((loc) => loc.code === currentDesiredLocale);
1138
- const defaultLocale = locales.find((locale) => locale.isDefault);
1139
- if (!doesLocaleExist && defaultLocale?.code) {
1140
- handleChange(defaultLocale.code, true);
1141
- }
1142
- }, [hasI18n, handleChange, locales, query.plugins?.i18n?.locale]);
1143
- if (!hasI18n || !Array.isArray(locales) || locales.length === 0) {
1144
- return null;
1145
- }
1146
- const displayedLocales = locales.filter((locale) => {
1147
- return canCreate.includes(locale.code) || canRead.includes(locale.code);
1148
- });
1149
- return /* @__PURE__ */ jsx(
1150
- SingleSelect,
1151
- {
1152
- size: "S",
1153
- "aria-label": formatMessage({
1154
- id: getTranslation("actions.select-locale"),
1155
- defaultMessage: "Select locale"
1156
- }),
1157
- value: query.plugins?.i18n?.locale || locales.find((locale) => locale.isDefault)?.code,
1158
- onChange: handleChange,
1159
- children: displayedLocales.map((locale) => /* @__PURE__ */ jsx(SingleSelectOption, { value: locale.code, children: locale.name }, locale.id))
1160
- }
1161
- );
1162
- };
1163
- const PERMISSIONS = {
1164
- accessMain: [{ action: "plugin::i18n.locale.read", subject: null }],
1165
- create: [{ action: "plugin::i18n.locale.create", subject: null }],
1166
- delete: [{ action: "plugin::i18n.locale.delete", subject: null }],
1167
- update: [{ action: "plugin::i18n.locale.update", subject: null }],
1168
- read: [{ action: "plugin::i18n.locale.read", subject: null }]
1169
- };
1170
- const mutateEditViewHook = ({ layout }) => {
1171
- if (!("i18n" in layout.options) || typeof layout.options.i18n === "object" && layout.options.i18n !== null && "localized" in layout.options.i18n && !layout.options.i18n.localized) {
1172
- return { layout };
1173
- }
1174
- const components = Object.entries(layout.components).reduce(
1175
- (acc, [key, componentLayout]) => {
1176
- return {
1177
- ...acc,
1178
- [key]: {
1179
- ...componentLayout,
1180
- layout: componentLayout.layout.map((row) => row.map(addLabelActionToField))
1181
- }
1182
- };
1183
- },
1184
- {}
1185
- );
1186
- return {
1187
- layout: {
1188
- ...layout,
1189
- components,
1190
- layout: layout.layout.map((panel) => panel.map((row) => row.map(addLabelActionToField)))
1191
- }
1192
- };
1193
- };
1194
- const addLabelActionToField = (field) => {
1195
- const isFieldLocalized = doesFieldHaveI18nPluginOpt(field.attribute.pluginOptions) ? field.attribute.pluginOptions.i18n.localized : true;
1196
- const labelActionProps = {
1197
- title: {
1198
- id: isFieldLocalized ? getTranslation("Field.localized") : getTranslation("Field.not-localized"),
1199
- defaultMessage: isFieldLocalized ? "This value is unique for the selected locale" : "This value is the same across all locales"
1200
- },
1201
- icon: isFieldLocalized ? /* @__PURE__ */ jsx(Earth, {}) : /* @__PURE__ */ jsx(EarthStriked, {})
1202
- };
1203
- return {
1204
- ...field,
1205
- labelAction: /* @__PURE__ */ jsx(LabelAction, { ...labelActionProps })
1206
- };
1207
- };
1208
- const doesFieldHaveI18nPluginOpt = (pluginOpts) => {
1209
- if (!pluginOpts) {
1210
- return false;
1211
- }
1212
- return "i18n" in pluginOpts && typeof pluginOpts.i18n === "object" && pluginOpts.i18n !== null && "localized" in pluginOpts.i18n;
1213
- };
1214
- const LabelAction = ({ title, icon }) => {
1215
- const { formatMessage } = useIntl();
1216
- return /* @__PURE__ */ jsxs(Span, { tag: "span", children: [
1217
- /* @__PURE__ */ jsx(VisuallyHidden, { tag: "span", children: formatMessage(title) }),
1218
- React.cloneElement(icon, {
1219
- "aria-hidden": true,
1220
- focusable: false
1221
- // See: https://allyjs.io/tutorials/focusing-in-svg.html#making-svg-elements-focusable
1222
- })
1223
- ] });
1224
- };
1225
- const Span = styled(Flex)`
1226
- svg {
1227
- width: 12px;
1228
- height: 12px;
1229
-
1230
- fill: ${({ theme }) => theme.colors.neutral500};
1231
-
1232
- path {
1233
- fill: ${({ theme }) => theme.colors.neutral500};
1234
- }
1235
- }
1236
- `;
1237
- const LocaleListCell = ({ locale: currentLocale, localizations }) => {
1238
- const { locale: language } = useIntl();
1239
- const { data: locales = [] } = useGetLocalesQuery();
1240
- const formatter = useCollator(language, {
1241
- sensitivity: "base"
1242
- });
1243
- if (!Array.isArray(locales) || !localizations) {
1244
- return null;
1245
- }
1246
- const availableLocales = localizations.map((loc) => loc.locale);
1247
- const localesForDocument = locales.reduce((acc, locale) => {
1248
- const createdLocale = [currentLocale, ...availableLocales].find((loc) => {
1249
- return loc === locale.code;
1250
- });
1251
- if (createdLocale) {
1252
- acc.push(locale);
1253
- }
1254
- return acc;
1255
- }, []).map((locale) => {
1256
- if (locale.isDefault) {
1257
- return `${locale.name} (default)`;
1258
- }
1259
- return locale.name;
1260
- }).toSorted((a, b) => formatter.compare(a, b));
1261
- return /* @__PURE__ */ jsxs(Popover.Root, { children: [
1262
- /* @__PURE__ */ jsx(Popover.Trigger, { children: /* @__PURE__ */ jsx(Button, { variant: "ghost", type: "button", onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsxs(Flex, { minWidth: "100%", alignItems: "center", justifyContent: "center", fontWeight: "regular", children: [
1263
- /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", ellipsis: true, marginRight: 2, children: localesForDocument.join(", ") }),
1264
- /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(CaretDown, { width: "1.2rem", height: "1.2rem" }) })
1265
- ] }) }) }),
1266
- /* @__PURE__ */ jsx(Popover.Content, { sideOffset: 16, children: /* @__PURE__ */ jsx("ul", { children: localesForDocument.map((name) => /* @__PURE__ */ jsx(Box, { padding: 3, tag: "li", children: /* @__PURE__ */ jsx(Typography, { children: name }) }, name)) }) })
1267
- ] });
1268
- };
1269
- const addColumnToTableHook = ({ displayedHeaders, layout }) => {
1270
- const { options } = layout;
1271
- const isFieldLocalized = doesPluginOptionsHaveI18nLocalized(options) ? options.i18n.localized : false;
1272
- if (!isFieldLocalized) {
1273
- return { displayedHeaders, layout };
1274
- }
1275
- return {
1276
- displayedHeaders: [
1277
- ...displayedHeaders,
1278
- {
1279
- attribute: { type: "string" },
1280
- label: {
1281
- id: getTranslation("list-view.table.header.label"),
1282
- defaultMessage: "Available in"
1283
- },
1284
- searchable: false,
1285
- sortable: false,
1286
- name: "locales",
1287
- // @ts-expect-error – ID is seen as number | string; this will change when we move the type over.
1288
- cellFormatter: (props, _header, meta) => /* @__PURE__ */ jsx(LocaleListCell, { ...props, ...meta })
1289
- }
1290
- ],
1291
- layout
1292
- };
1293
- };
1294
- const addLocaleToReleasesHook = ({ displayedHeaders = [] }) => {
1295
- return {
1296
- displayedHeaders: [
1297
- ...displayedHeaders,
1298
- {
1299
- label: {
1300
- id: "content-releases.page.ReleaseDetails.table.header.label.locale",
1301
- defaultMessage: "locale"
1302
- },
1303
- name: "locale"
1304
- }
1305
- ],
1306
- hasI18nEnabled: true
1307
- };
1308
- };
1309
- const extendCTBAttributeInitialDataMiddleware = () => {
1310
- return ({ getState }) => (next) => (action) => {
1311
- const enhanceAction = () => {
1312
- try {
1313
- const store = getState();
1314
- const hasi18nEnabled = get(
1315
- store,
1316
- [
1317
- "content-type-builder_dataManagerProvider",
1318
- "modifiedData",
1319
- "contentType",
1320
- "schema",
1321
- "pluginOptions",
1322
- "i18n",
1323
- "localized"
1324
- ],
1325
- false
1326
- );
1327
- if (hasi18nEnabled) {
1328
- const pluginOptions = action.options ? { ...action.options.pluginOptions, i18n: { localized: true } } : { i18n: { localized: true } };
1329
- return next({
1330
- ...action,
1331
- options: {
1332
- pluginOptions
1333
- }
1334
- });
1335
- }
1336
- return next(action);
1337
- } catch (err) {
1338
- return next(action);
1339
- }
1340
- };
1341
- if (action.type === "ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA" && action.forTarget === "contentType" && !["relation", "component"].includes(action.attributeType) && !action.isEditing) {
1342
- return enhanceAction();
1343
- }
1344
- if (action.type === "ContentTypeBuilder/FormModal/SET_CUSTOM_FIELD_DATA_SCHEMA" && action.forTarget === "contentType" && !action.isEditing) {
1345
- return enhanceAction();
1346
- }
1347
- if ((action.type === "ContentTypeBuilder/FormModal/RESET_PROPS_AND_SET_FORM_FOR_ADDING_AN_EXISTING_COMPO" || action.type === "ContentTypeBuilder/FormModal/RESET_PROPS_AND_SAVE_CURRENT_DATA") && action.forTarget === "contentType") {
1348
- return enhanceAction();
1349
- }
1350
- return next(action);
1351
- };
1352
- };
1353
- const extendCTBInitialDataMiddleware = () => {
1354
- return () => (next) => (action) => {
1355
- if (action.type === "ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT" && action.modalType === "contentType") {
1356
- const i18n = { localized: false };
1357
- const pluginOptions = action.data.pluginOptions ? { ...action.data.pluginOptions, i18n } : { i18n };
1358
- const data = { ...action.data, pluginOptions };
1359
- if (action.actionType === "create") {
1360
- return next({ ...action, data });
1361
- }
1362
- if (!action.data.pluginOptions?.i18n?.localized) {
1363
- return next({ ...action, data });
1364
- }
1365
- }
1366
- return next(action);
1367
- };
1368
- };
1369
- const localeMiddleware = (ctx) => (next) => (permissions) => {
1370
- const match = matchPath("/content-manager/:collectionType/:model?/:id", ctx.pathname);
1371
- if (!match) {
1372
- return next(permissions);
1373
- }
1374
- const search = qs.parse(ctx.search);
1375
- if (typeof search !== "object") {
1376
- return next(permissions);
1377
- }
1378
- if (!("plugins" in search && typeof search.plugins === "object")) {
1379
- return next(permissions);
1380
- }
1381
- if (!("i18n" in search.plugins && typeof search.plugins.i18n === "object" && !Array.isArray(search.plugins.i18n))) {
1382
- return next(permissions);
1383
- }
1384
- const { locale } = search.plugins.i18n;
1385
- if (typeof locale !== "string") {
1386
- return next(permissions);
1387
- }
1388
- const revisedPermissions = permissions.filter(
1389
- (permission) => !permission.properties?.locales || permission.properties.locales.includes(locale)
1390
- );
1391
- return next(revisedPermissions);
1392
- };
1393
- const prefixPluginTranslations = (trad, pluginId2) => {
1394
- return Object.keys(trad).reduce((acc, current) => {
1395
- acc[`${pluginId2}.${current}`] = trad[current];
1396
- return acc;
1397
- }, {});
1398
- };
1399
- const mutateCTBContentTypeSchema = (nextSchema, prevSchema) => {
1400
- if (!doesPluginOptionsHaveI18nLocalized(nextSchema.pluginOptions)) {
1401
- return nextSchema;
1402
- }
1403
- const isNextSchemaLocalized = nextSchema.pluginOptions.i18n.localized;
1404
- const isPrevSchemaLocalized = doesPluginOptionsHaveI18nLocalized(
1405
- prevSchema?.schema?.pluginOptions
1406
- ) ? prevSchema?.schema?.pluginOptions.i18n.localized : false;
1407
- if (isNextSchemaLocalized && isPrevSchemaLocalized) {
1408
- return nextSchema;
1409
- }
1410
- if (isNextSchemaLocalized) {
1411
- const attributes = addLocalisationToFields(nextSchema.attributes);
1412
- return { ...nextSchema, attributes };
1413
- }
1414
- if (!isNextSchemaLocalized) {
1415
- const pluginOptions = omit(nextSchema.pluginOptions, "i18n");
1416
- const attributes = disableAttributesLocalisation(nextSchema.attributes);
1417
- return { ...nextSchema, pluginOptions, attributes };
1418
- }
1419
- return nextSchema;
1420
- };
1421
- const addLocalisationToFields = (attributes) => Object.keys(attributes).reduce((acc, current) => {
1422
- const currentAttribute = attributes[current];
1423
- if (LOCALIZED_FIELDS.includes(currentAttribute.type)) {
1424
- const i18n = { localized: true };
1425
- const pluginOptions = currentAttribute.pluginOptions ? { ...currentAttribute.pluginOptions, i18n } : { i18n };
1426
- acc[current] = { ...currentAttribute, pluginOptions };
1427
- return acc;
1428
- }
1429
- acc[current] = currentAttribute;
1430
- return acc;
1431
- }, {});
1432
- const disableAttributesLocalisation = (attributes) => Object.keys(attributes).reduce((acc, current) => {
1433
- acc[current] = omit(attributes[current], "pluginOptions.i18n");
1434
- return acc;
1435
- }, {});
1436
- const index = {
1437
- register(app) {
1438
- app.addMiddlewares([extendCTBAttributeInitialDataMiddleware, extendCTBInitialDataMiddleware]);
1439
- app.addMiddlewares([() => i18nApi.middleware]);
1440
- app.addReducers({
1441
- [i18nApi.reducerPath]: i18nApi.reducer
1442
- });
1443
- app.addRBACMiddleware([localeMiddleware]);
1444
- app.registerPlugin({
1445
- id: pluginId,
1446
- name: pluginId
1447
- });
1448
- },
1449
- bootstrap(app) {
1450
- app.registerHook("Admin/CM/pages/ListView/inject-column-in-table", addColumnToTableHook);
1451
- app.registerHook("Admin/CM/pages/EditView/mutate-edit-view-layout", mutateEditViewHook);
1452
- app.registerHook(
1453
- "ContentReleases/pages/ReleaseDetails/add-locale-in-releases",
1454
- addLocaleToReleasesHook
1455
- );
1456
- app.addSettingsLink("global", {
1457
- intlLabel: {
1458
- id: getTranslation("plugin.name"),
1459
- defaultMessage: "Internationalization"
1460
- },
1461
- id: "internationalization",
1462
- to: "internationalization",
1463
- Component: () => import("./SettingsPage-B-KzAqT3.mjs").then((mod) => ({ default: mod.ProtectedSettingsPage })),
1464
- permissions: PERMISSIONS.accessMain
1465
- });
1466
- const contentManager = app.getPlugin("content-manager");
1467
- contentManager.apis.addDocumentHeaderAction([LocalePickerAction, FillFromAnotherLocaleAction]);
1468
- contentManager.apis.addDocumentAction((actions) => {
1469
- const indexOfDeleteAction = actions.findIndex((action) => action.type === "delete");
1470
- actions.splice(indexOfDeleteAction, 0, DeleteLocaleAction);
1471
- return actions;
1472
- });
1473
- contentManager.apis.addDocumentAction((actions) => {
1474
- actions.splice(2, 0, BulkLocalePublishAction);
1475
- actions.splice(5, 0, BulkLocaleUnpublishAction);
1476
- return actions;
1477
- });
1478
- contentManager.injectComponent("listView", "actions", {
1479
- name: "i18n-locale-filter",
1480
- Component: LocalePicker
1481
- });
1482
- contentManager.injectComponent("listView", "publishModalAdditionalInfos", {
1483
- name: "i18n-publish-bullets-in-modal",
1484
- Component: PublishModalAdditionalInfo
1485
- });
1486
- contentManager.injectComponent("listView", "unpublishModalAdditionalInfos", {
1487
- name: "i18n-unpublish-bullets-in-modal",
1488
- Component: UnpublishModalAdditionalInfo
1489
- });
1490
- contentManager.injectComponent("listView", "deleteModalAdditionalInfos", {
1491
- name: "i18n-delete-bullets-in-modal",
1492
- Component: DeleteModalAdditionalInfo
1493
- });
1494
- const ctbPlugin = app.getPlugin("content-type-builder");
1495
- if (ctbPlugin) {
1496
- const ctbFormsAPI = ctbPlugin.apis.forms;
1497
- ctbFormsAPI.addContentTypeSchemaMutation(mutateCTBContentTypeSchema);
1498
- ctbFormsAPI.components.add({ id: "checkboxConfirmation", component: CheckboxConfirmation });
1499
- ctbFormsAPI.extendContentType({
1500
- validator: () => ({
1501
- i18n: yup.object().shape({
1502
- localized: yup.bool()
1503
- })
1504
- }),
1505
- form: {
1506
- advanced() {
1507
- return [
1508
- {
1509
- name: "pluginOptions.i18n.localized",
1510
- description: {
1511
- id: getTranslation("plugin.schema.i18n.localized.description-content-type"),
1512
- defaultMessage: "Allows translating an entry into different languages"
1513
- },
1514
- type: "checkboxConfirmation",
1515
- intlLabel: {
1516
- id: getTranslation("plugin.schema.i18n.localized.label-content-type"),
1517
- defaultMessage: "Localization"
1518
- }
1519
- }
1520
- ];
1521
- }
1522
- }
1523
- });
1524
- ctbFormsAPI.extendFields(LOCALIZED_FIELDS, {
1525
- form: {
1526
- advanced({ contentTypeSchema, forTarget, type, step }) {
1527
- if (forTarget !== "contentType") {
1528
- return [];
1529
- }
1530
- const hasI18nEnabled = get(
1531
- contentTypeSchema,
1532
- ["schema", "pluginOptions", "i18n", "localized"],
1533
- false
1534
- );
1535
- if (!hasI18nEnabled) {
1536
- return [];
1537
- }
1538
- if (type === "component" && step === "1") {
1539
- return [];
1540
- }
1541
- return [
1542
- {
1543
- name: "pluginOptions.i18n.localized",
1544
- description: {
1545
- id: getTranslation("plugin.schema.i18n.localized.description-field"),
1546
- defaultMessage: "The field can have different values in each locale"
1547
- },
1548
- type: "checkbox",
1549
- intlLabel: {
1550
- id: getTranslation("plugin.schema.i18n.localized.label-field"),
1551
- defaultMessage: "Enable localization for this field"
1552
- }
1553
- }
1554
- ];
1555
- }
1556
- }
1557
- });
1558
- }
1559
- },
1560
- async registerTrads({ locales }) {
1561
- const importedTrads = await Promise.all(
1562
- locales.map((locale) => {
1563
- return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => import("./de-D80IRBP9.mjs"), "./translations/dk.json": () => import("./dk-CJ6Zzz78.mjs"), "./translations/en.json": () => import("./en-BTyF7WVW.mjs"), "./translations/es.json": () => import("./es-V8WnPN7w.mjs"), "./translations/fr.json": () => import("./fr-F94noFiV.mjs"), "./translations/ko.json": () => import("./ko-CF-P3Car.mjs"), "./translations/pl.json": () => import("./pl-Dxr9RUmD.mjs"), "./translations/ru.json": () => import("./ru-B-4sVwXN.mjs"), "./translations/tr.json": () => import("./tr-Ccu6Yj11.mjs"), "./translations/zh-Hans.json": () => import("./zh-Hans-Bfo6_TCM.mjs"), "./translations/zh.json": () => import("./zh-BIz395Ms.mjs") }), `./translations/${locale}.json`, 3).then(({ default: data }) => {
1564
- return {
1565
- data: prefixPluginTranslations(data, pluginId),
1566
- locale
1567
- };
1568
- }).catch(() => {
1569
- return {
1570
- data: {},
1571
- locale
1572
- };
1573
- });
1574
- })
1575
- );
1576
- return Promise.resolve(importedTrads);
1577
- }
1578
- };
1579
- export {
1580
- PERMISSIONS as P,
1581
- useGetDefaultLocalesQuery as a,
1582
- useDeleteLocaleMutation as b,
1583
- useUpdateLocaleMutation as c,
1584
- useGetLocalesQuery as d,
1585
- getTranslation as g,
1586
- index as i,
1587
- useCreateLocaleMutation as u
1588
- };
1589
- //# sourceMappingURL=index-BcYj5jo9.mjs.map