@strapi/i18n 0.0.0 → 5.0.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/README.md +17 -1
  2. package/dist/_chunks/SettingsPage-B73NO_8-.js +585 -0
  3. package/dist/_chunks/SettingsPage-B73NO_8-.js.map +1 -0
  4. package/dist/_chunks/SettingsPage-pvdzbKEM.mjs +565 -0
  5. package/dist/_chunks/SettingsPage-pvdzbKEM.mjs.map +1 -0
  6. package/dist/_chunks/de-9eCAqqrB.mjs +66 -0
  7. package/dist/_chunks/de-9eCAqqrB.mjs.map +1 -0
  8. package/dist/_chunks/de-DtWiGdHl.js +66 -0
  9. package/dist/_chunks/de-DtWiGdHl.js.map +1 -0
  10. package/dist/_chunks/dk-2qBjxt-P.mjs +66 -0
  11. package/dist/_chunks/dk-2qBjxt-P.mjs.map +1 -0
  12. package/dist/_chunks/dk-D8C-casx.js +66 -0
  13. package/dist/_chunks/dk-D8C-casx.js.map +1 -0
  14. package/dist/_chunks/en-BuBc6LKZ.js +69 -0
  15. package/dist/_chunks/en-BuBc6LKZ.js.map +1 -0
  16. package/dist/_chunks/en-CnrTsjWS.mjs +69 -0
  17. package/dist/_chunks/en-CnrTsjWS.mjs.map +1 -0
  18. package/dist/_chunks/es-DS-XFGSw.js +66 -0
  19. package/dist/_chunks/es-DS-XFGSw.js.map +1 -0
  20. package/dist/_chunks/es-DlmMVaBG.mjs +66 -0
  21. package/dist/_chunks/es-DlmMVaBG.mjs.map +1 -0
  22. package/dist/_chunks/fr-3S6ke71d.mjs +66 -0
  23. package/dist/_chunks/fr-3S6ke71d.mjs.map +1 -0
  24. package/dist/_chunks/fr-BTjekDpq.js +66 -0
  25. package/dist/_chunks/fr-BTjekDpq.js.map +1 -0
  26. package/dist/_chunks/index-kcYwoCdE.js +1082 -0
  27. package/dist/_chunks/index-kcYwoCdE.js.map +1 -0
  28. package/dist/_chunks/index-lckTPHiZ.mjs +1058 -0
  29. package/dist/_chunks/index-lckTPHiZ.mjs.map +1 -0
  30. package/dist/_chunks/ko-DmcGUBQ3.js +65 -0
  31. package/dist/_chunks/ko-DmcGUBQ3.js.map +1 -0
  32. package/dist/_chunks/ko-qTjQ8IMw.mjs +65 -0
  33. package/dist/_chunks/ko-qTjQ8IMw.mjs.map +1 -0
  34. package/dist/_chunks/pl-B67TSHqT.mjs +66 -0
  35. package/dist/_chunks/pl-B67TSHqT.mjs.map +1 -0
  36. package/dist/_chunks/pl-Cn5RYonZ.js +66 -0
  37. package/dist/_chunks/pl-Cn5RYonZ.js.map +1 -0
  38. package/dist/_chunks/ru-BMBgVL3s.js +68 -0
  39. package/dist/_chunks/ru-BMBgVL3s.js.map +1 -0
  40. package/dist/_chunks/ru-hagMa57T.mjs +68 -0
  41. package/dist/_chunks/ru-hagMa57T.mjs.map +1 -0
  42. package/dist/_chunks/tr-CarUU76c.js +66 -0
  43. package/dist/_chunks/tr-CarUU76c.js.map +1 -0
  44. package/dist/_chunks/tr-Dw_jmkG-.mjs +66 -0
  45. package/dist/_chunks/tr-Dw_jmkG-.mjs.map +1 -0
  46. package/dist/_chunks/zh-57YM4amO.mjs +66 -0
  47. package/dist/_chunks/zh-57YM4amO.mjs.map +1 -0
  48. package/dist/_chunks/zh-CukOviB0.js +66 -0
  49. package/dist/_chunks/zh-CukOviB0.js.map +1 -0
  50. package/dist/_chunks/zh-Hans-DSHIXAa3.js +57 -0
  51. package/dist/_chunks/zh-Hans-DSHIXAa3.js.map +1 -0
  52. package/dist/_chunks/zh-Hans-Dyc-aR-h.mjs +57 -0
  53. package/dist/_chunks/zh-Hans-Dyc-aR-h.mjs.map +1 -0
  54. package/dist/admin/index.js +6 -0
  55. package/dist/admin/index.js.map +1 -0
  56. package/dist/admin/index.mjs +7 -0
  57. package/dist/admin/index.mjs.map +1 -0
  58. package/dist/admin/src/components/CMHeaderActions.d.ts +4 -0
  59. package/dist/admin/src/components/CMListViewModalsAdditionalInformation.d.ts +4 -0
  60. package/dist/admin/src/components/CheckboxConfirmation.d.ts +20 -0
  61. package/dist/admin/src/components/CreateLocale.d.ts +29 -0
  62. package/dist/admin/src/components/DeleteLocale.d.ts +5 -0
  63. package/dist/admin/src/components/EditLocale.d.ts +13 -0
  64. package/dist/admin/src/components/Initializer.d.ts +5 -0
  65. package/dist/admin/src/components/LocaleListCell.d.ts +9 -0
  66. package/dist/admin/src/components/LocalePicker.d.ts +2 -0
  67. package/dist/admin/src/components/LocaleTable.d.ts +11 -0
  68. package/dist/admin/src/constants.d.ts +22 -0
  69. package/dist/admin/src/contentManagerHooks/editView.d.ts +6 -0
  70. package/dist/admin/src/contentManagerHooks/listView.d.ts +22 -0
  71. package/dist/admin/src/contentReleasesHooks/releaseDetailsView.d.ts +36 -0
  72. package/dist/admin/src/hooks/useI18n.d.ts +16 -0
  73. package/dist/admin/src/index.d.ts +16 -0
  74. package/dist/admin/src/middlewares/extendCTBAttributeInitialData.d.ts +4 -0
  75. package/dist/admin/src/middlewares/extendCTBInitialData.d.ts +4 -0
  76. package/dist/admin/src/middlewares/rbac-middleware.d.ts +3 -0
  77. package/dist/admin/src/pages/SettingsPage.d.ts +3 -0
  78. package/dist/admin/src/pluginId.d.ts +1 -0
  79. package/dist/admin/src/services/api.d.ts +3 -0
  80. package/dist/admin/src/services/locales.d.ts +4 -0
  81. package/dist/admin/src/types.d.ts +9 -0
  82. package/dist/admin/src/utils/baseQuery.d.ts +20 -0
  83. package/dist/admin/src/utils/fields.d.ts +7 -0
  84. package/dist/admin/src/utils/getTranslation.d.ts +2 -0
  85. package/dist/admin/src/utils/prefixPluginTranslations.d.ts +3 -0
  86. package/dist/admin/src/utils/schemas.d.ts +24 -0
  87. package/dist/admin/src/utils/strings.d.ts +2 -0
  88. package/dist/server/index.js +3522 -0
  89. package/dist/server/index.js.map +1 -0
  90. package/dist/server/index.mjs +3503 -0
  91. package/dist/server/index.mjs.map +1 -0
  92. package/dist/server/src/bootstrap.d.ts +6 -0
  93. package/dist/server/src/bootstrap.d.ts.map +1 -0
  94. package/dist/server/src/constants/index.d.ts +15 -0
  95. package/dist/server/src/constants/index.d.ts.map +1 -0
  96. package/dist/server/src/content-types/index.d.ts +37 -0
  97. package/dist/server/src/content-types/index.d.ts.map +1 -0
  98. package/dist/server/src/content-types/locale/index.d.ts +35 -0
  99. package/dist/server/src/content-types/locale/index.d.ts.map +1 -0
  100. package/dist/server/src/controllers/content-types.d.ts +6 -0
  101. package/dist/server/src/controllers/content-types.d.ts.map +1 -0
  102. package/dist/server/src/controllers/index.d.ts +10 -0
  103. package/dist/server/src/controllers/index.d.ts.map +1 -0
  104. package/dist/server/src/controllers/iso-locales.d.ts +4 -0
  105. package/dist/server/src/controllers/iso-locales.d.ts.map +1 -0
  106. package/dist/server/src/controllers/locales.d.ts +4 -0
  107. package/dist/server/src/controllers/locales.d.ts.map +1 -0
  108. package/dist/server/src/controllers/validate-locale-creation.d.ts +4 -0
  109. package/dist/server/src/controllers/validate-locale-creation.d.ts.map +1 -0
  110. package/dist/server/src/domain/locale.d.ts +11 -0
  111. package/dist/server/src/domain/locale.d.ts.map +1 -0
  112. package/dist/server/src/graphql.d.ts +8 -0
  113. package/dist/server/src/graphql.d.ts.map +1 -0
  114. package/dist/server/src/index.d.ts +148 -0
  115. package/dist/server/src/index.d.ts.map +1 -0
  116. package/dist/server/src/migrations/content-type/disable/index.d.ts +3 -0
  117. package/dist/server/src/migrations/content-type/disable/index.d.ts.map +1 -0
  118. package/dist/server/src/migrations/content-type/enable/index.d.ts +3 -0
  119. package/dist/server/src/migrations/content-type/enable/index.d.ts.map +1 -0
  120. package/dist/server/src/register.d.ts +6 -0
  121. package/dist/server/src/register.d.ts.map +1 -0
  122. package/dist/server/src/routes/admin.d.ts +18 -0
  123. package/dist/server/src/routes/admin.d.ts.map +1 -0
  124. package/dist/server/src/routes/content-api.d.ts +10 -0
  125. package/dist/server/src/routes/content-api.d.ts.map +1 -0
  126. package/dist/server/src/routes/index.d.ts +28 -0
  127. package/dist/server/src/routes/index.d.ts.map +1 -0
  128. package/dist/server/src/services/content-types.d.ts +13 -0
  129. package/dist/server/src/services/content-types.d.ts.map +1 -0
  130. package/dist/server/src/services/entity-service-decorator.d.ts +29 -0
  131. package/dist/server/src/services/entity-service-decorator.d.ts.map +1 -0
  132. package/dist/server/src/services/index.d.ts +71 -0
  133. package/dist/server/src/services/index.d.ts.map +1 -0
  134. package/dist/server/src/services/iso-locales.d.ts +10 -0
  135. package/dist/server/src/services/iso-locales.d.ts.map +1 -0
  136. package/dist/server/src/services/locales.d.ts +17 -0
  137. package/dist/server/src/services/locales.d.ts.map +1 -0
  138. package/dist/server/src/services/localizations.d.ts +8 -0
  139. package/dist/server/src/services/localizations.d.ts.map +1 -0
  140. package/dist/server/src/services/metrics.d.ts +8 -0
  141. package/dist/server/src/services/metrics.d.ts.map +1 -0
  142. package/dist/server/src/services/permissions/actions.d.ts +16 -0
  143. package/dist/server/src/services/permissions/actions.d.ts.map +1 -0
  144. package/dist/server/src/services/permissions/conditions.d.ts +15 -0
  145. package/dist/server/src/services/permissions/conditions.d.ts.map +1 -0
  146. package/dist/server/src/services/permissions/engine.d.ts +6 -0
  147. package/dist/server/src/services/permissions/engine.d.ts.map +1 -0
  148. package/dist/server/src/services/permissions/sections-builder.d.ts +6 -0
  149. package/dist/server/src/services/permissions/sections-builder.d.ts.map +1 -0
  150. package/dist/server/src/services/permissions.d.ts +28 -0
  151. package/dist/server/src/services/permissions.d.ts.map +1 -0
  152. package/dist/server/src/utils/index.d.ts +43 -0
  153. package/dist/server/src/utils/index.d.ts.map +1 -0
  154. package/dist/server/src/validation/content-types.d.ts +3 -0
  155. package/dist/server/src/validation/content-types.d.ts.map +1 -0
  156. package/dist/server/src/validation/locales.d.ts +12 -0
  157. package/dist/server/src/validation/locales.d.ts.map +1 -0
  158. package/dist/shared/contracts/content-manager.d.ts +27 -0
  159. package/dist/shared/contracts/iso-locales.d.ts +21 -0
  160. package/dist/shared/contracts/locales.d.ts +77 -0
  161. package/dist/shared/contracts/shared.d.ts +6 -0
  162. package/package.json +83 -4
  163. package/strapi-server.js +3 -0
