@strapi/i18n 0.0.0-experimental.145e7d7ddefd1aef71aaf3d9bb86440d013035bf

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