@strapi/i18n 0.0.0-experimental.a65a85fdea97faae8679d3ffc5f9d79af61abd26 → 0.0.0

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