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