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