@strapi/i18n 0.0.0-experimental.0faf8967355707d2684ecb8579b03979ad5df042
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 +37 -0
- package/README.md +17 -0
- package/dist/_chunks/SettingsPage-DdW0J2We.mjs +554 -0
- package/dist/_chunks/SettingsPage-DdW0J2We.mjs.map +1 -0
- package/dist/_chunks/SettingsPage-P9JDTTir.js +574 -0
- package/dist/_chunks/SettingsPage-P9JDTTir.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-BYRZFDBV.mjs +81 -0
- package/dist/_chunks/en-BYRZFDBV.mjs.map +1 -0
- package/dist/_chunks/en-Dk9At9_Z.js +81 -0
- package/dist/_chunks/en-Dk9At9_Z.js.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-C6wPnwIO.mjs +1614 -0
- package/dist/_chunks/index-C6wPnwIO.mjs.map +1 -0
- package/dist/_chunks/index-CjsJhQ5j.js +1636 -0
- package/dist/_chunks/index-CjsJhQ5j.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 +16 -0
- package/dist/admin/src/components/CMHeaderActions.d.ts +36 -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/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/clean.d.ts +4 -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 +25 -0
- package/dist/admin/src/utils/strings.d.ts +2 -0
- package/dist/server/index.js +3432 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +3413 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/server/src/bootstrap.d.ts +3 -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 +150 -0
- package/dist/server/src/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/index.d.ts +75 -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 +28 -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 +40 -0
- package/dist/server/src/services/permissions.d.ts.map +1 -0
- package/dist/server/src/utils/index.d.ts +41 -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 +100 -0
package/LICENSE
ADDED
@@ -0,0 +1,37 @@
|
|
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 below.
|
6
|
+
|
7
|
+
Enterprise License
|
8
|
+
|
9
|
+
If you or the company you represent has entered into a written agreement referencing the Enterprise Edition of the Strapi source code available at
|
10
|
+
https://github.com/strapi/strapi, then such agreement applies to your use of the Enterprise Edition of the Strapi Software. If you or the company you
|
11
|
+
represent is using the Enterprise Edition of the Strapi Software in connection with a subscription to our cloud offering, then the agreement you have
|
12
|
+
agreed to with respect to our cloud offering and the licenses included in such agreement apply to your use of the Enterprise Edition of the Strapi Software.
|
13
|
+
Otherwise, the Strapi Enterprise Software License Agreement (found here https://strapi.io/enterprise-terms) applies to your use of the Enterprise Edition of the Strapi Software.
|
14
|
+
|
15
|
+
BY ACCESSING OR USING THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE, YOU ARE AGREEING TO BE BOUND BY THE RELEVANT REFERENCED AGREEMENT.
|
16
|
+
IF YOU ARE NOT AUTHORIZED TO ACCEPT THESE TERMS ON BEHALF OF THE COMPANY YOU REPRESENT OR IF YOU DO NOT AGREE TO ALL OF THE RELEVANT TERMS AND CONDITIONS REFERENCED AND YOU
|
17
|
+
HAVE NOT OTHERWISE EXECUTED A WRITTEN AGREEMENT WITH STRAPI, YOU ARE NOT AUTHORIZED TO ACCESS OR USE OR ALLOW ANY USER TO ACCESS OR USE ANY PART OF
|
18
|
+
THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE. YOUR ACCESS RIGHTS ARE CONDITIONAL ON YOUR CONSENT TO THE RELEVANT REFERENCED TERMS TO THE EXCLUSION OF ALL OTHER TERMS;
|
19
|
+
IF THE RELEVANT REFERENCED TERMS ARE CONSIDERED AN OFFER BY YOU, ACCEPTANCE IS EXPRESSLY LIMITED TO THE RELEVANT REFERENCED TERMS.
|
20
|
+
|
21
|
+
* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below.
|
22
|
+
|
23
|
+
MIT Expat License
|
24
|
+
|
25
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
26
|
+
of this software and associated documentation files (the "Software"), to deal
|
27
|
+
in the Software without restriction, including without limitation the rights
|
28
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
29
|
+
copies of the Software, and to permit persons to whom the Software is
|
30
|
+
furnished to do so, subject to the following conditions:
|
31
|
+
|
32
|
+
The above copyright notice and this permission notice shall be included in all
|
33
|
+
copies or substantial portions of the Software.
|
34
|
+
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
36
|
+
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,
|
37
|
+
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 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,554 @@
|
|
1
|
+
import { jsxs, jsx, Fragment } 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 { Modal, Button, useId, Tabs, Flex, Typography, Divider, Box, Grid, Field, SingleSelect, SingleSelectOption, Dialog, 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 useDeleteLocaleMutation, c as useUpdateLocaleMutation, d as useGetLocalesQuery, P as PERMISSIONS } from "./index-C6wPnwIO.mjs";
|
10
|
+
const isBaseQueryError = (error) => {
|
11
|
+
return error.name !== void 0;
|
12
|
+
};
|
13
|
+
const CreateLocale = ({ disabled, variant = "default" }) => {
|
14
|
+
const { formatMessage } = useIntl();
|
15
|
+
const [visible, setVisible] = React.useState(false);
|
16
|
+
return /* @__PURE__ */ jsxs(Modal.Root, { open: visible, onOpenChange: setVisible, children: [
|
17
|
+
/* @__PURE__ */ jsx(Modal.Trigger, { children: /* @__PURE__ */ jsx(
|
18
|
+
Button,
|
19
|
+
{
|
20
|
+
variant,
|
21
|
+
disabled,
|
22
|
+
startIcon: /* @__PURE__ */ jsx(Plus, {}),
|
23
|
+
onClick: () => setVisible(true),
|
24
|
+
size: "S",
|
25
|
+
children: formatMessage({
|
26
|
+
id: getTranslation("Settings.list.actions.add"),
|
27
|
+
defaultMessage: "Add new locale"
|
28
|
+
})
|
29
|
+
}
|
30
|
+
) }),
|
31
|
+
/* @__PURE__ */ jsx(CreateModal, { onClose: () => setVisible(false) })
|
32
|
+
] });
|
33
|
+
};
|
34
|
+
const LOCALE_SCHEMA = yup.object().shape({
|
35
|
+
code: yup.string().required({
|
36
|
+
id: "Settings.locales.modal.create.code.error",
|
37
|
+
defaultMessage: "Please select a locale"
|
38
|
+
}),
|
39
|
+
name: yup.string().max(50, {
|
40
|
+
id: "Settings.locales.modal.create.name.error.min",
|
41
|
+
defaultMessage: "The locale display name can only be less than 50 characters."
|
42
|
+
}).required({
|
43
|
+
id: "Settings.locales.modal.create.name.error.required",
|
44
|
+
defaultMessage: "Please give the locale a display name"
|
45
|
+
}),
|
46
|
+
isDefault: yup.boolean()
|
47
|
+
});
|
48
|
+
const initialFormValues = {
|
49
|
+
code: "",
|
50
|
+
name: "",
|
51
|
+
isDefault: false
|
52
|
+
};
|
53
|
+
const CreateModal = ({ onClose }) => {
|
54
|
+
const titleId = useId();
|
55
|
+
const { toggleNotification } = useNotification();
|
56
|
+
const {
|
57
|
+
_unstableFormatAPIError: formatAPIError,
|
58
|
+
_unstableFormatValidationErrors: formatValidationErrors
|
59
|
+
} = useAPIErrorHandler();
|
60
|
+
const [createLocale] = useCreateLocaleMutation();
|
61
|
+
const { formatMessage } = useIntl();
|
62
|
+
const refetchPermissions = useAuth("CreateModal", (state) => state.refetchPermissions);
|
63
|
+
const handleSubmit = async (values, helpers) => {
|
64
|
+
try {
|
65
|
+
const res = await createLocale(values);
|
66
|
+
if ("error" in res) {
|
67
|
+
if (isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
68
|
+
helpers.setErrors(formatValidationErrors(res.error));
|
69
|
+
} else {
|
70
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
71
|
+
}
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
toggleNotification({
|
75
|
+
type: "success",
|
76
|
+
message: formatMessage({
|
77
|
+
id: getTranslation("Settings.locales.modal.create.success"),
|
78
|
+
defaultMessage: "Created locale"
|
79
|
+
})
|
80
|
+
});
|
81
|
+
refetchPermissions();
|
82
|
+
onClose();
|
83
|
+
} catch (err) {
|
84
|
+
toggleNotification({
|
85
|
+
type: "danger",
|
86
|
+
message: formatMessage({
|
87
|
+
id: "notification.error",
|
88
|
+
defaultMessage: "An error occurred, please try again"
|
89
|
+
})
|
90
|
+
});
|
91
|
+
}
|
92
|
+
};
|
93
|
+
return /* @__PURE__ */ jsx(Modal.Content, { children: /* @__PURE__ */ jsxs(
|
94
|
+
Form,
|
95
|
+
{
|
96
|
+
method: "POST",
|
97
|
+
initialValues: initialFormValues,
|
98
|
+
validationSchema: LOCALE_SCHEMA,
|
99
|
+
onSubmit: handleSubmit,
|
100
|
+
children: [
|
101
|
+
/* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: formatMessage({
|
102
|
+
id: getTranslation("Settings.list.actions.add"),
|
103
|
+
defaultMessage: "Add new locale"
|
104
|
+
}) }) }),
|
105
|
+
/* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsxs(Tabs.Root, { variant: "simple", defaultValue: "basic", children: [
|
106
|
+
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", children: [
|
107
|
+
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "beta", id: titleId, children: formatMessage({
|
108
|
+
id: getTranslation("Settings.locales.modal.title"),
|
109
|
+
defaultMessage: "Configuration"
|
110
|
+
}) }),
|
111
|
+
/* @__PURE__ */ jsxs(Tabs.List, { "aria-labelledby": titleId, children: [
|
112
|
+
/* @__PURE__ */ jsx(Tabs.Trigger, { value: "basic", children: formatMessage({
|
113
|
+
id: getTranslation("Settings.locales.modal.base"),
|
114
|
+
defaultMessage: "Basic settings"
|
115
|
+
}) }),
|
116
|
+
/* @__PURE__ */ jsx(Tabs.Trigger, { value: "advanced", children: formatMessage({
|
117
|
+
id: getTranslation("Settings.locales.modal.advanced"),
|
118
|
+
defaultMessage: "Advanced settings"
|
119
|
+
}) })
|
120
|
+
] })
|
121
|
+
] }),
|
122
|
+
/* @__PURE__ */ jsx(Divider, {}),
|
123
|
+
/* @__PURE__ */ jsxs(Box, { paddingTop: 7, paddingBottom: 7, children: [
|
124
|
+
/* @__PURE__ */ jsx(Tabs.Content, { value: "basic", children: /* @__PURE__ */ jsx(BaseForm, {}) }),
|
125
|
+
/* @__PURE__ */ jsx(Tabs.Content, { value: "advanced", children: /* @__PURE__ */ jsx(AdvancedForm, {}) })
|
126
|
+
] })
|
127
|
+
] }) }),
|
128
|
+
/* @__PURE__ */ jsxs(Modal.Footer, { children: [
|
129
|
+
/* @__PURE__ */ jsx(Modal.Close, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: formatMessage({ id: "app.components.Button.cancel", defaultMessage: "Cancel" }) }) }),
|
130
|
+
/* @__PURE__ */ jsx(SubmitButton, {})
|
131
|
+
] })
|
132
|
+
]
|
133
|
+
}
|
134
|
+
) });
|
135
|
+
};
|
136
|
+
const SubmitButton = () => {
|
137
|
+
const { formatMessage } = useIntl();
|
138
|
+
const isSubmitting = useForm("SubmitButton", (state) => state.isSubmitting);
|
139
|
+
const modified = useForm("SubmitButton", (state) => state.modified);
|
140
|
+
return /* @__PURE__ */ jsx(Button, { type: "submit", startIcon: /* @__PURE__ */ jsx(Check, {}), disabled: isSubmitting || !modified, children: formatMessage({ id: "global.save", defaultMessage: "Save" }) });
|
141
|
+
};
|
142
|
+
const BaseForm = ({ mode = "create" }) => {
|
143
|
+
const { formatMessage } = useIntl();
|
144
|
+
const { toggleNotification } = useNotification();
|
145
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
146
|
+
const { data: defaultLocales, error } = useGetDefaultLocalesQuery();
|
147
|
+
React.useEffect(() => {
|
148
|
+
if (error) {
|
149
|
+
toggleNotification({
|
150
|
+
type: "danger",
|
151
|
+
message: formatAPIError(error)
|
152
|
+
});
|
153
|
+
}
|
154
|
+
}, [error, formatAPIError, toggleNotification]);
|
155
|
+
if (!Array.isArray(defaultLocales)) {
|
156
|
+
return null;
|
157
|
+
}
|
158
|
+
const options = defaultLocales.map((locale) => ({
|
159
|
+
label: locale.name,
|
160
|
+
value: locale.code
|
161
|
+
}));
|
162
|
+
const translatedForm = [
|
163
|
+
{
|
164
|
+
disabled: mode !== "create",
|
165
|
+
label: {
|
166
|
+
id: getTranslation("Settings.locales.modal.create.code.label"),
|
167
|
+
defaultMessage: "Locales"
|
168
|
+
},
|
169
|
+
name: "code",
|
170
|
+
options,
|
171
|
+
placeholder: {
|
172
|
+
id: "components.placeholder.select",
|
173
|
+
defaultMessage: "Select"
|
174
|
+
},
|
175
|
+
required: true,
|
176
|
+
size: 6,
|
177
|
+
type: "enumeration"
|
178
|
+
},
|
179
|
+
{
|
180
|
+
hint: {
|
181
|
+
id: getTranslation("Settings.locales.modal.create.name.label.description"),
|
182
|
+
defaultMessage: "Locale will be displayed under that name in the administration panel"
|
183
|
+
},
|
184
|
+
label: {
|
185
|
+
id: getTranslation("Settings.locales.modal.create.name.label"),
|
186
|
+
defaultMessage: "Locale display name"
|
187
|
+
},
|
188
|
+
name: "name",
|
189
|
+
required: true,
|
190
|
+
size: 6,
|
191
|
+
type: "string"
|
192
|
+
}
|
193
|
+
].map((field) => ({
|
194
|
+
...field,
|
195
|
+
hint: field.hint ? formatMessage(field.hint) : void 0,
|
196
|
+
label: formatMessage(field.label),
|
197
|
+
placeholder: field.placeholder ? formatMessage(field.placeholder) : void 0
|
198
|
+
}));
|
199
|
+
return /* @__PURE__ */ jsx(Grid.Root, { gap: 4, children: translatedForm.map(({ size, ...field }) => /* @__PURE__ */ jsx(Grid.Item, { col: size, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsx(FormRenderer, { ...field }) }, field.name)) });
|
200
|
+
};
|
201
|
+
const AdvancedForm = ({ isDefaultLocale }) => {
|
202
|
+
const { formatMessage } = useIntl();
|
203
|
+
const form = [
|
204
|
+
{
|
205
|
+
disabled: isDefaultLocale,
|
206
|
+
hint: {
|
207
|
+
id: getTranslation("Settings.locales.modal.advanced.setAsDefault.hint"),
|
208
|
+
defaultMessage: "One default locale is required, change it by selecting another one"
|
209
|
+
},
|
210
|
+
label: {
|
211
|
+
id: getTranslation("Settings.locales.modal.advanced.setAsDefault"),
|
212
|
+
defaultMessage: "Set as default locale"
|
213
|
+
},
|
214
|
+
name: "isDefault",
|
215
|
+
size: 6,
|
216
|
+
type: "boolean"
|
217
|
+
}
|
218
|
+
].map((field) => ({
|
219
|
+
...field,
|
220
|
+
hint: field.hint ? formatMessage(field.hint) : void 0,
|
221
|
+
label: formatMessage(field.label)
|
222
|
+
}));
|
223
|
+
return /* @__PURE__ */ jsx(Grid.Root, { gap: 4, children: form.map(({ size, ...field }) => /* @__PURE__ */ jsx(Grid.Item, { col: size, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsx(FormRenderer, { ...field }) }, field.name)) });
|
224
|
+
};
|
225
|
+
const FormRenderer = (field) => {
|
226
|
+
switch (field.type) {
|
227
|
+
case "enumeration":
|
228
|
+
return /* @__PURE__ */ jsx(EnumerationInput, { ...field });
|
229
|
+
default:
|
230
|
+
return /* @__PURE__ */ jsx(InputRenderer, { ...field });
|
231
|
+
}
|
232
|
+
};
|
233
|
+
const EnumerationInput = ({
|
234
|
+
disabled,
|
235
|
+
hint,
|
236
|
+
label,
|
237
|
+
name,
|
238
|
+
options,
|
239
|
+
placeholder,
|
240
|
+
required
|
241
|
+
}) => {
|
242
|
+
const { value, error, onChange } = useField(name);
|
243
|
+
const { data: defaultLocales = [] } = useGetDefaultLocalesQuery();
|
244
|
+
const handleChange = (value2) => {
|
245
|
+
if (Array.isArray(defaultLocales)) {
|
246
|
+
const locale = defaultLocales.find((locale2) => locale2.code === value2);
|
247
|
+
onChange(name, value2);
|
248
|
+
onChange("name", locale.name);
|
249
|
+
} else {
|
250
|
+
onChange(name, value2);
|
251
|
+
}
|
252
|
+
};
|
253
|
+
return /* @__PURE__ */ jsxs(Field.Root, { error, hint, name, required, children: [
|
254
|
+
/* @__PURE__ */ jsx(Field.Label, { children: label }),
|
255
|
+
/* @__PURE__ */ jsx(
|
256
|
+
SingleSelect,
|
257
|
+
{
|
258
|
+
disabled,
|
259
|
+
onChange: handleChange,
|
260
|
+
placeholder,
|
261
|
+
value,
|
262
|
+
children: options.map((option) => /* @__PURE__ */ jsx(SingleSelectOption, { value: option.value, children: option.label }, option.value))
|
263
|
+
}
|
264
|
+
),
|
265
|
+
/* @__PURE__ */ jsx(Field.Error, {}),
|
266
|
+
/* @__PURE__ */ jsx(Field.Hint, {})
|
267
|
+
] });
|
268
|
+
};
|
269
|
+
const DeleteLocale = ({ id, name }) => {
|
270
|
+
const { formatMessage } = useIntl();
|
271
|
+
const { toggleNotification } = useNotification();
|
272
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
273
|
+
const [visible, setVisible] = React.useState(false);
|
274
|
+
const [deleteLocale] = useDeleteLocaleMutation();
|
275
|
+
const handleConfirm = async () => {
|
276
|
+
try {
|
277
|
+
const res = await deleteLocale(id);
|
278
|
+
if ("error" in res) {
|
279
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
280
|
+
return;
|
281
|
+
}
|
282
|
+
toggleNotification({
|
283
|
+
type: "success",
|
284
|
+
message: formatMessage({
|
285
|
+
id: getTranslation("Settings.locales.modal.delete.success"),
|
286
|
+
defaultMessage: "Deleted locale"
|
287
|
+
})
|
288
|
+
});
|
289
|
+
setVisible(false);
|
290
|
+
} catch (err) {
|
291
|
+
toggleNotification({
|
292
|
+
type: "danger",
|
293
|
+
message: formatMessage({
|
294
|
+
id: "notification.error",
|
295
|
+
defaultMessage: "An error occurred, please try again"
|
296
|
+
})
|
297
|
+
});
|
298
|
+
}
|
299
|
+
};
|
300
|
+
return /* @__PURE__ */ jsxs(Dialog.Root, { open: visible, onOpenChange: setVisible, children: [
|
301
|
+
/* @__PURE__ */ jsx(Dialog.Trigger, { children: /* @__PURE__ */ jsx(
|
302
|
+
IconButton,
|
303
|
+
{
|
304
|
+
onClick: () => setVisible(true),
|
305
|
+
label: formatMessage(
|
306
|
+
{
|
307
|
+
id: getTranslation("Settings.list.actions.delete"),
|
308
|
+
defaultMessage: "Delete {name} locale"
|
309
|
+
},
|
310
|
+
{
|
311
|
+
name
|
312
|
+
}
|
313
|
+
),
|
314
|
+
variant: "ghost",
|
315
|
+
children: /* @__PURE__ */ jsx(Trash, {})
|
316
|
+
}
|
317
|
+
) }),
|
318
|
+
/* @__PURE__ */ jsx(ConfirmDialog, { onConfirm: handleConfirm })
|
319
|
+
] });
|
320
|
+
};
|
321
|
+
const EditLocale = (props) => {
|
322
|
+
const { formatMessage } = useIntl();
|
323
|
+
const [visible, setVisible] = React.useState(false);
|
324
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
325
|
+
/* @__PURE__ */ jsx(
|
326
|
+
IconButton,
|
327
|
+
{
|
328
|
+
onClick: () => setVisible(true),
|
329
|
+
label: formatMessage(
|
330
|
+
{
|
331
|
+
id: getTranslation("Settings.list.actions.edit"),
|
332
|
+
defaultMessage: "Edit {name} locale"
|
333
|
+
},
|
334
|
+
{
|
335
|
+
name: props.name
|
336
|
+
}
|
337
|
+
),
|
338
|
+
variant: "ghost",
|
339
|
+
children: /* @__PURE__ */ jsx(Pencil, {})
|
340
|
+
}
|
341
|
+
),
|
342
|
+
/* @__PURE__ */ jsx(EditModal, { ...props, open: visible, onOpenChange: setVisible })
|
343
|
+
] });
|
344
|
+
};
|
345
|
+
const EditModal = ({ id, code, isDefault, name, open, onOpenChange }) => {
|
346
|
+
const { toggleNotification } = useNotification();
|
347
|
+
const {
|
348
|
+
_unstableFormatAPIError: formatAPIError,
|
349
|
+
_unstableFormatValidationErrors: formatValidationErrors
|
350
|
+
} = useAPIErrorHandler();
|
351
|
+
const refetchPermissions = useAuth("EditModal", (state) => state.refetchPermissions);
|
352
|
+
const { formatMessage } = useIntl();
|
353
|
+
const titleId = useId();
|
354
|
+
const [updateLocale] = useUpdateLocaleMutation();
|
355
|
+
const handleSubmit = async ({ code: _code, ...data }, helpers) => {
|
356
|
+
try {
|
357
|
+
const res = await updateLocale({
|
358
|
+
id,
|
359
|
+
...data
|
360
|
+
});
|
361
|
+
if ("error" in res) {
|
362
|
+
if (isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
363
|
+
helpers.setErrors(formatValidationErrors(res.error));
|
364
|
+
} else {
|
365
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
366
|
+
}
|
367
|
+
return;
|
368
|
+
}
|
369
|
+
toggleNotification({
|
370
|
+
type: "success",
|
371
|
+
message: formatMessage({
|
372
|
+
id: getTranslation("Settings.locales.modal.edit.success"),
|
373
|
+
defaultMessage: "Updated locale"
|
374
|
+
})
|
375
|
+
});
|
376
|
+
refetchPermissions();
|
377
|
+
onOpenChange(false);
|
378
|
+
} catch (err) {
|
379
|
+
toggleNotification({
|
380
|
+
type: "danger",
|
381
|
+
message: formatMessage({
|
382
|
+
id: "notification.error",
|
383
|
+
defaultMessage: "An error occurred, please try again"
|
384
|
+
})
|
385
|
+
});
|
386
|
+
}
|
387
|
+
};
|
388
|
+
return /* @__PURE__ */ jsx(Modal.Root, { open, onOpenChange, children: /* @__PURE__ */ jsx(Modal.Content, { children: /* @__PURE__ */ jsxs(
|
389
|
+
Form,
|
390
|
+
{
|
391
|
+
method: "PUT",
|
392
|
+
onSubmit: handleSubmit,
|
393
|
+
initialValues: {
|
394
|
+
code,
|
395
|
+
name,
|
396
|
+
isDefault
|
397
|
+
},
|
398
|
+
validationSchema: LOCALE_SCHEMA,
|
399
|
+
children: [
|
400
|
+
/* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: formatMessage(
|
401
|
+
{
|
402
|
+
id: getTranslation("Settings.list.actions.edit"),
|
403
|
+
defaultMessage: "Edit a locale"
|
404
|
+
},
|
405
|
+
{
|
406
|
+
name
|
407
|
+
}
|
408
|
+
) }) }),
|
409
|
+
/* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsxs(Tabs.Root, { variant: "simple", defaultValue: "basic", children: [
|
410
|
+
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", children: [
|
411
|
+
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "beta", id: titleId, children: formatMessage({
|
412
|
+
id: getTranslation("Settings.locales.modal.title"),
|
413
|
+
defaultMessage: "Configuration"
|
414
|
+
}) }),
|
415
|
+
/* @__PURE__ */ jsxs(Tabs.List, { "aria-labelledby": titleId, children: [
|
416
|
+
/* @__PURE__ */ jsx(Tabs.Trigger, { value: "basic", children: formatMessage({
|
417
|
+
id: getTranslation("Settings.locales.modal.base"),
|
418
|
+
defaultMessage: "Basic settings"
|
419
|
+
}) }),
|
420
|
+
/* @__PURE__ */ jsx(Tabs.Trigger, { value: "advanced", children: formatMessage({
|
421
|
+
id: getTranslation("Settings.locales.modal.advanced"),
|
422
|
+
defaultMessage: "Advanced settings"
|
423
|
+
}) })
|
424
|
+
] })
|
425
|
+
] }),
|
426
|
+
/* @__PURE__ */ jsx(Divider, {}),
|
427
|
+
/* @__PURE__ */ jsxs(Box, { paddingTop: 7, paddingBottom: 7, children: [
|
428
|
+
/* @__PURE__ */ jsx(Tabs.Content, { value: "basic", children: /* @__PURE__ */ jsx(BaseForm, { mode: "edit" }) }),
|
429
|
+
/* @__PURE__ */ jsx(Tabs.Content, { value: "advanced", children: /* @__PURE__ */ jsx(AdvancedForm, { isDefaultLocale: isDefault }) })
|
430
|
+
] })
|
431
|
+
] }) }),
|
432
|
+
/* @__PURE__ */ jsxs(Modal.Footer, { children: [
|
433
|
+
/* @__PURE__ */ jsx(Modal.Close, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: formatMessage({ id: "app.components.Button.cancel", defaultMessage: "Cancel" }) }) }),
|
434
|
+
/* @__PURE__ */ jsx(SubmitButton, {})
|
435
|
+
] })
|
436
|
+
]
|
437
|
+
}
|
438
|
+
) }) });
|
439
|
+
};
|
440
|
+
const LocaleTable = ({ locales = [], canDelete, canUpdate }) => {
|
441
|
+
const [editLocaleId, setEditLocaleId] = React.useState();
|
442
|
+
const { formatMessage } = useIntl();
|
443
|
+
const handleClick = (localeId) => () => {
|
444
|
+
if (canUpdate) {
|
445
|
+
setEditLocaleId(localeId);
|
446
|
+
}
|
447
|
+
};
|
448
|
+
return /* @__PURE__ */ jsxs(Table, { colCount: 4, rowCount: locales.length + 1, children: [
|
449
|
+
/* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
|
450
|
+
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
|
451
|
+
id: getTranslation("Settings.locales.row.id"),
|
452
|
+
defaultMessage: "ID"
|
453
|
+
}) }) }),
|
454
|
+
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
|
455
|
+
id: getTranslation("Settings.locales.row.displayName"),
|
456
|
+
defaultMessage: "Display name"
|
457
|
+
}) }) }),
|
458
|
+
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
|
459
|
+
id: getTranslation("Settings.locales.row.default-locale"),
|
460
|
+
defaultMessage: "Default locale"
|
461
|
+
}) }) }),
|
462
|
+
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(VisuallyHidden, { children: "Actions" }) })
|
463
|
+
] }) }),
|
464
|
+
/* @__PURE__ */ jsx(Tbody, { children: locales.map((locale) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
465
|
+
/* @__PURE__ */ jsxs(
|
466
|
+
Tr,
|
467
|
+
{
|
468
|
+
onClick: handleClick(locale.id),
|
469
|
+
style: { cursor: canUpdate ? "pointer" : "default" },
|
470
|
+
children: [
|
471
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: locale.id }) }),
|
472
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: locale.name }) }),
|
473
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: locale.isDefault ? formatMessage({
|
474
|
+
id: getTranslation("Settings.locales.default"),
|
475
|
+
defaultMessage: "Default"
|
476
|
+
}) : null }) }),
|
477
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Flex, { gap: 1, justifyContent: "flex-end", onClick: (e) => e.stopPropagation(), children: [
|
478
|
+
canUpdate && /* @__PURE__ */ jsx(EditLocale, { ...locale }),
|
479
|
+
canDelete && !locale.isDefault && /* @__PURE__ */ jsx(DeleteLocale, { ...locale })
|
480
|
+
] }) })
|
481
|
+
]
|
482
|
+
}
|
483
|
+
),
|
484
|
+
/* @__PURE__ */ jsx(
|
485
|
+
EditModal,
|
486
|
+
{
|
487
|
+
...locale,
|
488
|
+
onOpenChange: () => setEditLocaleId(void 0),
|
489
|
+
open: editLocaleId === locale.id
|
490
|
+
}
|
491
|
+
)
|
492
|
+
] }, locale.id)) })
|
493
|
+
] });
|
494
|
+
};
|
495
|
+
const SettingsPage = () => {
|
496
|
+
const { formatMessage } = useIntl();
|
497
|
+
const { toggleNotification } = useNotification();
|
498
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
499
|
+
const { data: locales, isLoading: isLoadingLocales, error } = useGetLocalesQuery();
|
500
|
+
const {
|
501
|
+
isLoading: isLoadingRBAC,
|
502
|
+
allowedActions: { canUpdate, canCreate, canDelete }
|
503
|
+
} = useRBAC(PERMISSIONS);
|
504
|
+
React.useEffect(() => {
|
505
|
+
if (error) {
|
506
|
+
toggleNotification({
|
507
|
+
type: "danger",
|
508
|
+
message: formatAPIError(error)
|
509
|
+
});
|
510
|
+
}
|
511
|
+
}, [error, formatAPIError, toggleNotification]);
|
512
|
+
const isLoading = isLoadingLocales || isLoadingRBAC;
|
513
|
+
if (isLoading) {
|
514
|
+
return /* @__PURE__ */ jsx(Page.Loading, {});
|
515
|
+
}
|
516
|
+
if (error || !Array.isArray(locales)) {
|
517
|
+
return /* @__PURE__ */ jsx(Page.Error, {});
|
518
|
+
}
|
519
|
+
return /* @__PURE__ */ jsxs(Page.Main, { tabIndex: -1, children: [
|
520
|
+
/* @__PURE__ */ jsx(
|
521
|
+
Layouts.Header,
|
522
|
+
{
|
523
|
+
primaryAction: /* @__PURE__ */ jsx(CreateLocale, { disabled: !canCreate }),
|
524
|
+
title: formatMessage({
|
525
|
+
id: getTranslation("plugin.name"),
|
526
|
+
defaultMessage: "Internationalization"
|
527
|
+
}),
|
528
|
+
subtitle: formatMessage({
|
529
|
+
id: getTranslation("Settings.list.description"),
|
530
|
+
defaultMessage: "Configure the settings"
|
531
|
+
})
|
532
|
+
}
|
533
|
+
),
|
534
|
+
/* @__PURE__ */ jsx(Layouts.Content, { children: locales.length > 0 ? /* @__PURE__ */ jsx(LocaleTable, { locales, canDelete, canUpdate }) : /* @__PURE__ */ jsx(
|
535
|
+
EmptyStateLayout,
|
536
|
+
{
|
537
|
+
icon: /* @__PURE__ */ jsx(EmptyDocuments, { width: void 0, height: void 0 }),
|
538
|
+
content: formatMessage({
|
539
|
+
id: getTranslation("Settings.list.empty.title"),
|
540
|
+
defaultMessage: "There are no locales"
|
541
|
+
}),
|
542
|
+
action: /* @__PURE__ */ jsx(CreateLocale, { disabled: !canCreate, variant: "secondary" })
|
543
|
+
}
|
544
|
+
) })
|
545
|
+
] });
|
546
|
+
};
|
547
|
+
const ProtectedSettingsPage = () => {
|
548
|
+
return /* @__PURE__ */ jsx(Page.Protect, { permissions: PERMISSIONS.read, children: /* @__PURE__ */ jsx(SettingsPage, {}) });
|
549
|
+
};
|
550
|
+
export {
|
551
|
+
ProtectedSettingsPage,
|
552
|
+
SettingsPage
|
553
|
+
};
|
554
|
+
//# sourceMappingURL=SettingsPage-DdW0J2We.mjs.map
|