@strapi/i18n 0.0.0 → 5.0.0-beta.7

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 (163) hide show
  1. package/README.md +17 -1
  2. package/dist/_chunks/SettingsPage-BvzzUueI.js +584 -0
  3. package/dist/_chunks/SettingsPage-BvzzUueI.js.map +1 -0
  4. package/dist/_chunks/SettingsPage-CB5yd4O3.mjs +564 -0
  5. package/dist/_chunks/SettingsPage-CB5yd4O3.mjs.map +1 -0
  6. package/dist/_chunks/de-9eCAqqrB.mjs +66 -0
  7. package/dist/_chunks/de-9eCAqqrB.mjs.map +1 -0
  8. package/dist/_chunks/de-DtWiGdHl.js +66 -0
  9. package/dist/_chunks/de-DtWiGdHl.js.map +1 -0
  10. package/dist/_chunks/dk-2qBjxt-P.mjs +66 -0
  11. package/dist/_chunks/dk-2qBjxt-P.mjs.map +1 -0
  12. package/dist/_chunks/dk-D8C-casx.js +66 -0
  13. package/dist/_chunks/dk-D8C-casx.js.map +1 -0
  14. package/dist/_chunks/en-BuBc6LKZ.js +69 -0
  15. package/dist/_chunks/en-BuBc6LKZ.js.map +1 -0
  16. package/dist/_chunks/en-CnrTsjWS.mjs +69 -0
  17. package/dist/_chunks/en-CnrTsjWS.mjs.map +1 -0
  18. package/dist/_chunks/es-DS-XFGSw.js +66 -0
  19. package/dist/_chunks/es-DS-XFGSw.js.map +1 -0
  20. package/dist/_chunks/es-DlmMVaBG.mjs +66 -0
  21. package/dist/_chunks/es-DlmMVaBG.mjs.map +1 -0
  22. package/dist/_chunks/fr-3S6ke71d.mjs +66 -0
  23. package/dist/_chunks/fr-3S6ke71d.mjs.map +1 -0
  24. package/dist/_chunks/fr-BTjekDpq.js +66 -0
  25. package/dist/_chunks/fr-BTjekDpq.js.map +1 -0
  26. package/dist/_chunks/index-DRjoX_5r.js +1084 -0
  27. package/dist/_chunks/index-DRjoX_5r.js.map +1 -0
  28. package/dist/_chunks/index-aiqKWFfV.mjs +1061 -0
  29. package/dist/_chunks/index-aiqKWFfV.mjs.map +1 -0
  30. package/dist/_chunks/ko-DmcGUBQ3.js +65 -0
  31. package/dist/_chunks/ko-DmcGUBQ3.js.map +1 -0
  32. package/dist/_chunks/ko-qTjQ8IMw.mjs +65 -0
  33. package/dist/_chunks/ko-qTjQ8IMw.mjs.map +1 -0
  34. package/dist/_chunks/pl-B67TSHqT.mjs +66 -0
  35. package/dist/_chunks/pl-B67TSHqT.mjs.map +1 -0
  36. package/dist/_chunks/pl-Cn5RYonZ.js +66 -0
  37. package/dist/_chunks/pl-Cn5RYonZ.js.map +1 -0
  38. package/dist/_chunks/ru-BMBgVL3s.js +68 -0
  39. package/dist/_chunks/ru-BMBgVL3s.js.map +1 -0
  40. package/dist/_chunks/ru-hagMa57T.mjs +68 -0
  41. package/dist/_chunks/ru-hagMa57T.mjs.map +1 -0
  42. package/dist/_chunks/tr-CarUU76c.js +66 -0
  43. package/dist/_chunks/tr-CarUU76c.js.map +1 -0
  44. package/dist/_chunks/tr-Dw_jmkG-.mjs +66 -0
  45. package/dist/_chunks/tr-Dw_jmkG-.mjs.map +1 -0
  46. package/dist/_chunks/zh-57YM4amO.mjs +66 -0
  47. package/dist/_chunks/zh-57YM4amO.mjs.map +1 -0
  48. package/dist/_chunks/zh-CukOviB0.js +66 -0
  49. package/dist/_chunks/zh-CukOviB0.js.map +1 -0
  50. package/dist/_chunks/zh-Hans-DSHIXAa3.js +57 -0
  51. package/dist/_chunks/zh-Hans-DSHIXAa3.js.map +1 -0
  52. package/dist/_chunks/zh-Hans-Dyc-aR-h.mjs +57 -0
  53. package/dist/_chunks/zh-Hans-Dyc-aR-h.mjs.map +1 -0
  54. package/dist/admin/index.js +6 -0
  55. package/dist/admin/index.js.map +1 -0
  56. package/dist/admin/index.mjs +7 -0
  57. package/dist/admin/index.mjs.map +1 -0
  58. package/dist/admin/src/components/CMHeaderActions.d.ts +4 -0
  59. package/dist/admin/src/components/CMListViewModalsAdditionalInformation.d.ts +4 -0
  60. package/dist/admin/src/components/CheckboxConfirmation.d.ts +20 -0
  61. package/dist/admin/src/components/CreateLocale.d.ts +29 -0
  62. package/dist/admin/src/components/DeleteLocale.d.ts +5 -0
  63. package/dist/admin/src/components/EditLocale.d.ts +13 -0
  64. package/dist/admin/src/components/Initializer.d.ts +5 -0
  65. package/dist/admin/src/components/LocaleListCell.d.ts +9 -0
  66. package/dist/admin/src/components/LocalePicker.d.ts +2 -0
  67. package/dist/admin/src/components/LocaleTable.d.ts +11 -0
  68. package/dist/admin/src/constants.d.ts +22 -0
  69. package/dist/admin/src/contentManagerHooks/editView.d.ts +6 -0
  70. package/dist/admin/src/contentManagerHooks/listView.d.ts +22 -0
  71. package/dist/admin/src/contentReleasesHooks/releaseDetailsView.d.ts +36 -0
  72. package/dist/admin/src/hooks/useI18n.d.ts +16 -0
  73. package/dist/admin/src/index.d.ts +16 -0
  74. package/dist/admin/src/middlewares/extendCTBAttributeInitialData.d.ts +4 -0
  75. package/dist/admin/src/middlewares/extendCTBInitialData.d.ts +4 -0
  76. package/dist/admin/src/middlewares/rbac-middleware.d.ts +3 -0
  77. package/dist/admin/src/pages/SettingsPage.d.ts +3 -0
  78. package/dist/admin/src/pluginId.d.ts +1 -0
  79. package/dist/admin/src/services/api.d.ts +3 -0
  80. package/dist/admin/src/services/locales.d.ts +4 -0
  81. package/dist/admin/src/types.d.ts +9 -0
  82. package/dist/admin/src/utils/baseQuery.d.ts +19 -0
  83. package/dist/admin/src/utils/fields.d.ts +7 -0
  84. package/dist/admin/src/utils/getTranslation.d.ts +2 -0
  85. package/dist/admin/src/utils/prefixPluginTranslations.d.ts +3 -0
  86. package/dist/admin/src/utils/schemas.d.ts +24 -0
  87. package/dist/admin/src/utils/strings.d.ts +2 -0
  88. package/dist/server/index.js +3522 -0
  89. package/dist/server/index.js.map +1 -0
  90. package/dist/server/index.mjs +3503 -0
  91. package/dist/server/index.mjs.map +1 -0
  92. package/dist/server/src/bootstrap.d.ts +6 -0
  93. package/dist/server/src/bootstrap.d.ts.map +1 -0
  94. package/dist/server/src/constants/index.d.ts +15 -0
  95. package/dist/server/src/constants/index.d.ts.map +1 -0
  96. package/dist/server/src/content-types/index.d.ts +37 -0
  97. package/dist/server/src/content-types/index.d.ts.map +1 -0
  98. package/dist/server/src/content-types/locale/index.d.ts +35 -0
  99. package/dist/server/src/content-types/locale/index.d.ts.map +1 -0
  100. package/dist/server/src/controllers/content-types.d.ts +6 -0
  101. package/dist/server/src/controllers/content-types.d.ts.map +1 -0
  102. package/dist/server/src/controllers/index.d.ts +10 -0
  103. package/dist/server/src/controllers/index.d.ts.map +1 -0
  104. package/dist/server/src/controllers/iso-locales.d.ts +4 -0
  105. package/dist/server/src/controllers/iso-locales.d.ts.map +1 -0
  106. package/dist/server/src/controllers/locales.d.ts +4 -0
  107. package/dist/server/src/controllers/locales.d.ts.map +1 -0
  108. package/dist/server/src/controllers/validate-locale-creation.d.ts +4 -0
  109. package/dist/server/src/controllers/validate-locale-creation.d.ts.map +1 -0
  110. package/dist/server/src/domain/locale.d.ts +11 -0
  111. package/dist/server/src/domain/locale.d.ts.map +1 -0
  112. package/dist/server/src/graphql.d.ts +8 -0
  113. package/dist/server/src/graphql.d.ts.map +1 -0
  114. package/dist/server/src/index.d.ts +148 -0
  115. package/dist/server/src/index.d.ts.map +1 -0
  116. package/dist/server/src/migrations/content-type/disable/index.d.ts +3 -0
  117. package/dist/server/src/migrations/content-type/disable/index.d.ts.map +1 -0
  118. package/dist/server/src/migrations/content-type/enable/index.d.ts +3 -0
  119. package/dist/server/src/migrations/content-type/enable/index.d.ts.map +1 -0
  120. package/dist/server/src/register.d.ts +6 -0
  121. package/dist/server/src/register.d.ts.map +1 -0
  122. package/dist/server/src/routes/admin.d.ts +18 -0
  123. package/dist/server/src/routes/admin.d.ts.map +1 -0
  124. package/dist/server/src/routes/content-api.d.ts +10 -0
  125. package/dist/server/src/routes/content-api.d.ts.map +1 -0
  126. package/dist/server/src/routes/index.d.ts +28 -0
  127. package/dist/server/src/routes/index.d.ts.map +1 -0
  128. package/dist/server/src/services/content-types.d.ts +13 -0
  129. package/dist/server/src/services/content-types.d.ts.map +1 -0
  130. package/dist/server/src/services/entity-service-decorator.d.ts +29 -0
  131. package/dist/server/src/services/entity-service-decorator.d.ts.map +1 -0
  132. package/dist/server/src/services/index.d.ts +71 -0
  133. package/dist/server/src/services/index.d.ts.map +1 -0
  134. package/dist/server/src/services/iso-locales.d.ts +10 -0
  135. package/dist/server/src/services/iso-locales.d.ts.map +1 -0
  136. package/dist/server/src/services/locales.d.ts +17 -0
  137. package/dist/server/src/services/locales.d.ts.map +1 -0
  138. package/dist/server/src/services/localizations.d.ts +8 -0
  139. package/dist/server/src/services/localizations.d.ts.map +1 -0
  140. package/dist/server/src/services/metrics.d.ts +8 -0
  141. package/dist/server/src/services/metrics.d.ts.map +1 -0
  142. package/dist/server/src/services/permissions/actions.d.ts +16 -0
  143. package/dist/server/src/services/permissions/actions.d.ts.map +1 -0
  144. package/dist/server/src/services/permissions/conditions.d.ts +15 -0
  145. package/dist/server/src/services/permissions/conditions.d.ts.map +1 -0
  146. package/dist/server/src/services/permissions/engine.d.ts +6 -0
  147. package/dist/server/src/services/permissions/engine.d.ts.map +1 -0
  148. package/dist/server/src/services/permissions/sections-builder.d.ts +6 -0
  149. package/dist/server/src/services/permissions/sections-builder.d.ts.map +1 -0
  150. package/dist/server/src/services/permissions.d.ts +28 -0
  151. package/dist/server/src/services/permissions.d.ts.map +1 -0
  152. package/dist/server/src/utils/index.d.ts +43 -0
  153. package/dist/server/src/utils/index.d.ts.map +1 -0
  154. package/dist/server/src/validation/content-types.d.ts +3 -0
  155. package/dist/server/src/validation/content-types.d.ts.map +1 -0
  156. package/dist/server/src/validation/locales.d.ts +12 -0
  157. package/dist/server/src/validation/locales.d.ts.map +1 -0
  158. package/dist/shared/contracts/content-manager.d.ts +27 -0
  159. package/dist/shared/contracts/iso-locales.d.ts +21 -0
  160. package/dist/shared/contracts/locales.d.ts +77 -0
  161. package/dist/shared/contracts/shared.d.ts +6 -0
  162. package/package.json +82 -4
  163. package/strapi-server.js +3 -0
