@strapi/i18n 0.0.0-experimental.17b4116f461a49b8ce5386f7c8d79c511d40fb3b
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/LICENSE +22 -0
- package/README.md +17 -0
- package/dist/_chunks/SettingsPage-CeqfDjsb.mjs +565 -0
- package/dist/_chunks/SettingsPage-CeqfDjsb.mjs.map +1 -0
- package/dist/_chunks/SettingsPage-Djqsdrzs.js +585 -0
- package/dist/_chunks/SettingsPage-Djqsdrzs.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-BuBc6LKZ.js +69 -0
- package/dist/_chunks/en-BuBc6LKZ.js.map +1 -0
- package/dist/_chunks/en-CnrTsjWS.mjs +69 -0
- package/dist/_chunks/en-CnrTsjWS.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-BDU1w_fd.mjs +1058 -0
- package/dist/_chunks/index-BDU1w_fd.mjs.map +1 -0
- package/dist/_chunks/index-DMXJeGjN.js +1082 -0
- package/dist/_chunks/index-DMXJeGjN.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/CMHeaderActions.d.ts +4 -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 +13 -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 +36 -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 +3 -0
- package/dist/admin/src/services/locales.d.ts +4 -0
- package/dist/admin/src/types.d.ts +9 -0
- package/dist/admin/src/utils/baseQuery.d.ts +20 -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 +27 -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 +101 -0
- package/strapi-server.js +3 -0
package/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015-present Strapi Solutions SAS
|
2
|
+
|
3
|
+
Portions of the Strapi software are licensed as follows:
|
4
|
+
|
5
|
+
* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE".
|
6
|
+
|
7
|
+
* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below.
|
8
|
+
|
9
|
+
MIT Expat License
|
10
|
+
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
13
|
+
in the Software without restriction, including without limitation the rights
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
16
|
+
furnished to do so, subject to the following conditions:
|
17
|
+
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
19
|
+
copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Strapi plugin i18n
|
2
|
+
|
3
|
+
The Internationalization (i18n) plugin allows Strapi users to create, manage and distribute localized content in different languages, called "locales". For more information about the concept of internationalization, please refer to the [W3C definition](https://www.w3.org/International/questions/qa-i18n.en#i18n).
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- Admin panel users can create several localized versions of their content
|
8
|
+
- Developers can build localized projects by fetching and consuming the right content depending on the country/language of the audience
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
This plugin is pre-installed & required with strapi
|
13
|
+
|
14
|
+
## Documentation
|
15
|
+
|
16
|
+
- [Developer documentation](https://docs.strapi.io/developer-docs/latest/plugins/i18n.html#installation)
|
17
|
+
- [User documentation](https://docs.strapi.io/user-docs/latest/content-manager/translating-content.html)
|
@@ -0,0 +1,565 @@
|
|
1
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
2
|
+
import * as React from "react";
|
3
|
+
import { useNotification, useAPIErrorHandler, useAuth, Form, useForm, InputRenderer, useField, ConfirmDialog, useRBAC, Page, Layouts } from "@strapi/admin/strapi-admin";
|
4
|
+
import { Button, ModalLayout, ModalHeader, Typography, ModalBody, TabGroup, Flex, Tabs, Tab, Divider, Box, TabPanels, TabPanel, ModalFooter, Grid, GridItem, SingleSelect, SingleSelectOption, IconButton, Table, Thead, Tr, Th, VisuallyHidden, Tbody, Td, EmptyStateLayout } from "@strapi/design-system";
|
5
|
+
import { EmptyDocuments } from "@strapi/icons/symbols";
|
6
|
+
import { useIntl } from "react-intl";
|
7
|
+
import { Plus, Check, Trash, Pencil } from "@strapi/icons";
|
8
|
+
import * as yup from "yup";
|
9
|
+
import { g as getTranslation, u as useCreateLocaleMutation, a as useGetDefaultLocalesQuery, b as useGetLocalesQuery, i as isBaseQueryError, c as useDeleteLocaleMutation, d as useUpdateLocaleMutation, P as PERMISSIONS } from "./index-BDU1w_fd.mjs";
|
10
|
+
const CreateLocale = ({ disabled, variant = "default" }) => {
|
11
|
+
const { formatMessage } = useIntl();
|
12
|
+
const [visible, setVisible] = React.useState(false);
|
13
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
14
|
+
/* @__PURE__ */ jsx(
|
15
|
+
Button,
|
16
|
+
{
|
17
|
+
variant,
|
18
|
+
disabled,
|
19
|
+
startIcon: /* @__PURE__ */ jsx(Plus, {}),
|
20
|
+
onClick: () => setVisible(true),
|
21
|
+
size: "S",
|
22
|
+
children: formatMessage({
|
23
|
+
id: getTranslation("Settings.list.actions.add"),
|
24
|
+
defaultMessage: "Add new locale"
|
25
|
+
})
|
26
|
+
}
|
27
|
+
),
|
28
|
+
visible ? /* @__PURE__ */ jsx(CreateModal, { onClose: () => setVisible(false) }) : null
|
29
|
+
] });
|
30
|
+
};
|
31
|
+
const LOCALE_SCHEMA = yup.object().shape({
|
32
|
+
code: yup.string().required({
|
33
|
+
id: "Settings.locales.modal.create.code.error",
|
34
|
+
defaultMessage: "Please select a locale"
|
35
|
+
}),
|
36
|
+
name: yup.string().max(50, {
|
37
|
+
id: "Settings.locales.modal.create.name.error.min",
|
38
|
+
defaultMessage: "The locale display name can only be less than 50 characters."
|
39
|
+
}).required({
|
40
|
+
id: "Settings.locales.modal.create.name.error.required",
|
41
|
+
defaultMessage: "Please give the locale a display name"
|
42
|
+
}),
|
43
|
+
isDefault: yup.boolean()
|
44
|
+
});
|
45
|
+
const initialFormValues = {
|
46
|
+
code: "",
|
47
|
+
name: "",
|
48
|
+
isDefault: false
|
49
|
+
};
|
50
|
+
const CreateModal = ({ onClose }) => {
|
51
|
+
const { toggleNotification } = useNotification();
|
52
|
+
const {
|
53
|
+
_unstableFormatAPIError: formatAPIError,
|
54
|
+
_unstableFormatValidationErrors: formatValidationErrors
|
55
|
+
} = useAPIErrorHandler();
|
56
|
+
const [createLocale] = useCreateLocaleMutation();
|
57
|
+
const { formatMessage } = useIntl();
|
58
|
+
const refetchPermissions = useAuth("CreateModal", (state) => state.refetchPermissions);
|
59
|
+
const handleSubmit = async (values, helpers) => {
|
60
|
+
try {
|
61
|
+
const res = await createLocale(values);
|
62
|
+
if ("error" in res) {
|
63
|
+
if (isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
64
|
+
helpers.setErrors(formatValidationErrors(res.error));
|
65
|
+
} else {
|
66
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
67
|
+
}
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
toggleNotification({
|
71
|
+
type: "success",
|
72
|
+
message: formatMessage({
|
73
|
+
id: getTranslation("Settings.locales.modal.create.success"),
|
74
|
+
defaultMessage: "Created locale"
|
75
|
+
})
|
76
|
+
});
|
77
|
+
refetchPermissions();
|
78
|
+
onClose();
|
79
|
+
} catch (err) {
|
80
|
+
toggleNotification({
|
81
|
+
type: "danger",
|
82
|
+
message: formatMessage({
|
83
|
+
id: "notification.error",
|
84
|
+
defaultMessage: "An error occurred, please try again"
|
85
|
+
})
|
86
|
+
});
|
87
|
+
}
|
88
|
+
};
|
89
|
+
const titleId = React.useId();
|
90
|
+
return /* @__PURE__ */ jsx(ModalLayout, { onClose, labelledBy: titleId, children: /* @__PURE__ */ jsxs(
|
91
|
+
Form,
|
92
|
+
{
|
93
|
+
method: "POST",
|
94
|
+
initialValues: initialFormValues,
|
95
|
+
validationSchema: LOCALE_SCHEMA,
|
96
|
+
onSubmit: handleSubmit,
|
97
|
+
children: [
|
98
|
+
/* @__PURE__ */ jsx(ModalHeader, { children: /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", textColor: "neutral800", as: "h2", id: titleId, children: formatMessage({
|
99
|
+
id: getTranslation("Settings.list.actions.add"),
|
100
|
+
defaultMessage: "Add new locale"
|
101
|
+
}) }) }),
|
102
|
+
/* @__PURE__ */ jsx(ModalBody, { children: /* @__PURE__ */ jsxs(
|
103
|
+
TabGroup,
|
104
|
+
{
|
105
|
+
label: formatMessage({
|
106
|
+
id: getTranslation("Settings.locales.modal.title"),
|
107
|
+
defaultMessage: "Configurations"
|
108
|
+
}),
|
109
|
+
variant: "simple",
|
110
|
+
children: [
|
111
|
+
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", children: [
|
112
|
+
/* @__PURE__ */ jsx(Typography, { as: "h2", variant: "beta", children: formatMessage({
|
113
|
+
id: getTranslation("Settings.locales.modal.title"),
|
114
|
+
defaultMessage: "Configuration"
|
115
|
+
}) }),
|
116
|
+
/* @__PURE__ */ jsxs(Tabs, { children: [
|
117
|
+
/* @__PURE__ */ jsx(Tab, { children: formatMessage({
|
118
|
+
id: getTranslation("Settings.locales.modal.base"),
|
119
|
+
defaultMessage: "Basic settings"
|
120
|
+
}) }),
|
121
|
+
/* @__PURE__ */ jsx(Tab, { children: formatMessage({
|
122
|
+
id: getTranslation("Settings.locales.modal.advanced"),
|
123
|
+
defaultMessage: "Advanced settings"
|
124
|
+
}) })
|
125
|
+
] })
|
126
|
+
] }),
|
127
|
+
/* @__PURE__ */ jsx(Divider, {}),
|
128
|
+
/* @__PURE__ */ jsx(Box, { paddingTop: 7, paddingBottom: 7, children: /* @__PURE__ */ jsxs(TabPanels, { children: [
|
129
|
+
/* @__PURE__ */ jsx(TabPanel, { children: /* @__PURE__ */ jsx(BaseForm, {}) }),
|
130
|
+
/* @__PURE__ */ jsx(TabPanel, { children: /* @__PURE__ */ jsx(AdvancedForm, {}) })
|
131
|
+
] }) })
|
132
|
+
]
|
133
|
+
}
|
134
|
+
) }),
|
135
|
+
/* @__PURE__ */ jsx(
|
136
|
+
ModalFooter,
|
137
|
+
{
|
138
|
+
startActions: /* @__PURE__ */ jsx(Button, { variant: "tertiary", onClick: onClose, children: formatMessage({ id: "app.components.Button.cancel", defaultMessage: "Cancel" }) }),
|
139
|
+
endActions: /* @__PURE__ */ jsx(SubmitButton, {})
|
140
|
+
}
|
141
|
+
)
|
142
|
+
]
|
143
|
+
}
|
144
|
+
) });
|
145
|
+
};
|
146
|
+
const SubmitButton = () => {
|
147
|
+
const { formatMessage } = useIntl();
|
148
|
+
const isSubmitting = useForm("SubmitButton", (state) => state.isSubmitting);
|
149
|
+
const modified = useForm("SubmitButton", (state) => state.modified);
|
150
|
+
return /* @__PURE__ */ jsx(Button, { type: "submit", startIcon: /* @__PURE__ */ jsx(Check, {}), disabled: isSubmitting || !modified, children: formatMessage({ id: "global.save", defaultMessage: "Save" }) });
|
151
|
+
};
|
152
|
+
const BaseForm = ({ mode = "create" }) => {
|
153
|
+
const { formatMessage } = useIntl();
|
154
|
+
const { toggleNotification } = useNotification();
|
155
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
156
|
+
const { data: defaultLocales = [], error } = useGetDefaultLocalesQuery();
|
157
|
+
const { data: locales = [] } = useGetLocalesQuery();
|
158
|
+
React.useEffect(() => {
|
159
|
+
if (error) {
|
160
|
+
toggleNotification({
|
161
|
+
type: "danger",
|
162
|
+
message: formatAPIError(error)
|
163
|
+
});
|
164
|
+
}
|
165
|
+
}, [error, formatAPIError, toggleNotification]);
|
166
|
+
if (!Array.isArray(defaultLocales) || !Array.isArray(locales)) {
|
167
|
+
return null;
|
168
|
+
}
|
169
|
+
const options = defaultLocales.map((locale) => ({
|
170
|
+
label: locale.name,
|
171
|
+
value: locale.code
|
172
|
+
}));
|
173
|
+
const translatedForm = [
|
174
|
+
{
|
175
|
+
disabled: mode !== "create",
|
176
|
+
label: {
|
177
|
+
id: getTranslation("Settings.locales.modal.create.code.label"),
|
178
|
+
defaultMessage: "Locales"
|
179
|
+
},
|
180
|
+
name: "code",
|
181
|
+
options,
|
182
|
+
placeholder: {
|
183
|
+
id: "components.placeholder.select",
|
184
|
+
defaultMessage: "Select"
|
185
|
+
},
|
186
|
+
required: true,
|
187
|
+
size: 6,
|
188
|
+
type: "enumeration"
|
189
|
+
},
|
190
|
+
{
|
191
|
+
hint: {
|
192
|
+
id: getTranslation("Settings.locales.modal.create.name.label.description"),
|
193
|
+
defaultMessage: "Locale will be displayed under that name in the administration panel"
|
194
|
+
},
|
195
|
+
label: {
|
196
|
+
id: getTranslation("Settings.locales.modal.create.name.label"),
|
197
|
+
defaultMessage: "Locale display name"
|
198
|
+
},
|
199
|
+
name: "name",
|
200
|
+
required: true,
|
201
|
+
size: 6,
|
202
|
+
type: "string"
|
203
|
+
}
|
204
|
+
].map((field) => ({
|
205
|
+
...field,
|
206
|
+
hint: field.hint ? formatMessage(field.hint) : void 0,
|
207
|
+
label: formatMessage(field.label),
|
208
|
+
placeholder: field.placeholder ? formatMessage(field.placeholder) : void 0
|
209
|
+
}));
|
210
|
+
return /* @__PURE__ */ jsx(Grid, { gap: 4, children: translatedForm.map(({ size, ...field }) => /* @__PURE__ */ jsx(GridItem, { col: size, children: /* @__PURE__ */ jsx(FormRenderer, { ...field }) }, field.name)) });
|
211
|
+
};
|
212
|
+
const AdvancedForm = ({ isDefaultLocale }) => {
|
213
|
+
const { formatMessage } = useIntl();
|
214
|
+
const form = [
|
215
|
+
{
|
216
|
+
disabled: isDefaultLocale,
|
217
|
+
hint: {
|
218
|
+
id: getTranslation("Settings.locales.modal.advanced.setAsDefault.hint"),
|
219
|
+
defaultMessage: "One default locale is required, change it by selecting another one"
|
220
|
+
},
|
221
|
+
label: {
|
222
|
+
id: getTranslation("Settings.locales.modal.advanced.setAsDefault"),
|
223
|
+
defaultMessage: "Set as default locale"
|
224
|
+
},
|
225
|
+
name: "isDefault",
|
226
|
+
size: 6,
|
227
|
+
type: "boolean"
|
228
|
+
}
|
229
|
+
].map((field) => ({
|
230
|
+
...field,
|
231
|
+
hint: field.hint ? formatMessage(field.hint) : void 0,
|
232
|
+
label: formatMessage(field.label)
|
233
|
+
}));
|
234
|
+
return /* @__PURE__ */ jsx(Grid, { gap: 4, children: form.map(({ size, ...field }) => /* @__PURE__ */ jsx(GridItem, { col: size, children: /* @__PURE__ */ jsx(FormRenderer, { ...field }) }, field.name)) });
|
235
|
+
};
|
236
|
+
const FormRenderer = (field) => {
|
237
|
+
switch (field.type) {
|
238
|
+
case "enumeration":
|
239
|
+
return /* @__PURE__ */ jsx(EnumerationInput, { ...field });
|
240
|
+
default:
|
241
|
+
return /* @__PURE__ */ jsx(InputRenderer, { ...field });
|
242
|
+
}
|
243
|
+
};
|
244
|
+
const EnumerationInput = ({
|
245
|
+
disabled,
|
246
|
+
hint,
|
247
|
+
label,
|
248
|
+
name,
|
249
|
+
options,
|
250
|
+
placeholder,
|
251
|
+
required
|
252
|
+
}) => {
|
253
|
+
const { value, error, onChange } = useField(name);
|
254
|
+
const { data: defaultLocales = [] } = useGetDefaultLocalesQuery();
|
255
|
+
const handleChange = (value2) => {
|
256
|
+
if (Array.isArray(defaultLocales)) {
|
257
|
+
const locale = defaultLocales.find((locale2) => locale2.code === value2);
|
258
|
+
onChange(name, value2);
|
259
|
+
onChange("name", locale.name);
|
260
|
+
} else {
|
261
|
+
onChange(name, value2);
|
262
|
+
}
|
263
|
+
};
|
264
|
+
return /* @__PURE__ */ jsx(
|
265
|
+
SingleSelect,
|
266
|
+
{
|
267
|
+
disabled,
|
268
|
+
error,
|
269
|
+
hint,
|
270
|
+
label,
|
271
|
+
name,
|
272
|
+
onChange: handleChange,
|
273
|
+
placeholder,
|
274
|
+
required,
|
275
|
+
value,
|
276
|
+
children: options.map((option) => /* @__PURE__ */ jsx(SingleSelectOption, { value: option.value, children: option.label }, option.value))
|
277
|
+
}
|
278
|
+
);
|
279
|
+
};
|
280
|
+
const DeleteLocale = ({ id, name }) => {
|
281
|
+
const { formatMessage } = useIntl();
|
282
|
+
const { toggleNotification } = useNotification();
|
283
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
284
|
+
const [visible, setVisible] = React.useState(false);
|
285
|
+
const [deleteLocale] = useDeleteLocaleMutation();
|
286
|
+
const handleConfirm = async () => {
|
287
|
+
try {
|
288
|
+
const res = await deleteLocale(id);
|
289
|
+
if ("error" in res) {
|
290
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
291
|
+
return;
|
292
|
+
}
|
293
|
+
toggleNotification({
|
294
|
+
type: "success",
|
295
|
+
message: formatMessage({
|
296
|
+
id: getTranslation("Settings.locales.modal.delete.success"),
|
297
|
+
defaultMessage: "Deleted locale"
|
298
|
+
})
|
299
|
+
});
|
300
|
+
} catch (err) {
|
301
|
+
toggleNotification({
|
302
|
+
type: "danger",
|
303
|
+
message: formatMessage({
|
304
|
+
id: "notification.error",
|
305
|
+
defaultMessage: "An error occurred, please try again"
|
306
|
+
})
|
307
|
+
});
|
308
|
+
}
|
309
|
+
};
|
310
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
311
|
+
/* @__PURE__ */ jsx(
|
312
|
+
IconButton,
|
313
|
+
{
|
314
|
+
onClick: () => setVisible(true),
|
315
|
+
label: formatMessage(
|
316
|
+
{
|
317
|
+
id: getTranslation("Settings.list.actions.delete"),
|
318
|
+
defaultMessage: "Delete {name} locale"
|
319
|
+
},
|
320
|
+
{
|
321
|
+
name
|
322
|
+
}
|
323
|
+
),
|
324
|
+
icon: /* @__PURE__ */ jsx(Trash, {}),
|
325
|
+
borderWidth: 0
|
326
|
+
}
|
327
|
+
),
|
328
|
+
/* @__PURE__ */ jsx(ConfirmDialog, { onConfirm: handleConfirm, onClose: () => setVisible(false), isOpen: visible })
|
329
|
+
] });
|
330
|
+
};
|
331
|
+
const EditLocale = (props) => {
|
332
|
+
const { formatMessage } = useIntl();
|
333
|
+
const [visible, setVisible] = React.useState(false);
|
334
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
335
|
+
/* @__PURE__ */ jsx(
|
336
|
+
IconButton,
|
337
|
+
{
|
338
|
+
onClick: () => setVisible(true),
|
339
|
+
label: formatMessage(
|
340
|
+
{
|
341
|
+
id: getTranslation("Settings.list.actions.edit"),
|
342
|
+
defaultMessage: "Edit {name} locale"
|
343
|
+
},
|
344
|
+
{
|
345
|
+
name: props.name
|
346
|
+
}
|
347
|
+
),
|
348
|
+
icon: /* @__PURE__ */ jsx(Pencil, {}),
|
349
|
+
borderWidth: 0
|
350
|
+
}
|
351
|
+
),
|
352
|
+
visible ? /* @__PURE__ */ jsx(EditModal, { ...props, onClose: () => setVisible(false) }) : null
|
353
|
+
] });
|
354
|
+
};
|
355
|
+
const EditModal = ({ id, code, isDefault, name, onClose }) => {
|
356
|
+
const { toggleNotification } = useNotification();
|
357
|
+
const {
|
358
|
+
_unstableFormatAPIError: formatAPIError,
|
359
|
+
_unstableFormatValidationErrors: formatValidationErrors
|
360
|
+
} = useAPIErrorHandler();
|
361
|
+
const refetchPermissions = useAuth("EditModal", (state) => state.refetchPermissions);
|
362
|
+
const { formatMessage } = useIntl();
|
363
|
+
const titleId = React.useId();
|
364
|
+
const [updateLocale] = useUpdateLocaleMutation();
|
365
|
+
const handleSubmit = async ({ code: _code, ...data }, helpers) => {
|
366
|
+
try {
|
367
|
+
const res = await updateLocale({
|
368
|
+
id,
|
369
|
+
...data
|
370
|
+
});
|
371
|
+
if ("error" in res) {
|
372
|
+
if (isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
373
|
+
helpers.setErrors(formatValidationErrors(res.error));
|
374
|
+
} else {
|
375
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
376
|
+
}
|
377
|
+
return;
|
378
|
+
}
|
379
|
+
toggleNotification({
|
380
|
+
type: "success",
|
381
|
+
message: formatMessage({
|
382
|
+
id: getTranslation("Settings.locales.modal.edit.success"),
|
383
|
+
defaultMessage: "Updated locale"
|
384
|
+
})
|
385
|
+
});
|
386
|
+
refetchPermissions();
|
387
|
+
onClose();
|
388
|
+
} catch (err) {
|
389
|
+
toggleNotification({
|
390
|
+
type: "danger",
|
391
|
+
message: formatMessage({
|
392
|
+
id: "notification.error",
|
393
|
+
defaultMessage: "An error occurred, please try again"
|
394
|
+
})
|
395
|
+
});
|
396
|
+
}
|
397
|
+
};
|
398
|
+
return /* @__PURE__ */ jsx(ModalLayout, { onClose, labelledBy: titleId, children: /* @__PURE__ */ jsxs(
|
399
|
+
Form,
|
400
|
+
{
|
401
|
+
method: "PUT",
|
402
|
+
onSubmit: handleSubmit,
|
403
|
+
initialValues: {
|
404
|
+
code,
|
405
|
+
name,
|
406
|
+
isDefault
|
407
|
+
},
|
408
|
+
validationSchema: LOCALE_SCHEMA,
|
409
|
+
children: [
|
410
|
+
/* @__PURE__ */ jsx(ModalHeader, { children: /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", textColor: "neutral800", as: "h2", id: titleId, children: formatMessage({
|
411
|
+
id: getTranslation("Settings.list.actions.edit"),
|
412
|
+
defaultMessage: "Edit a locale"
|
413
|
+
}) }) }),
|
414
|
+
/* @__PURE__ */ jsx(ModalBody, { children: /* @__PURE__ */ jsxs(
|
415
|
+
TabGroup,
|
416
|
+
{
|
417
|
+
label: formatMessage({
|
418
|
+
id: getTranslation("Settings.locales.modal.title"),
|
419
|
+
defaultMessage: "Configurations"
|
420
|
+
}),
|
421
|
+
variant: "simple",
|
422
|
+
children: [
|
423
|
+
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", children: [
|
424
|
+
/* @__PURE__ */ jsx(Typography, { as: "h2", variant: "beta", children: formatMessage({
|
425
|
+
id: getTranslation("Settings.locales.modal.title"),
|
426
|
+
defaultMessage: "Configuration"
|
427
|
+
}) }),
|
428
|
+
/* @__PURE__ */ jsxs(Tabs, { children: [
|
429
|
+
/* @__PURE__ */ jsx(Tab, { children: formatMessage({
|
430
|
+
id: getTranslation("Settings.locales.modal.base"),
|
431
|
+
defaultMessage: "Basic settings"
|
432
|
+
}) }),
|
433
|
+
/* @__PURE__ */ jsx(Tab, { children: formatMessage({
|
434
|
+
id: getTranslation("Settings.locales.modal.advanced"),
|
435
|
+
defaultMessage: "Advanced settings"
|
436
|
+
}) })
|
437
|
+
] })
|
438
|
+
] }),
|
439
|
+
/* @__PURE__ */ jsx(Divider, {}),
|
440
|
+
/* @__PURE__ */ jsx(Box, { paddingTop: 7, paddingBottom: 7, children: /* @__PURE__ */ jsxs(TabPanels, { children: [
|
441
|
+
/* @__PURE__ */ jsx(TabPanel, { children: /* @__PURE__ */ jsx(BaseForm, { mode: "edit" }) }),
|
442
|
+
/* @__PURE__ */ jsx(TabPanel, { children: /* @__PURE__ */ jsx(AdvancedForm, { isDefaultLocale: isDefault }) })
|
443
|
+
] }) })
|
444
|
+
]
|
445
|
+
}
|
446
|
+
) }),
|
447
|
+
/* @__PURE__ */ jsx(
|
448
|
+
ModalFooter,
|
449
|
+
{
|
450
|
+
startActions: /* @__PURE__ */ jsx(Button, { variant: "tertiary", onClick: onClose, children: formatMessage({ id: "app.components.Button.cancel", defaultMessage: "Cancel" }) }),
|
451
|
+
endActions: /* @__PURE__ */ jsx(SubmitButton, {})
|
452
|
+
}
|
453
|
+
)
|
454
|
+
]
|
455
|
+
}
|
456
|
+
) });
|
457
|
+
};
|
458
|
+
const LocaleTable = ({ locales = [], canDelete, canUpdate }) => {
|
459
|
+
const [editLocaleId, setEditLocaleId] = React.useState();
|
460
|
+
const { formatMessage } = useIntl();
|
461
|
+
const handleClick = (localeId) => () => {
|
462
|
+
if (canUpdate) {
|
463
|
+
setEditLocaleId(localeId);
|
464
|
+
}
|
465
|
+
};
|
466
|
+
return /* @__PURE__ */ jsxs(Table, { colCount: 4, rowCount: locales.length + 1, children: [
|
467
|
+
/* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
|
468
|
+
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
|
469
|
+
id: getTranslation("Settings.locales.row.id"),
|
470
|
+
defaultMessage: "ID"
|
471
|
+
}) }) }),
|
472
|
+
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
|
473
|
+
id: getTranslation("Settings.locales.row.displayName"),
|
474
|
+
defaultMessage: "Display name"
|
475
|
+
}) }) }),
|
476
|
+
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
|
477
|
+
id: getTranslation("Settings.locales.row.default-locale"),
|
478
|
+
defaultMessage: "Default locale"
|
479
|
+
}) }) }),
|
480
|
+
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(VisuallyHidden, { children: "Actions" }) })
|
481
|
+
] }) }),
|
482
|
+
/* @__PURE__ */ jsx(Tbody, { children: locales.map((locale) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
483
|
+
/* @__PURE__ */ jsxs(
|
484
|
+
Tr,
|
485
|
+
{
|
486
|
+
onClick: handleClick(locale.id),
|
487
|
+
style: { cursor: canUpdate ? "pointer" : "default" },
|
488
|
+
children: [
|
489
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: locale.id }) }),
|
490
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: locale.name }) }),
|
491
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: locale.isDefault ? formatMessage({
|
492
|
+
id: getTranslation("Settings.locales.default"),
|
493
|
+
defaultMessage: "Default"
|
494
|
+
}) : null }) }),
|
495
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Flex, { gap: 1, justifyContent: "flex-end", onClick: (e) => e.stopPropagation(), children: [
|
496
|
+
canUpdate && /* @__PURE__ */ jsx(EditLocale, { ...locale }),
|
497
|
+
canDelete && !locale.isDefault && /* @__PURE__ */ jsx(DeleteLocale, { ...locale })
|
498
|
+
] }) })
|
499
|
+
]
|
500
|
+
}
|
501
|
+
),
|
502
|
+
editLocaleId === locale.id ? /* @__PURE__ */ jsx(EditModal, { ...locale, onClose: () => setEditLocaleId(void 0) }) : null
|
503
|
+
] }, locale.id)) })
|
504
|
+
] });
|
505
|
+
};
|
506
|
+
const SettingsPage = () => {
|
507
|
+
const { formatMessage } = useIntl();
|
508
|
+
const { toggleNotification } = useNotification();
|
509
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
510
|
+
const { data: locales, isLoading: isLoadingLocales, error } = useGetLocalesQuery();
|
511
|
+
const {
|
512
|
+
isLoading: isLoadingRBAC,
|
513
|
+
allowedActions: { canUpdate, canCreate, canDelete }
|
514
|
+
} = useRBAC(PERMISSIONS);
|
515
|
+
React.useEffect(() => {
|
516
|
+
if (error) {
|
517
|
+
toggleNotification({
|
518
|
+
type: "danger",
|
519
|
+
message: formatAPIError(error)
|
520
|
+
});
|
521
|
+
}
|
522
|
+
}, [error, formatAPIError, toggleNotification]);
|
523
|
+
const isLoading = isLoadingLocales || isLoadingRBAC;
|
524
|
+
if (isLoading) {
|
525
|
+
return /* @__PURE__ */ jsx(Page.Loading, {});
|
526
|
+
}
|
527
|
+
if (error || !Array.isArray(locales)) {
|
528
|
+
return /* @__PURE__ */ jsx(Page.Error, {});
|
529
|
+
}
|
530
|
+
return /* @__PURE__ */ jsxs(Page.Main, { tabIndex: -1, children: [
|
531
|
+
/* @__PURE__ */ jsx(
|
532
|
+
Layouts.Header,
|
533
|
+
{
|
534
|
+
primaryAction: /* @__PURE__ */ jsx(CreateLocale, { disabled: !canCreate }),
|
535
|
+
title: formatMessage({
|
536
|
+
id: getTranslation("plugin.name"),
|
537
|
+
defaultMessage: "Internationalization"
|
538
|
+
}),
|
539
|
+
subtitle: formatMessage({
|
540
|
+
id: getTranslation("Settings.list.description"),
|
541
|
+
defaultMessage: "Configure the settings"
|
542
|
+
})
|
543
|
+
}
|
544
|
+
),
|
545
|
+
/* @__PURE__ */ jsx(Layouts.Content, { children: locales.length > 0 ? /* @__PURE__ */ jsx(LocaleTable, { locales, canDelete, canUpdate }) : /* @__PURE__ */ jsx(
|
546
|
+
EmptyStateLayout,
|
547
|
+
{
|
548
|
+
icon: /* @__PURE__ */ jsx(EmptyDocuments, { width: void 0, height: void 0 }),
|
549
|
+
content: formatMessage({
|
550
|
+
id: getTranslation("Settings.list.empty.title"),
|
551
|
+
defaultMessage: "There are no locales"
|
552
|
+
}),
|
553
|
+
action: /* @__PURE__ */ jsx(CreateLocale, { disabled: !canCreate, variant: "secondary" })
|
554
|
+
}
|
555
|
+
) })
|
556
|
+
] });
|
557
|
+
};
|
558
|
+
const ProtectedSettingsPage = () => {
|
559
|
+
return /* @__PURE__ */ jsx(Page.Protect, { permissions: PERMISSIONS.read, children: /* @__PURE__ */ jsx(SettingsPage, {}) });
|
560
|
+
};
|
561
|
+
export {
|
562
|
+
ProtectedSettingsPage,
|
563
|
+
SettingsPage
|
564
|
+
};
|
565
|
+
//# sourceMappingURL=SettingsPage-CeqfDjsb.mjs.map
|