@strapi/i18n 5.9.0 → 5.10.0

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