@@ -0,0 +1,1084 @@
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 strapiAdmin = require("@strapi/admin/strapi-admin");
11
+ const strapiAdmin$1 = require("@strapi/content-manager/strapi-admin");
12
+ const reactRouterDom = require("react-router-dom");
13
+ const react = require("@reduxjs/toolkit/query/react");
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
+ setIsOpen(false);
76
+ };
77
+ const handleToggle = () => setIsOpen((prev) => !prev);
78
+ const label = intlLabel.id ? formatMessage(
79
+ { id: intlLabel.id, defaultMessage: intlLabel.defaultMessage },
80
+ { ...intlLabel.values }
81
+ ) : name;
82
+ const hint = description ? formatMessage(
83
+ { id: description.id, defaultMessage: description.defaultMessage },
84
+ { ...description.values }
85
+ ) : "";
86
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
87
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { hint, name, children: [
88
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Checkbox, { onValueChange: handleChange, value, type: "checkbox", children: label }),
89
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {})
90
+ ] }),
91
+ isOpen && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog, { onClose: handleToggle, title: "Confirmation", isOpen, children: [
92
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.DialogBody, { icon: /* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, {}), children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
93
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", children: /* @__PURE__ */ jsxRuntime.jsx(TextAlignTypography, { id: "confirm-description", children: formatMessage({
94
+ id: getTranslation("CheckboxConfirmation.Modal.content"),
95
+ defaultMessage: "Disabling localization will engender the deletion of all your content but the one associated to your default locale (if existing)."
96
+ }) }) }),
97
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "semiBold", id: "confirm-description", children: formatMessage({
98
+ id: getTranslation("CheckboxConfirmation.Modal.body"),
99
+ defaultMessage: "Do you want to disable it?"
100
+ }) }) })
101
+ ] }) }),
102
+ /* @__PURE__ */ jsxRuntime.jsx(
103
+ designSystem.DialogFooter,
104
+ {
105
+ startAction: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: handleToggle, variant: "tertiary", children: formatMessage({
106
+ id: "components.popUpWarning.button.cancel",
107
+ defaultMessage: "No, cancel"
108
+ }) }),
109
+ endAction: /* @__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
+ };
118
+ const LOCALIZED_FIELDS = [
119
+ "biginteger",
120
+ "boolean",
121
+ "component",
122
+ "date",
123
+ "datetime",
124
+ "decimal",
125
+ "dynamiczone",
126
+ "email",
127
+ "enumeration",
128
+ "float",
129
+ "integer",
130
+ "json",
131
+ "media",
132
+ "number",
133
+ "password",
134
+ "richtext",
135
+ "blocks",
136
+ "string",
137
+ "text",
138
+ "time"
139
+ ];
140
+ 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";
141
+ const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
142
+ const useI18n = () => {
143
+ const params = reactRouterDom.useParams();
144
+ const userPermissions = strapiAdmin.useAuth("useI18n", (state) => state.permissions);
145
+ const actions = React__namespace.useMemo(() => {
146
+ const permissions = userPermissions.filter((permission) => permission.subject === params.slug);
147
+ return permissions.reduce(
148
+ (acc, permission) => {
149
+ const [actionShorthand] = permission.action.split(".").slice(-1);
150
+ return {
151
+ ...acc,
152
+ [`can${capitalize(actionShorthand)}`]: permission.properties?.locales ?? []
153
+ };
154
+ },
155
+ { canCreate: [], canRead: [], canUpdate: [], canDelete: [], canPublish: [] }
156
+ );
157
+ }, [params.slug, userPermissions]);
158
+ const { schema } = strapiAdmin$1.unstable_useDocument(
159
+ {
160
+ // We can non-null assert these because below we skip the query if they are not present
161
+ collectionType: params.collectionType,
162
+ model: params.slug
163
+ },
164
+ {
165
+ skip: !params.slug || !params.collectionType
166
+ }
167
+ );
168
+ if (doesPluginOptionsHaveI18nLocalized(schema?.pluginOptions)) {
169
+ return {
170
+ hasI18n: schema.pluginOptions.i18n.localized,
171
+ ...actions
172
+ };
173
+ }
174
+ return {
175
+ hasI18n: false,
176
+ ...actions
177
+ };
178
+ };
179
+ const fetchBaseQuery = () => async (query, { signal }) => {
180
+ try {
181
+ const { get: get2, post, del, put } = strapiAdmin.getFetchClient();
182
+ if (typeof query === "string") {
183
+ const result = await get2(query, { signal });
184
+ return { data: result.data };
185
+ } else {
186
+ const { url, method = "GET", data, config } = query;
187
+ if (method === "POST") {
188
+ const result2 = await post(url, data, {
189
+ ...config,
190
+ signal
191
+ });
192
+ return { data: result2.data };
193
+ }
194
+ if (method === "DELETE") {
195
+ const result2 = await del(url, {
196
+ ...config,
197
+ signal
198
+ });
199
+ return { data: result2.data };
200
+ }
201
+ if (method === "PUT") {
202
+ const result2 = await put(url, data, {
203
+ ...config,
204
+ signal
205
+ });
206
+ return { data: result2.data };
207
+ }
208
+ const result = await get2(url, {
209
+ ...config,
210
+ signal
211
+ });
212
+ return { data: result.data };
213
+ }
214
+ } catch (err) {
215
+ if (strapiAdmin.isFetchError(err)) {
216
+ if (typeof err.response?.data === "object" && err.response?.data !== null && "error" in err.response?.data) {
217
+ return { data: void 0, error: err.response?.data.error };
218
+ } else {
219
+ return {
220
+ data: void 0,
221
+ error: {
222
+ name: "UnknownError",
223
+ message: "There was an unknown error response from the API",
224
+ details: err.response,
225
+ status: err.status
226
+ }
227
+ };
228
+ }
229
+ }
230
+ const error = err;
231
+ return {
232
+ data: void 0,
233
+ error: {
234
+ name: error.name,
235
+ message: error.message,
236
+ stack: error.stack
237
+ }
238
+ };
239
+ }
240
+ };
241
+ const isBaseQueryError = (error) => {
242
+ return error.name !== void 0;
243
+ };
244
+ const i18nApi = react.createApi({
245
+ reducerPath: "i18nApi",
246
+ baseQuery: fetchBaseQuery(),
247
+ tagTypes: ["Locale"],
248
+ endpoints: () => ({})
249
+ });
250
+ const localesApi = i18nApi.injectEndpoints({
251
+ endpoints: (builder) => ({
252
+ createLocale: builder.mutation({
253
+ query: (data) => ({
254
+ url: "/i18n/locales",
255
+ method: "POST",
256
+ data
257
+ }),
258
+ invalidatesTags: [{ type: "Locale", id: "LIST" }]
259
+ }),
260
+ deleteLocale: builder.mutation({
261
+ query: (id) => ({
262
+ url: `/i18n/locales/${id}`,
263
+ method: "DELETE"
264
+ }),
265
+ invalidatesTags: (result, error, id) => [{ type: "Locale", id }]
266
+ }),
267
+ getLocales: builder.query({
268
+ query: () => "/i18n/locales",
269
+ providesTags: (res) => [
270
+ { type: "Locale", id: "LIST" },
271
+ ...Array.isArray(res) ? res.map((locale) => ({
272
+ type: "Locale",
273
+ id: locale.id
274
+ })) : []
275
+ ]
276
+ }),
277
+ getDefaultLocales: builder.query({
278
+ query: () => "/i18n/iso-locales"
279
+ }),
280
+ updateLocale: builder.mutation({
281
+ query: ({ id, ...data }) => ({
282
+ url: `/i18n/locales/${id}`,
283
+ method: "PUT",
284
+ data
285
+ }),
286
+ invalidatesTags: (result, error, { id }) => [{ type: "Locale", id }]
287
+ })
288
+ })
289
+ });
290
+ const {
291
+ useCreateLocaleMutation,
292
+ useDeleteLocaleMutation,
293
+ useGetLocalesQuery,
294
+ useGetDefaultLocalesQuery,
295
+ useUpdateLocaleMutation
296
+ } = localesApi;
297
+ const LocalePickerAction = ({
298
+ document,
299
+ meta,
300
+ model,
301
+ collectionType,
302
+ documentId
303
+ }) => {
304
+ const { formatMessage } = reactIntl.useIntl();
305
+ const [{ query }, setQuery] = strapiAdmin.useQueryParams();
306
+ const { hasI18n, canCreate, canRead } = useI18n();
307
+ const { data: locales = [] } = useGetLocalesQuery();
308
+ const { schema } = strapiAdmin$1.unstable_useDocument({ model, collectionType, documentId });
309
+ const handleSelect = React__namespace.useCallback(
310
+ (value) => {
311
+ setQuery({
312
+ plugins: {
313
+ ...query.plugins,
314
+ i18n: {
315
+ locale: value
316
+ }
317
+ }
318
+ });
319
+ },
320
+ [query.plugins, setQuery]
321
+ );
322
+ React__namespace.useEffect(() => {
323
+ if (!Array.isArray(locales) || !hasI18n) {
324
+ return;
325
+ }
326
+ const currentDesiredLocale = query.plugins?.i18n?.locale;
327
+ const doesLocaleExist = locales.find((loc) => loc.code === currentDesiredLocale);
328
+ const defaultLocale = locales.find((locale) => locale.isDefault);
329
+ if (!doesLocaleExist && defaultLocale?.code) {
330
+ handleSelect(defaultLocale.code);
331
+ }
332
+ }, [handleSelect, hasI18n, locales, query.plugins?.i18n?.locale]);
333
+ if (!hasI18n || !Array.isArray(locales) || locales.length === 0) {
334
+ return null;
335
+ }
336
+ const currentLocale = query.plugins?.i18n?.locale || locales.find((loc) => loc.isDefault)?.code;
337
+ const allCurrentLocales = [
338
+ { status: getDocumentStatus(document, meta), locale: currentLocale },
339
+ ...meta?.availableLocales ?? []
340
+ ];
341
+ return {
342
+ label: formatMessage({
343
+ id: getTranslation("Settings.locales.modal.locales.label"),
344
+ defaultMessage: "Locales"
345
+ }),
346
+ options: locales.map((locale) => {
347
+ const currentLocaleDoc = allCurrentLocales.find(
348
+ (doc) => "locale" in doc ? doc.locale === locale.code : false
349
+ );
350
+ const status = currentLocaleDoc?.status ?? "draft";
351
+ const permissionsToCheck = currentLocaleDoc ? canCreate : canRead;
352
+ const statusVariant = status === "draft" ? "primary" : status === "published" ? "success" : "alternative";
353
+ return {
354
+ disabled: !permissionsToCheck.includes(locale.code),
355
+ value: locale.code,
356
+ label: locale.name,
357
+ startIcon: schema?.options?.draftAndPublish ? /* @__PURE__ */ jsxRuntime.jsx(
358
+ designSystem.Status,
359
+ {
360
+ display: "flex",
361
+ paddingLeft: "6px",
362
+ paddingRight: "6px",
363
+ paddingTop: "2px",
364
+ paddingBottom: "2px",
365
+ showBullet: false,
366
+ size: "S",
367
+ variant: statusVariant,
368
+ children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "span", variant: "pi", fontWeight: "bold", children: capitalize(status) })
369
+ }
370
+ ) : null
371
+ };
372
+ }),
373
+ onSelect: handleSelect,
374
+ value: currentLocale
375
+ };
376
+ };
377
+ const getDocumentStatus = (document, meta) => {
378
+ const docStatus = document?.status;
379
+ const statuses = meta?.availableStatus ?? [];
380
+ if (!docStatus) {
381
+ return "draft";
382
+ }
383
+ if (docStatus === "draft" && statuses.find((doc) => doc.publishedAt !== null)) {
384
+ return "published";
385
+ }
386
+ return docStatus;
387
+ };
388
+ const DeleteLocaleAction = ({
389
+ document,
390
+ documentId,
391
+ model,
392
+ collectionType
393
+ }) => {
394
+ const { formatMessage } = reactIntl.useIntl();
395
+ const navigate = reactRouterDom.useNavigate();
396
+ const { toggleNotification } = strapiAdmin.useNotification();
397
+ const { delete: deleteAction } = strapiAdmin$1.unstable_useDocumentActions();
398
+ const { hasI18n, canDelete } = useI18n();
399
+ if (!hasI18n) {
400
+ return null;
401
+ }
402
+ return {
403
+ disabled: document?.locale && !canDelete.includes(document.locale) || !document || !document.id,
404
+ position: ["header", "table-row"],
405
+ label: formatMessage({
406
+ id: getTranslation("actions.delete.label"),
407
+ defaultMessage: "Delete locale"
408
+ }),
409
+ icon: /* @__PURE__ */ jsxRuntime.jsx(StyledTrash, {}),
410
+ variant: "danger",
411
+ dialog: {
412
+ type: "dialog",
413
+ title: formatMessage({
414
+ id: getTranslation("actions.delete.dialog.title"),
415
+ defaultMessage: "Confirmation"
416
+ }),
417
+ content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
418
+ /* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
419
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
420
+ id: getTranslation("actions.delete.dialog.body"),
421
+ defaultMessage: "Are you sure?"
422
+ }) })
423
+ ] }),
424
+ onConfirm: async () => {
425
+ if (!documentId || !document?.locale) {
426
+ console.error(
427
+ "You're trying to delete a document without an id or locale, this is likely a bug with Strapi. Please open an issue."
428
+ );
429
+ toggleNotification({
430
+ message: formatMessage({
431
+ id: getTranslation("actions.delete.error"),
432
+ defaultMessage: "An error occurred while trying to delete the document locale."
433
+ }),
434
+ type: "danger"
435
+ });
436
+ return;
437
+ }
438
+ const res = await deleteAction({
439
+ documentId,
440
+ model,
441
+ collectionType,
442
+ params: { locale: document.locale }
443
+ });
444
+ if (!("error" in res)) {
445
+ navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
446
+ }
447
+ }
448
+ }
449
+ };
450
+ };
451
+ const StyledTrash = styledComponents.styled(icons.Trash)`
452
+ path {
453
+ fill: currentColor;
454
+ }
455
+ `;
456
+ const Emphasis = (chunks) => {
457
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "semiBold", textColor: "danger500", children: chunks });
458
+ };
459
+ const DeleteModalAdditionalInfo = () => {
460
+ const { hasI18n } = useI18n();
461
+ const { formatMessage } = reactIntl.useIntl();
462
+ if (!hasI18n) {
463
+ return null;
464
+ }
465
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger500", children: formatMessage(
466
+ {
467
+ id: getTranslation("Settings.list.actions.deleteAdditionalInfos"),
468
+ defaultMessage: "This will delete the active locale versions <em>(from Internationalization)</em>"
469
+ },
470
+ {
471
+ em: Emphasis
472
+ }
473
+ ) });
474
+ };
475
+ const PublishModalAdditionalInfo = () => {
476
+ const { hasI18n } = useI18n();
477
+ const { formatMessage } = reactIntl.useIntl();
478
+ if (!hasI18n) {
479
+ return null;
480
+ }
481
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger500", children: formatMessage(
482
+ {
483
+ id: getTranslation("Settings.list.actions.publishAdditionalInfos"),
484
+ defaultMessage: "This will publish the active locale versions <em>(from Internationalization)</em>"
485
+ },
486
+ {
487
+ em: Emphasis
488
+ }
489
+ ) });
490
+ };
491
+ const UnpublishModalAdditionalInfo = () => {
492
+ const { hasI18n } = useI18n();
493
+ const { formatMessage } = reactIntl.useIntl();
494
+ if (!hasI18n) {
495
+ return null;
496
+ }
497
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger500", children: formatMessage(
498
+ {
499
+ id: getTranslation("Settings.list.actions.unpublishAdditionalInfos"),
500
+ defaultMessage: "This will unpublish the active locale versions <em>(from Internationalization)</em>"
501
+ },
502
+ {
503
+ em: Emphasis
504
+ }
505
+ ) });
506
+ };
507
+ const Initializer = ({ setPlugin }) => {
508
+ const setPluginRef = React__namespace.useRef(setPlugin);
509
+ React__namespace.useEffect(() => {
510
+ setPluginRef.current(pluginId);
511
+ }, []);
512
+ return null;
513
+ };
514
+ const LocalePicker = () => {
515
+ const { formatMessage } = reactIntl.useIntl();
516
+ const [{ query }, setQuery] = strapiAdmin.useQueryParams();
517
+ const { hasI18n, canRead, canCreate } = useI18n();
518
+ const { data: locales = [] } = useGetLocalesQuery(void 0, {
519
+ skip: !hasI18n
520
+ });
521
+ const handleChange = React__namespace.useCallback(
522
+ (code, replace = false) => {
523
+ setQuery(
524
+ {
525
+ page: 1,
526
+ plugins: { ...query.plugins, i18n: { locale: code } }
527
+ },
528
+ "push",
529
+ replace
530
+ );
531
+ },
532
+ [query.plugins, setQuery]
533
+ );
534
+ React__namespace.useEffect(() => {
535
+ if (!Array.isArray(locales) || !hasI18n) {
536
+ return;
537
+ }
538
+ const currentDesiredLocale = query.plugins?.i18n?.locale;
539
+ const doesLocaleExist = locales.find((loc) => loc.code === currentDesiredLocale);
540
+ const defaultLocale = locales.find((locale) => locale.isDefault);
541
+ if (!doesLocaleExist && defaultLocale?.code) {
542
+ handleChange(defaultLocale.code, true);
543
+ }
544
+ }, [hasI18n, handleChange, locales, query.plugins?.i18n?.locale]);
545
+ if (!hasI18n || !Array.isArray(locales) || locales.length === 0) {
546
+ return null;
547
+ }
548
+ const displayedLocales = locales.filter((locale) => {
549
+ return canCreate.includes(locale.code) || canRead.includes(locale.code);
550
+ });
551
+ return /* @__PURE__ */ jsxRuntime.jsx(
552
+ designSystem.SingleSelect,
553
+ {
554
+ size: "S",
555
+ "aria-label": formatMessage({
556
+ id: getTranslation("actions.select-locale"),
557
+ defaultMessage: "Select locale"
558
+ }),
559
+ value: query.plugins?.i18n?.locale || locales.find((locale) => locale.isDefault)?.code,
560
+ onChange: handleChange,
561
+ children: displayedLocales.map((locale) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: locale.code, children: locale.name }, locale.id))
562
+ }
563
+ );
564
+ };
565
+ const PERMISSIONS = {
566
+ accessMain: [{ action: "plugin::i18n.locale.read", subject: null }],
567
+ create: [{ action: "plugin::i18n.locale.create", subject: null }],
568
+ delete: [{ action: "plugin::i18n.locale.delete", subject: null }],
569
+ update: [{ action: "plugin::i18n.locale.update", subject: null }],
570
+ read: [{ action: "plugin::i18n.locale.read", subject: null }]
571
+ };
572
+ const mutateEditViewHook = ({ layout }) => {
573
+ if ("i18n" in layout.options && typeof layout.options.i18n === "object" && layout.options.i18n !== null && "localized" in layout.options.i18n && !layout.options.i18n.localized) {
574
+ return { layout };
575
+ }
576
+ const components = Object.entries(layout.components).reduce(
577
+ (acc, [key, componentLayout]) => {
578
+ return {
579
+ ...acc,
580
+ [key]: {
581
+ ...componentLayout,
582
+ layout: componentLayout.layout.map((row) => row.map(addLabelActionToField))
583
+ }
584
+ };
585
+ },
586
+ {}
587
+ );
588
+ return {
589
+ layout: {
590
+ ...layout,
591
+ components,
592
+ layout: layout.layout.map((panel) => panel.map((row) => row.map(addLabelActionToField)))
593
+ }
594
+ };
595
+ };
596
+ const addLabelActionToField = (field) => {
597
+ const isFieldLocalized = doesFieldHaveI18nPluginOpt(field.attribute.pluginOptions) ? field.attribute.pluginOptions.i18n.localized : true;
598
+ const labelActionProps = {
599
+ title: {
600
+ id: isFieldLocalized ? getTranslation("Field.localized") : getTranslation("Field.not-localized"),
601
+ defaultMessage: isFieldLocalized ? "This value is unique for the selected locale" : "This value is the same across all locales"
602
+ },
603
+ icon: isFieldLocalized ? /* @__PURE__ */ jsxRuntime.jsx(icons.Earth, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.EarthStriked, {})
604
+ };
605
+ return {
606
+ ...field,
607
+ labelAction: /* @__PURE__ */ jsxRuntime.jsx(LabelAction, { ...labelActionProps })
608
+ };
609
+ };
610
+ const doesFieldHaveI18nPluginOpt = (pluginOpts) => {
611
+ if (!pluginOpts) {
612
+ return false;
613
+ }
614
+ return "i18n" in pluginOpts && typeof pluginOpts.i18n === "object" && pluginOpts.i18n !== null && "localized" in pluginOpts.i18n;
615
+ };
616
+ const LabelAction = ({ title, icon }) => {
617
+ const { formatMessage } = reactIntl.useIntl();
618
+ return /* @__PURE__ */ jsxRuntime.jsxs(Span, { tag: "span", children: [
619
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { tag: "span", children: `(${formatMessage(title)})` }),
620
+ React__namespace.cloneElement(icon, {
621
+ "aria-hidden": true,
622
+ focusable: false
623
+ // See: https://allyjs.io/tutorials/focusing-in-svg.html#making-svg-elements-focusable
624
+ })
625
+ ] });
626
+ };
627
+ const Span = styledComponents.styled(designSystem.Flex)`
628
+ svg {
629
+ width: 12px;
630
+ height: 12px;
631
+
632
+ fill: ${({ theme }) => theme.colors.neutral500};
633
+
634
+ path {
635
+ fill: ${({ theme }) => theme.colors.neutral500};
636
+ }
637
+ }
638
+ `;
639
+ const LocaleListCell = ({
640
+ documentId,
641
+ locale: currentLocale,
642
+ collectionType,
643
+ model
644
+ }) => {
645
+ const { meta, isLoading } = strapiAdmin$1.unstable_useDocument({
646
+ documentId,
647
+ collectionType,
648
+ model,
649
+ params: {
650
+ locale: currentLocale
651
+ }
652
+ });
653
+ const { locale: language } = reactIntl.useIntl();
654
+ const [visible, setVisible] = React__namespace.useState(false);
655
+ const buttonRef = React__namespace.useRef(null);
656
+ const { data: locales = [] } = useGetLocalesQuery();
657
+ const handleTogglePopover = (e) => {
658
+ e.stopPropagation();
659
+ setVisible((prev) => !prev);
660
+ };
661
+ const formatter = designSystem.useCollator(language, {
662
+ sensitivity: "base"
663
+ });
664
+ if (!Array.isArray(locales) || isLoading) {
665
+ return null;
666
+ }
667
+ const availableLocales = meta?.availableLocales.map((doc) => doc.locale) ?? [];
668
+ const localesForDocument = locales.reduce((acc, locale) => {
669
+ const createdLocale = [currentLocale, ...availableLocales].find((loc) => {
670
+ return loc === locale.code;
671
+ });
672
+ if (createdLocale) {
673
+ acc.push(locale);
674
+ }
675
+ return acc;
676
+ }, []).map((locale) => {
677
+ if (locale.isDefault) {
678
+ return `${locale.name} (default)`;
679
+ }
680
+ return locale.name;
681
+ }).toSorted((a, b) => formatter.compare(a, b));
682
+ return /* @__PURE__ */ jsxRuntime.jsxs(Button, { type: "button", onClick: handleTogglePopover, ref: buttonRef, children: [
683
+ /* @__PURE__ */ jsxRuntime.jsxs(
684
+ ActionWrapper,
685
+ {
686
+ minWidth: "100%",
687
+ alignItems: "center",
688
+ justifyContent: "center",
689
+ height: "3.2rem",
690
+ width: "3.2rem",
691
+ children: [
692
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", ellipsis: true, children: localesForDocument.join(", ") }),
693
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { children: /* @__PURE__ */ jsxRuntime.jsx(icons.CaretDown, {}) })
694
+ ]
695
+ }
696
+ ),
697
+ visible && /* @__PURE__ */ jsxRuntime.jsx(
698
+ designSystem.Popover,
699
+ {
700
+ onDismiss: () => setVisible(false),
701
+ source: buttonRef,
702
+ spacing: 16,
703
+ centered: true,
704
+ 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)) })
705
+ }
706
+ )
707
+ ] });
708
+ };
709
+ const Button = styledComponents.styled.button`
710
+ width: 100%;
711
+
712
+ svg {
713
+ > g,
714
+ path {
715
+ fill: ${({ theme }) => theme.colors.neutral500};
716
+ }
717
+ }
718
+ &:hover {
719
+ svg {
720
+ > g,
721
+ path {
722
+ fill: ${({ theme }) => theme.colors.neutral600};
723
+ }
724
+ }
725
+ }
726
+ &:active {
727
+ svg {
728
+ > g,
729
+ path {
730
+ fill: ${({ theme }) => theme.colors.neutral400};
731
+ }
732
+ }
733
+ }
734
+ `;
735
+ const ActionWrapper = styledComponents.styled(designSystem.Flex)`
736
+ svg {
737
+ height: 0.4rem;
738
+ }
739
+ `;
740
+ const addColumnToTableHook = ({ displayedHeaders, layout }) => {
741
+ const { options } = layout;
742
+ const isFieldLocalized = doesPluginOptionsHaveI18nLocalized(options) ? options.i18n.localized : false;
743
+ if (!isFieldLocalized) {
744
+ return { displayedHeaders, layout };
745
+ }
746
+ return {
747
+ displayedHeaders: [
748
+ ...displayedHeaders,
749
+ {
750
+ attribute: { type: "string" },
751
+ label: {
752
+ id: getTranslation("list-view.table.header.label"),
753
+ defaultMessage: "Available in"
754
+ },
755
+ searchable: false,
756
+ sortable: false,
757
+ name: "locales",
758
+ // @ts-expect-error – ID is seen as number | string; this will change when we move the type over.
759
+ cellFormatter: (props, _header, meta) => /* @__PURE__ */ jsxRuntime.jsx(LocaleListCell, { ...props, ...meta })
760
+ }
761
+ ],
762
+ layout
763
+ };
764
+ };
765
+ const addLocaleToReleasesHook = ({ displayedHeaders = [] }) => {
766
+ return {
767
+ displayedHeaders: [
768
+ // TODO: Fix when migrating to v5
769
+ // ...displayedHeaders,
770
+ {
771
+ key: "__locale__",
772
+ fieldSchema: { type: "string" },
773
+ metadatas: {
774
+ label: {
775
+ id: "content-releases.page.ReleaseDetails.table.header.label.locale",
776
+ defaultMessage: "locale"
777
+ },
778
+ searchable: false,
779
+ sortable: false
780
+ },
781
+ name: "locale"
782
+ }
783
+ ],
784
+ hasI18nEnabled: true
785
+ };
786
+ };
787
+ const extendCTBAttributeInitialDataMiddleware = () => {
788
+ return ({ getState }) => (next) => (action) => {
789
+ const enhanceAction = () => {
790
+ try {
791
+ const store = getState();
792
+ const hasi18nEnabled = get__default.default(
793
+ store,
794
+ [
795
+ "content-type-builder_dataManagerProvider",
796
+ "modifiedData",
797
+ "contentType",
798
+ "schema",
799
+ "pluginOptions",
800
+ "i18n",
801
+ "localized"
802
+ ],
803
+ false
804
+ );
805
+ if (hasi18nEnabled) {
806
+ const pluginOptions = action.options ? { ...action.options.pluginOptions, i18n: { localized: true } } : { i18n: { localized: true } };
807
+ return next({
808
+ ...action,
809
+ options: {
810
+ pluginOptions
811
+ }
812
+ });
813
+ }
814
+ return next(action);
815
+ } catch (err) {
816
+ return next(action);
817
+ }
818
+ };
819
+ if (action.type === "ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA" && action.forTarget === "contentType" && !["relation", "component"].includes(action.attributeType) && !action.isEditing) {
820
+ return enhanceAction();
821
+ }
822
+ if (action.type === "ContentTypeBuilder/FormModal/SET_CUSTOM_FIELD_DATA_SCHEMA" && action.forTarget === "contentType" && !action.isEditing) {
823
+ return enhanceAction();
824
+ }
825
+ 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") {
826
+ return enhanceAction();
827
+ }
828
+ return next(action);
829
+ };
830
+ };
831
+ const extendCTBInitialDataMiddleware = () => {
832
+ return () => (next) => (action) => {
833
+ if (action.type === "ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT" && action.modalType === "contentType") {
834
+ const i18n = { localized: false };
835
+ const pluginOptions = action.data.pluginOptions ? { ...action.data.pluginOptions, i18n } : { i18n };
836
+ const data = { ...action.data, pluginOptions };
837
+ if (action.actionType === "create") {
838
+ return next({ ...action, data });
839
+ }
840
+ if (!action.data.pluginOptions?.i18n?.localized) {
841
+ return next({ ...action, data });
842
+ }
843
+ }
844
+ return next(action);
845
+ };
846
+ };
847
+ const localeMiddleware = (ctx) => (next) => (permissions) => {
848
+ const match = reactRouterDom.matchPath("/content-manager/:collectionType/:model?/:id", ctx.pathname);
849
+ if (!match) {
850
+ return next(permissions);
851
+ }
852
+ const search = qs__namespace.parse(ctx.search);
853
+ if (typeof search !== "object") {
854
+ return next(permissions);
855
+ }
856
+ if (!("plugins" in search && typeof search.plugins === "object")) {
857
+ return next(permissions);
858
+ }
859
+ if (!("i18n" in search.plugins && typeof search.plugins.i18n === "object" && !Array.isArray(search.plugins.i18n))) {
860
+ return next(permissions);
861
+ }
862
+ const { locale } = search.plugins.i18n;
863
+ if (typeof locale !== "string") {
864
+ return next(permissions);
865
+ }
866
+ const revisedPermissions = permissions.filter(
867
+ (permission) => !permission.properties?.locales || permission.properties.locales.includes(locale)
868
+ );
869
+ return next(revisedPermissions);
870
+ };
871
+ const prefixPluginTranslations = (trad, pluginId2) => {
872
+ if (!pluginId2) {
873
+ throw new TypeError("pluginId can't be empty");
874
+ }
875
+ return Object.keys(trad).reduce((acc, current) => {
876
+ acc[`${pluginId2}.${current}`] = trad[current];
877
+ return acc;
878
+ }, {});
879
+ };
880
+ const mutateCTBContentTypeSchema = (nextSchema, prevSchema) => {
881
+ if (!doesPluginOptionsHaveI18nLocalized(nextSchema.pluginOptions)) {
882
+ return nextSchema;
883
+ }
884
+ const isNextSchemaLocalized = nextSchema.pluginOptions.i18n.localized;
885
+ const isPrevSchemaLocalized = doesPluginOptionsHaveI18nLocalized(
886
+ prevSchema?.schema?.pluginOptions
887
+ ) ? prevSchema?.schema?.pluginOptions.i18n.localized : false;
888
+ if (isNextSchemaLocalized && isPrevSchemaLocalized) {
889
+ return nextSchema;
890
+ }
891
+ if (isNextSchemaLocalized) {
892
+ const attributes = addLocalisationToFields(nextSchema.attributes);
893
+ return { ...nextSchema, attributes };
894
+ }
895
+ if (!isNextSchemaLocalized) {
896
+ const pluginOptions = omit__default.default(nextSchema.pluginOptions, "i18n");
897
+ const attributes = disableAttributesLocalisation(nextSchema.attributes);
898
+ return { ...nextSchema, pluginOptions, attributes };
899
+ }
900
+ return nextSchema;
901
+ };
902
+ const addLocalisationToFields = (attributes) => Object.keys(attributes).reduce((acc, current) => {
903
+ const currentAttribute = attributes[current];
904
+ if (LOCALIZED_FIELDS.includes(currentAttribute.type)) {
905
+ const i18n = { localized: true };
906
+ const pluginOptions = currentAttribute.pluginOptions ? { ...currentAttribute.pluginOptions, i18n } : { i18n };
907
+ acc[current] = { ...currentAttribute, pluginOptions };
908
+ return acc;
909
+ }
910
+ acc[current] = currentAttribute;
911
+ return acc;
912
+ }, {});
913
+ const disableAttributesLocalisation = (attributes) => Object.keys(attributes).reduce((acc, current) => {
914
+ acc[current] = omit__default.default(attributes[current], "pluginOptions.i18n");
915
+ return acc;
916
+ }, {});
917
+ const index = {
918
+ register(app) {
919
+ app.addMiddlewares([extendCTBAttributeInitialDataMiddleware, extendCTBInitialDataMiddleware]);
920
+ app.addMiddlewares([() => i18nApi.middleware]);
921
+ app.addReducers({
922
+ [i18nApi.reducerPath]: i18nApi.reducer
923
+ });
924
+ app.addRBACMiddleware([localeMiddleware]);
925
+ app.registerPlugin({
926
+ id: pluginId,
927
+ initializer: Initializer,
928
+ isReady: false,
929
+ name: pluginId
930
+ });
931
+ },
932
+ bootstrap(app) {
933
+ app.registerHook("Admin/CM/pages/ListView/inject-column-in-table", addColumnToTableHook);
934
+ app.registerHook("Admin/CM/pages/EditView/mutate-edit-view-layout", mutateEditViewHook);
935
+ app.registerHook(
936
+ "ContentReleases/pages/ReleaseDetails/add-locale-in-releases",
937
+ addLocaleToReleasesHook
938
+ );
939
+ app.addSettingsLink("global", {
940
+ intlLabel: {
941
+ id: getTranslation("plugin.name"),
942
+ defaultMessage: "Internationalization"
943
+ },
944
+ id: "internationalization",
945
+ to: "internationalization",
946
+ Component: () => Promise.resolve().then(() => require("./SettingsPage-BvzzUueI.js")).then((mod) => ({ default: mod.ProtectedSettingsPage })),
947
+ permissions: PERMISSIONS.accessMain
948
+ });
949
+ const contentManager = app.getPlugin("content-manager");
950
+ contentManager.apis.addDocumentHeaderAction([LocalePickerAction]);
951
+ contentManager.apis.addDocumentAction((actions) => {
952
+ const indexOfDeleteAction = actions.findIndex((action) => action.type === "delete");
953
+ actions.splice(indexOfDeleteAction, 0, DeleteLocaleAction);
954
+ return actions;
955
+ });
956
+ contentManager.injectComponent("listView", "actions", {
957
+ name: "i18n-locale-filter",
958
+ Component: LocalePicker
959
+ });
960
+ contentManager.injectComponent("listView", "publishModalAdditionalInfos", {
961
+ name: "i18n-publish-bullets-in-modal",
962
+ Component: PublishModalAdditionalInfo
963
+ });
964
+ contentManager.injectComponent("listView", "unpublishModalAdditionalInfos", {
965
+ name: "i18n-unpublish-bullets-in-modal",
966
+ Component: UnpublishModalAdditionalInfo
967
+ });
968
+ contentManager.injectComponent("listView", "deleteModalAdditionalInfos", {
969
+ name: "i18n-delete-bullets-in-modal",
970
+ Component: DeleteModalAdditionalInfo
971
+ });
972
+ const ctbPlugin = app.getPlugin("content-type-builder");
973
+ if (ctbPlugin) {
974
+ const ctbFormsAPI = ctbPlugin.apis.forms;
975
+ ctbFormsAPI.addContentTypeSchemaMutation(mutateCTBContentTypeSchema);
976
+ ctbFormsAPI.components.add({ id: "checkboxConfirmation", component: CheckboxConfirmation });
977
+ ctbFormsAPI.extendContentType({
978
+ validator: () => ({
979
+ i18n: yup__namespace.object().shape({
980
+ localized: yup__namespace.bool()
981
+ })
982
+ }),
983
+ form: {
984
+ advanced() {
985
+ return [
986
+ {
987
+ name: "pluginOptions.i18n.localized",
988
+ description: {
989
+ id: getTranslation("plugin.schema.i18n.localized.description-content-type"),
990
+ defaultMessage: "Allows translating an entry into different languages"
991
+ },
992
+ type: "checkboxConfirmation",
993
+ intlLabel: {
994
+ id: getTranslation("plugin.schema.i18n.localized.label-content-type"),
995
+ defaultMessage: "Localization"
996
+ }
997
+ }
998
+ ];
999
+ }
1000
+ }
1001
+ });
1002
+ ctbFormsAPI.extendFields(LOCALIZED_FIELDS, {
1003
+ validator: (args) => ({
1004
+ i18n: yup__namespace.object().shape({
1005
+ localized: yup__namespace.bool().test({
1006
+ name: "ensure-unique-localization",
1007
+ message: getTranslation("plugin.schema.i18n.ensure-unique-localization"),
1008
+ test(value) {
1009
+ if (value === void 0 || value) {
1010
+ return true;
1011
+ }
1012
+ const unique = get__default.default(args, ["3", "modifiedData", "unique"], null);
1013
+ if (unique && !value) {
1014
+ return false;
1015
+ }
1016
+ return true;
1017
+ }
1018
+ })
1019
+ })
1020
+ }),
1021
+ form: {
1022
+ advanced({ contentTypeSchema, forTarget, type, step }) {
1023
+ if (forTarget !== "contentType") {
1024
+ return [];
1025
+ }
1026
+ const hasI18nEnabled = get__default.default(
1027
+ contentTypeSchema,
1028
+ ["schema", "pluginOptions", "i18n", "localized"],
1029
+ false
1030
+ );
1031
+ if (!hasI18nEnabled) {
1032
+ return [];
1033
+ }
1034
+ if (type === "component" && step === "1") {
1035
+ return [];
1036
+ }
1037
+ return [
1038
+ {
1039
+ name: "pluginOptions.i18n.localized",
1040
+ description: {
1041
+ id: getTranslation("plugin.schema.i18n.localized.description-field"),
1042
+ defaultMessage: "The field can have different values in each locale"
1043
+ },
1044
+ type: "checkbox",
1045
+ intlLabel: {
1046
+ id: getTranslation("plugin.schema.i18n.localized.label-field"),
1047
+ defaultMessage: "Enable localization for this field"
1048
+ }
1049
+ }
1050
+ ];
1051
+ }
1052
+ }
1053
+ });
1054
+ }
1055
+ },
1056
+ async registerTrads({ locales }) {
1057
+ const importedTrads = await Promise.all(
1058
+ locales.map((locale) => {
1059
+ 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-BuBc6LKZ.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 }) => {
1060
+ return {
1061
+ data: prefixPluginTranslations(data, pluginId),
1062
+ locale
1063
+ };
1064
+ }).catch(() => {
1065
+ return {
1066
+ data: {},
1067
+ locale
1068
+ };
1069
+ });
1070
+ })
1071
+ );
1072
+ return Promise.resolve(importedTrads);
1073
+ }
1074
+ };
1075
+ exports.PERMISSIONS = PERMISSIONS;
1076
+ exports.getTranslation = getTranslation;
1077
+ exports.index = index;
1078
+ exports.isBaseQueryError = isBaseQueryError;
1079
+ exports.useCreateLocaleMutation = useCreateLocaleMutation;
1080
+ exports.useDeleteLocaleMutation = useDeleteLocaleMutation;
1081
+ exports.useGetDefaultLocalesQuery = useGetDefaultLocalesQuery;
1082
+ exports.useGetLocalesQuery = useGetLocalesQuery;
1083
+ exports.useUpdateLocaleMutation = useUpdateLocaleMutation;
1084
+ //# sourceMappingURL=index-DRjoX_5r.js.map