@strapi/i18n 0.0.0-next.f6dca5adf05ef6bed9605a1535999ab0bbbf063e → 0.0.0-next.fc9d26d995624dc886b29f563e1de655d47e6609

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