package/README.md CHANGED
@@ -1 +1,17 @@
1
- # Strapi i18n
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,585 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
5
+ const strapiAdmin = require("@strapi/admin/strapi-admin");
6
+ const designSystem = require("@strapi/design-system");
7
+ const symbols = require("@strapi/icons/symbols");
8
+ const reactIntl = require("react-intl");
9
+ const icons = require("@strapi/icons");
10
+ const yup = require("yup");
11
+ const index = require("./index-kcYwoCdE.js");
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule)
14
+ return e;
15
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
16
+ if (e) {
17
+ for (const k in e) {
18
+ if (k !== "default") {
19
+ const d = Object.getOwnPropertyDescriptor(e, k);
20
+ Object.defineProperty(n, k, d.get ? d : {
21
+ enumerable: true,
22
+ get: () => e[k]
23
+ });
24
+ }
25
+ }
26
+ }
27
+ n.default = e;
28
+ return Object.freeze(n);
29
+ }
30
+ const React__namespace = /* @__PURE__ */ _interopNamespace(React);
31
+ const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
32
+ const CreateLocale = ({ disabled, variant = "default" }) => {
33
+ const { formatMessage } = reactIntl.useIntl();
34
+ const [visible, setVisible] = React__namespace.useState(false);
35
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
36
+ /* @__PURE__ */ jsxRuntime.jsx(
37
+ designSystem.Button,
38
+ {
39
+ variant,
40
+ disabled,
41
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
42
+ onClick: () => setVisible(true),
43
+ size: "S",
44
+ children: formatMessage({
45
+ id: index.getTranslation("Settings.list.actions.add"),
46
+ defaultMessage: "Add new locale"
47
+ })
48
+ }
49
+ ),
50
+ visible ? /* @__PURE__ */ jsxRuntime.jsx(CreateModal, { onClose: () => setVisible(false) }) : null
51
+ ] });
52
+ };
53
+ const LOCALE_SCHEMA = yup__namespace.object().shape({
54
+ code: yup__namespace.string().required({
55
+ id: "Settings.locales.modal.create.code.error",
56
+ defaultMessage: "Please select a locale"
57
+ }),
58
+ name: yup__namespace.string().max(50, {
59
+ id: "Settings.locales.modal.create.name.error.min",
60
+ defaultMessage: "The locale display name can only be less than 50 characters."
61
+ }).required({
62
+ id: "Settings.locales.modal.create.name.error.required",
63
+ defaultMessage: "Please give the locale a display name"
64
+ }),
65
+ isDefault: yup__namespace.boolean()
66
+ });
67
+ const initialFormValues = {
68
+ code: "",
69
+ name: "",
70
+ isDefault: false
71
+ };
72
+ const CreateModal = ({ onClose }) => {
73
+ const { toggleNotification } = strapiAdmin.useNotification();
74
+ const {
75
+ _unstableFormatAPIError: formatAPIError,
76
+ _unstableFormatValidationErrors: formatValidationErrors
77
+ } = strapiAdmin.useAPIErrorHandler();
78
+ const [createLocale] = index.useCreateLocaleMutation();
79
+ const { formatMessage } = reactIntl.useIntl();
80
+ const refetchPermissions = strapiAdmin.useAuth("CreateModal", (state) => state.refetchPermissions);
81
+ const handleSubmit = async (values, helpers) => {
82
+ try {
83
+ const res = await createLocale(values);
84
+ if ("error" in res) {
85
+ if (index.isBaseQueryError(res.error) && res.error.name === "ValidationError") {
86
+ helpers.setErrors(formatValidationErrors(res.error));
87
+ } else {
88
+ toggleNotification({ type: "danger", message: formatAPIError(res.error) });
89
+ }
90
+ return;
91
+ }
92
+ toggleNotification({
93
+ type: "success",
94
+ message: formatMessage({
95
+ id: index.getTranslation("Settings.locales.modal.create.success"),
96
+ defaultMessage: "Created locale"
97
+ })
98
+ });
99
+ refetchPermissions();
100
+ onClose();
101
+ } catch (err) {
102
+ toggleNotification({
103
+ type: "danger",
104
+ message: formatMessage({
105
+ id: "notification.error",
106
+ defaultMessage: "An error occurred, please try again"
107
+ })
108
+ });
109
+ }
110
+ };
111
+ const titleId = React__namespace.useId();
112
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalLayout, { onClose, labelledBy: titleId, children: /* @__PURE__ */ jsxRuntime.jsxs(
113
+ strapiAdmin.Form,
114
+ {
115
+ method: "POST",
116
+ initialValues: initialFormValues,
117
+ validationSchema: LOCALE_SCHEMA,
118
+ onSubmit: handleSubmit,
119
+ children: [
120
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "bold", textColor: "neutral800", as: "h2", id: titleId, children: formatMessage({
121
+ id: index.getTranslation("Settings.list.actions.add"),
122
+ defaultMessage: "Add new locale"
123
+ }) }) }),
124
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalBody, { children: /* @__PURE__ */ jsxRuntime.jsxs(
125
+ designSystem.TabGroup,
126
+ {
127
+ label: formatMessage({
128
+ id: index.getTranslation("Settings.locales.modal.title"),
129
+ defaultMessage: "Configurations"
130
+ }),
131
+ variant: "simple",
132
+ children: [
133
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", children: [
134
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { as: "h2", variant: "beta", children: formatMessage({
135
+ id: index.getTranslation("Settings.locales.modal.title"),
136
+ defaultMessage: "Configuration"
137
+ }) }),
138
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tabs, { children: [
139
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tab, { children: formatMessage({
140
+ id: index.getTranslation("Settings.locales.modal.base"),
141
+ defaultMessage: "Basic settings"
142
+ }) }),
143
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tab, { children: formatMessage({
144
+ id: index.getTranslation("Settings.locales.modal.advanced"),
145
+ defaultMessage: "Advanced settings"
146
+ }) })
147
+ ] })
148
+ ] }),
149
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, {}),
150
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 7, paddingBottom: 7, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.TabPanels, { children: [
151
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.TabPanel, { children: /* @__PURE__ */ jsxRuntime.jsx(BaseForm, {}) }),
152
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.TabPanel, { children: /* @__PURE__ */ jsxRuntime.jsx(AdvancedForm, {}) })
153
+ ] }) })
154
+ ]
155
+ }
156
+ ) }),
157
+ /* @__PURE__ */ jsxRuntime.jsx(
158
+ designSystem.ModalFooter,
159
+ {
160
+ startActions: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", onClick: onClose, children: formatMessage({ id: "app.components.Button.cancel", defaultMessage: "Cancel" }) }),
161
+ endActions: /* @__PURE__ */ jsxRuntime.jsx(SubmitButton, {})
162
+ }
163
+ )
164
+ ]
165
+ }
166
+ ) });
167
+ };
168
+ const SubmitButton = () => {
169
+ const { formatMessage } = reactIntl.useIntl();
170
+ const isSubmitting = strapiAdmin.useForm("SubmitButton", (state) => state.isSubmitting);
171
+ const modified = strapiAdmin.useForm("SubmitButton", (state) => state.modified);
172
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { type: "submit", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}), disabled: isSubmitting || !modified, children: formatMessage({ id: "global.save", defaultMessage: "Save" }) });
173
+ };
174
+ const BaseForm = ({ mode = "create" }) => {
175
+ const { formatMessage } = reactIntl.useIntl();
176
+ const { toggleNotification } = strapiAdmin.useNotification();
177
+ const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
178
+ const { data: defaultLocales = [], error } = index.useGetDefaultLocalesQuery();
179
+ const { data: locales = [] } = index.useGetLocalesQuery();
180
+ React__namespace.useEffect(() => {
181
+ if (error) {
182
+ toggleNotification({
183
+ type: "danger",
184
+ message: formatAPIError(error)
185
+ });
186
+ }
187
+ }, [error, formatAPIError, toggleNotification]);
188
+ if (!Array.isArray(defaultLocales) || !Array.isArray(locales)) {
189
+ return null;
190
+ }
191
+ const options = defaultLocales.map((locale) => ({
192
+ label: locale.name,
193
+ value: locale.code
194
+ }));
195
+ const translatedForm = [
196
+ {
197
+ disabled: mode !== "create",
198
+ label: {
199
+ id: index.getTranslation("Settings.locales.modal.create.code.label"),
200
+ defaultMessage: "Locales"
201
+ },
202
+ name: "code",
203
+ options,
204
+ placeholder: {
205
+ id: "components.placeholder.select",
206
+ defaultMessage: "Select"
207
+ },
208
+ required: true,
209
+ size: 6,
210
+ type: "enumeration"
211
+ },
212
+ {
213
+ hint: {
214
+ id: index.getTranslation("Settings.locales.modal.create.name.label.description"),
215
+ defaultMessage: "Locale will be displayed under that name in the administration panel"
216
+ },
217
+ label: {
218
+ id: index.getTranslation("Settings.locales.modal.create.name.label"),
219
+ defaultMessage: "Locale display name"
220
+ },
221
+ name: "name",
222
+ required: true,
223
+ size: 6,
224
+ type: "string"
225
+ }
226
+ ].map((field) => ({
227
+ ...field,
228
+ hint: field.hint ? formatMessage(field.hint) : void 0,
229
+ label: formatMessage(field.label),
230
+ placeholder: field.placeholder ? formatMessage(field.placeholder) : void 0
231
+ }));
232
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid, { gap: 4, children: translatedForm.map(({ size, ...field }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: size, children: /* @__PURE__ */ jsxRuntime.jsx(FormRenderer, { ...field }) }, field.name)) });
233
+ };
234
+ const AdvancedForm = ({ isDefaultLocale }) => {
235
+ const { formatMessage } = reactIntl.useIntl();
236
+ const form = [
237
+ {
238
+ disabled: isDefaultLocale,
239
+ hint: {
240
+ id: index.getTranslation("Settings.locales.modal.advanced.setAsDefault.hint"),
241
+ defaultMessage: "One default locale is required, change it by selecting another one"
242
+ },
243
+ label: {
244
+ id: index.getTranslation("Settings.locales.modal.advanced.setAsDefault"),
245
+ defaultMessage: "Set as default locale"
246
+ },
247
+ name: "isDefault",
248
+ size: 6,
249
+ type: "boolean"
250
+ }
251
+ ].map((field) => ({
252
+ ...field,
253
+ hint: field.hint ? formatMessage(field.hint) : void 0,
254
+ label: formatMessage(field.label)
255
+ }));
256
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid, { gap: 4, children: form.map(({ size, ...field }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: size, children: /* @__PURE__ */ jsxRuntime.jsx(FormRenderer, { ...field }) }, field.name)) });
257
+ };
258
+ const FormRenderer = (field) => {
259
+ switch (field.type) {
260
+ case "enumeration":
261
+ return /* @__PURE__ */ jsxRuntime.jsx(EnumerationInput, { ...field });
262
+ default:
263
+ return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.InputRenderer, { ...field });
264
+ }
265
+ };
266
+ const EnumerationInput = ({
267
+ disabled,
268
+ hint,
269
+ label,
270
+ name,
271
+ options,
272
+ placeholder,
273
+ required
274
+ }) => {
275
+ const { value, error, onChange } = strapiAdmin.useField(name);
276
+ const { data: defaultLocales = [] } = index.useGetDefaultLocalesQuery();
277
+ const handleChange = (value2) => {
278
+ if (Array.isArray(defaultLocales)) {
279
+ const locale = defaultLocales.find((locale2) => locale2.code === value2);
280
+ onChange(name, value2);
281
+ onChange("name", locale.name);
282
+ } else {
283
+ onChange(name, value2);
284
+ }
285
+ };
286
+ return /* @__PURE__ */ jsxRuntime.jsx(
287
+ designSystem.SingleSelect,
288
+ {
289
+ disabled,
290
+ error,
291
+ hint,
292
+ label,
293
+ name,
294
+ onChange: handleChange,
295
+ placeholder,
296
+ required,
297
+ value,
298
+ children: options.map((option) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: option.value, children: option.label }, option.value))
299
+ }
300
+ );
301
+ };
302
+ const DeleteLocale = ({ id, name }) => {
303
+ const { formatMessage } = reactIntl.useIntl();
304
+ const { toggleNotification } = strapiAdmin.useNotification();
305
+ const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
306
+ const [visible, setVisible] = React__namespace.useState(false);
307
+ const [deleteLocale] = index.useDeleteLocaleMutation();
308
+ const handleConfirm = async () => {
309
+ try {
310
+ const res = await deleteLocale(id);
311
+ if ("error" in res) {
312
+ toggleNotification({ type: "danger", message: formatAPIError(res.error) });
313
+ return;
314
+ }
315
+ toggleNotification({
316
+ type: "success",
317
+ message: formatMessage({
318
+ id: index.getTranslation("Settings.locales.modal.delete.success"),
319
+ defaultMessage: "Deleted locale"
320
+ })
321
+ });
322
+ } catch (err) {
323
+ toggleNotification({
324
+ type: "danger",
325
+ message: formatMessage({
326
+ id: "notification.error",
327
+ defaultMessage: "An error occurred, please try again"
328
+ })
329
+ });
330
+ }
331
+ };
332
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
333
+ /* @__PURE__ */ jsxRuntime.jsx(
334
+ designSystem.IconButton,
335
+ {
336
+ onClick: () => setVisible(true),
337
+ label: formatMessage(
338
+ {
339
+ id: index.getTranslation("Settings.list.actions.delete"),
340
+ defaultMessage: "Delete {name} locale"
341
+ },
342
+ {
343
+ name
344
+ }
345
+ ),
346
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
347
+ borderWidth: 0
348
+ }
349
+ ),
350
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.ConfirmDialog, { onConfirm: handleConfirm, onClose: () => setVisible(false), isOpen: visible })
351
+ ] });
352
+ };
353
+ const EditLocale = (props) => {
354
+ const { formatMessage } = reactIntl.useIntl();
355
+ const [visible, setVisible] = React__namespace.useState(false);
356
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
357
+ /* @__PURE__ */ jsxRuntime.jsx(
358
+ designSystem.IconButton,
359
+ {
360
+ onClick: () => setVisible(true),
361
+ label: formatMessage(
362
+ {
363
+ id: index.getTranslation("Settings.list.actions.edit"),
364
+ defaultMessage: "Edit {name} locale"
365
+ },
366
+ {
367
+ name: props.name
368
+ }
369
+ ),
370
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Pencil, {}),
371
+ borderWidth: 0
372
+ }
373
+ ),
374
+ visible ? /* @__PURE__ */ jsxRuntime.jsx(EditModal, { ...props, onClose: () => setVisible(false) }) : null
375
+ ] });
376
+ };
377
+ const EditModal = ({ id, code, isDefault, name, onClose }) => {
378
+ const { toggleNotification } = strapiAdmin.useNotification();
379
+ const {
380
+ _unstableFormatAPIError: formatAPIError,
381
+ _unstableFormatValidationErrors: formatValidationErrors
382
+ } = strapiAdmin.useAPIErrorHandler();
383
+ const refetchPermissions = strapiAdmin.useAuth("EditModal", (state) => state.refetchPermissions);
384
+ const { formatMessage } = reactIntl.useIntl();
385
+ const titleId = React__namespace.useId();
386
+ const [updateLocale] = index.useUpdateLocaleMutation();
387
+ const handleSubmit = async ({ code: _code, ...data }, helpers) => {
388
+ try {
389
+ const res = await updateLocale({
390
+ id,
391
+ ...data
392
+ });
393
+ if ("error" in res) {
394
+ if (index.isBaseQueryError(res.error) && res.error.name === "ValidationError") {
395
+ helpers.setErrors(formatValidationErrors(res.error));
396
+ } else {
397
+ toggleNotification({ type: "danger", message: formatAPIError(res.error) });
398
+ }
399
+ return;
400
+ }
401
+ toggleNotification({
402
+ type: "success",
403
+ message: formatMessage({
404
+ id: index.getTranslation("Settings.locales.modal.edit.success"),
405
+ defaultMessage: "Updated locale"
406
+ })
407
+ });
408
+ refetchPermissions();
409
+ onClose();
410
+ } catch (err) {
411
+ toggleNotification({
412
+ type: "danger",
413
+ message: formatMessage({
414
+ id: "notification.error",
415
+ defaultMessage: "An error occurred, please try again"
416
+ })
417
+ });
418
+ }
419
+ };
420
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalLayout, { onClose, labelledBy: titleId, children: /* @__PURE__ */ jsxRuntime.jsxs(
421
+ strapiAdmin.Form,
422
+ {
423
+ method: "PUT",
424
+ onSubmit: handleSubmit,
425
+ initialValues: {
426
+ code,
427
+ name,
428
+ isDefault
429
+ },
430
+ validationSchema: LOCALE_SCHEMA,
431
+ children: [
432
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "bold", textColor: "neutral800", as: "h2", id: titleId, children: formatMessage({
433
+ id: index.getTranslation("Settings.list.actions.edit"),
434
+ defaultMessage: "Edit a locale"
435
+ }) }) }),
436
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalBody, { children: /* @__PURE__ */ jsxRuntime.jsxs(
437
+ designSystem.TabGroup,
438
+ {
439
+ label: formatMessage({
440
+ id: index.getTranslation("Settings.locales.modal.title"),
441
+ defaultMessage: "Configurations"
442
+ }),
443
+ variant: "simple",
444
+ children: [
445
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", children: [
446
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { as: "h2", variant: "beta", children: formatMessage({
447
+ id: index.getTranslation("Settings.locales.modal.title"),
448
+ defaultMessage: "Configuration"
449
+ }) }),
450
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tabs, { children: [
451
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tab, { children: formatMessage({
452
+ id: index.getTranslation("Settings.locales.modal.base"),
453
+ defaultMessage: "Basic settings"
454
+ }) }),
455
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tab, { children: formatMessage({
456
+ id: index.getTranslation("Settings.locales.modal.advanced"),
457
+ defaultMessage: "Advanced settings"
458
+ }) })
459
+ ] })
460
+ ] }),
461
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, {}),
462
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 7, paddingBottom: 7, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.TabPanels, { children: [
463
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.TabPanel, { children: /* @__PURE__ */ jsxRuntime.jsx(BaseForm, { mode: "edit" }) }),
464
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.TabPanel, { children: /* @__PURE__ */ jsxRuntime.jsx(AdvancedForm, { isDefaultLocale: isDefault }) })
465
+ ] }) })
466
+ ]
467
+ }
468
+ ) }),
469
+ /* @__PURE__ */ jsxRuntime.jsx(
470
+ designSystem.ModalFooter,
471
+ {
472
+ startActions: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", onClick: onClose, children: formatMessage({ id: "app.components.Button.cancel", defaultMessage: "Cancel" }) }),
473
+ endActions: /* @__PURE__ */ jsxRuntime.jsx(SubmitButton, {})
474
+ }
475
+ )
476
+ ]
477
+ }
478
+ ) });
479
+ };
480
+ const LocaleTable = ({ locales = [], canDelete, canUpdate }) => {
481
+ const [editLocaleId, setEditLocaleId] = React__namespace.useState();
482
+ const { formatMessage } = reactIntl.useIntl();
483
+ const handleClick = (localeId) => () => {
484
+ if (canUpdate) {
485
+ setEditLocaleId(localeId);
486
+ }
487
+ };
488
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Table, { colCount: 4, rowCount: locales.length + 1, children: [
489
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Thead, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
490
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
491
+ id: index.getTranslation("Settings.locales.row.id"),
492
+ defaultMessage: "ID"
493
+ }) }) }),
494
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
495
+ id: index.getTranslation("Settings.locales.row.displayName"),
496
+ defaultMessage: "Display name"
497
+ }) }) }),
498
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
499
+ id: index.getTranslation("Settings.locales.row.default-locale"),
500
+ defaultMessage: "Default locale"
501
+ }) }) }),
502
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { children: "Actions" }) })
503
+ ] }) }),
504
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: locales.map((locale) => /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Fragment, { children: [
505
+ /* @__PURE__ */ jsxRuntime.jsxs(
506
+ designSystem.Tr,
507
+ {
508
+ onClick: handleClick(locale.id),
509
+ style: { cursor: canUpdate ? "pointer" : "default" },
510
+ children: [
511
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", children: locale.id }) }),
512
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", children: locale.name }) }),
513
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", children: locale.isDefault ? formatMessage({
514
+ id: index.getTranslation("Settings.locales.default"),
515
+ defaultMessage: "Default"
516
+ }) : null }) }),
517
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, justifyContent: "flex-end", onClick: (e) => e.stopPropagation(), children: [
518
+ canUpdate && /* @__PURE__ */ jsxRuntime.jsx(EditLocale, { ...locale }),
519
+ canDelete && !locale.isDefault && /* @__PURE__ */ jsxRuntime.jsx(DeleteLocale, { ...locale })
520
+ ] }) })
521
+ ]
522
+ }
523
+ ),
524
+ editLocaleId === locale.id ? /* @__PURE__ */ jsxRuntime.jsx(EditModal, { ...locale, onClose: () => setEditLocaleId(void 0) }) : null
525
+ ] }, locale.id)) })
526
+ ] });
527
+ };
528
+ const SettingsPage = () => {
529
+ const { formatMessage } = reactIntl.useIntl();
530
+ const { toggleNotification } = strapiAdmin.useNotification();
531
+ const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
532
+ const { data: locales, isLoading: isLoadingLocales, error } = index.useGetLocalesQuery();
533
+ const {
534
+ isLoading: isLoadingRBAC,
535
+ allowedActions: { canUpdate, canCreate, canDelete }
536
+ } = strapiAdmin.useRBAC(index.PERMISSIONS);
537
+ React__namespace.useEffect(() => {
538
+ if (error) {
539
+ toggleNotification({
540
+ type: "danger",
541
+ message: formatAPIError(error)
542
+ });
543
+ }
544
+ }, [error, formatAPIError, toggleNotification]);
545
+ const isLoading = isLoadingLocales || isLoadingRBAC;
546
+ if (isLoading) {
547
+ return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Loading, {});
548
+ }
549
+ if (error || !Array.isArray(locales)) {
550
+ return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Error, {});
551
+ }
552
+ return /* @__PURE__ */ jsxRuntime.jsxs(strapiAdmin.Page.Main, { tabIndex: -1, children: [
553
+ /* @__PURE__ */ jsxRuntime.jsx(
554
+ designSystem.HeaderLayout,
555
+ {
556
+ primaryAction: /* @__PURE__ */ jsxRuntime.jsx(CreateLocale, { disabled: !canCreate }),
557
+ title: formatMessage({
558
+ id: index.getTranslation("plugin.name"),
559
+ defaultMessage: "Internationalization"
560
+ }),
561
+ subtitle: formatMessage({
562
+ id: index.getTranslation("Settings.list.description"),
563
+ defaultMessage: "Configure the settings"
564
+ })
565
+ }
566
+ ),
567
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.ContentLayout, { children: locales.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(LocaleTable, { locales, canDelete, canUpdate }) : /* @__PURE__ */ jsxRuntime.jsx(
568
+ designSystem.EmptyStateLayout,
569
+ {
570
+ icon: /* @__PURE__ */ jsxRuntime.jsx(symbols.EmptyDocuments, { width: void 0, height: void 0 }),
571
+ content: formatMessage({
572
+ id: index.getTranslation("Settings.list.empty.title"),
573
+ defaultMessage: "There are no locales"
574
+ }),
575
+ action: /* @__PURE__ */ jsxRuntime.jsx(CreateLocale, { disabled: !canCreate, variant: "secondary" })
576
+ }
577
+ ) })
578
+ ] });
579
+ };
580
+ const ProtectedSettingsPage = () => {
581
+ return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Protect, { permissions: index.PERMISSIONS.read, children: /* @__PURE__ */ jsxRuntime.jsx(SettingsPage, {}) });
582
+ };
583
+ exports.ProtectedSettingsPage = ProtectedSettingsPage;
584
+ exports.SettingsPage = SettingsPage;
585
+ //# sourceMappingURL=SettingsPage-B73NO_8-.js.map