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