@strapi/i18n 0.0.0 → 5.0.0-beta.7

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-BvzzUueI.js +584 -0
  3. package/dist/_chunks/SettingsPage-BvzzUueI.js.map +1 -0
  4. package/dist/_chunks/SettingsPage-CB5yd4O3.mjs +564 -0
  5. package/dist/_chunks/SettingsPage-CB5yd4O3.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-DRjoX_5r.js +1084 -0
  27. package/dist/_chunks/index-DRjoX_5r.js.map +1 -0
  28. package/dist/_chunks/index-aiqKWFfV.mjs +1061 -0
  29. package/dist/_chunks/index-aiqKWFfV.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 +19 -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 +82 -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,584 @@
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-DRjoX_5r.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", tag: "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, { tag: "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
+ React__namespace.useEffect(() => {
180
+ if (error) {
181
+ toggleNotification({
182
+ type: "danger",
183
+ message: formatAPIError(error)
184
+ });
185
+ }
186
+ }, [error, formatAPIError, toggleNotification]);
187
+ if (!Array.isArray(defaultLocales)) {
188
+ return null;
189
+ }
190
+ const options = defaultLocales.map((locale) => ({
191
+ label: locale.name,
192
+ value: locale.code
193
+ }));
194
+ const translatedForm = [
195
+ {
196
+ disabled: mode !== "create",
197
+ label: {
198
+ id: index.getTranslation("Settings.locales.modal.create.code.label"),
199
+ defaultMessage: "Locales"
200
+ },
201
+ name: "code",
202
+ options,
203
+ placeholder: {
204
+ id: "components.placeholder.select",
205
+ defaultMessage: "Select"
206
+ },
207
+ required: true,
208
+ size: 6,
209
+ type: "enumeration"
210
+ },
211
+ {
212
+ hint: {
213
+ id: index.getTranslation("Settings.locales.modal.create.name.label.description"),
214
+ defaultMessage: "Locale will be displayed under that name in the administration panel"
215
+ },
216
+ label: {
217
+ id: index.getTranslation("Settings.locales.modal.create.name.label"),
218
+ defaultMessage: "Locale display name"
219
+ },
220
+ name: "name",
221
+ required: true,
222
+ size: 6,
223
+ type: "string"
224
+ }
225
+ ].map((field) => ({
226
+ ...field,
227
+ hint: field.hint ? formatMessage(field.hint) : void 0,
228
+ label: formatMessage(field.label),
229
+ placeholder: field.placeholder ? formatMessage(field.placeholder) : void 0
230
+ }));
231
+ 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)) });
232
+ };
233
+ const AdvancedForm = ({ isDefaultLocale }) => {
234
+ const { formatMessage } = reactIntl.useIntl();
235
+ const form = [
236
+ {
237
+ disabled: isDefaultLocale,
238
+ hint: {
239
+ id: index.getTranslation("Settings.locales.modal.advanced.setAsDefault.hint"),
240
+ defaultMessage: "One default locale is required, change it by selecting another one"
241
+ },
242
+ label: {
243
+ id: index.getTranslation("Settings.locales.modal.advanced.setAsDefault"),
244
+ defaultMessage: "Set as default locale"
245
+ },
246
+ name: "isDefault",
247
+ size: 6,
248
+ type: "boolean"
249
+ }
250
+ ].map((field) => ({
251
+ ...field,
252
+ hint: field.hint ? formatMessage(field.hint) : void 0,
253
+ label: formatMessage(field.label)
254
+ }));
255
+ 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)) });
256
+ };
257
+ const FormRenderer = (field) => {
258
+ switch (field.type) {
259
+ case "enumeration":
260
+ return /* @__PURE__ */ jsxRuntime.jsx(EnumerationInput, { ...field });
261
+ default:
262
+ return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.InputRenderer, { ...field });
263
+ }
264
+ };
265
+ const EnumerationInput = ({
266
+ disabled,
267
+ hint,
268
+ label,
269
+ name,
270
+ options,
271
+ placeholder,
272
+ required
273
+ }) => {
274
+ const { value, error, onChange } = strapiAdmin.useField(name);
275
+ const { data: defaultLocales = [] } = index.useGetDefaultLocalesQuery();
276
+ const handleChange = (value2) => {
277
+ if (Array.isArray(defaultLocales)) {
278
+ const locale = defaultLocales.find((locale2) => locale2.code === value2);
279
+ onChange(name, value2);
280
+ onChange("name", locale.name);
281
+ } else {
282
+ onChange(name, value2);
283
+ }
284
+ };
285
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { error, hint, name, required, children: [
286
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: label }),
287
+ /* @__PURE__ */ jsxRuntime.jsx(
288
+ designSystem.SingleSelect,
289
+ {
290
+ disabled,
291
+ onChange: handleChange,
292
+ placeholder,
293
+ value,
294
+ children: options.map((option) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: option.value, children: option.label }, option.value))
295
+ }
296
+ ),
297
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {}),
298
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {})
299
+ ] });
300
+ };
301
+ const DeleteLocale = ({ id, name }) => {
302
+ const { formatMessage } = reactIntl.useIntl();
303
+ const { toggleNotification } = strapiAdmin.useNotification();
304
+ const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
305
+ const [visible, setVisible] = React__namespace.useState(false);
306
+ const [deleteLocale] = index.useDeleteLocaleMutation();
307
+ const handleConfirm = async () => {
308
+ try {
309
+ const res = await deleteLocale(id);
310
+ if ("error" in res) {
311
+ toggleNotification({ type: "danger", message: formatAPIError(res.error) });
312
+ return;
313
+ }
314
+ toggleNotification({
315
+ type: "success",
316
+ message: formatMessage({
317
+ id: index.getTranslation("Settings.locales.modal.delete.success"),
318
+ defaultMessage: "Deleted locale"
319
+ })
320
+ });
321
+ } catch (err) {
322
+ toggleNotification({
323
+ type: "danger",
324
+ message: formatMessage({
325
+ id: "notification.error",
326
+ defaultMessage: "An error occurred, please try again"
327
+ })
328
+ });
329
+ }
330
+ };
331
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
332
+ /* @__PURE__ */ jsxRuntime.jsx(
333
+ designSystem.IconButton,
334
+ {
335
+ onClick: () => setVisible(true),
336
+ label: formatMessage(
337
+ {
338
+ id: index.getTranslation("Settings.list.actions.delete"),
339
+ defaultMessage: "Delete {name} locale"
340
+ },
341
+ {
342
+ name
343
+ }
344
+ ),
345
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
346
+ borderWidth: 0
347
+ }
348
+ ),
349
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.ConfirmDialog, { onConfirm: handleConfirm, onClose: () => setVisible(false), isOpen: visible })
350
+ ] });
351
+ };
352
+ const EditLocale = (props) => {
353
+ const { formatMessage } = reactIntl.useIntl();
354
+ const [visible, setVisible] = React__namespace.useState(false);
355
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
356
+ /* @__PURE__ */ jsxRuntime.jsx(
357
+ designSystem.IconButton,
358
+ {
359
+ onClick: () => setVisible(true),
360
+ label: formatMessage(
361
+ {
362
+ id: index.getTranslation("Settings.list.actions.edit"),
363
+ defaultMessage: "Edit {name} locale"
364
+ },
365
+ {
366
+ name: props.name
367
+ }
368
+ ),
369
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Pencil, {}),
370
+ borderWidth: 0
371
+ }
372
+ ),
373
+ visible ? /* @__PURE__ */ jsxRuntime.jsx(EditModal, { ...props, onClose: () => setVisible(false) }) : null
374
+ ] });
375
+ };
376
+ const EditModal = ({ id, code, isDefault, name, onClose }) => {
377
+ const { toggleNotification } = strapiAdmin.useNotification();
378
+ const {
379
+ _unstableFormatAPIError: formatAPIError,
380
+ _unstableFormatValidationErrors: formatValidationErrors
381
+ } = strapiAdmin.useAPIErrorHandler();
382
+ const refetchPermissions = strapiAdmin.useAuth("EditModal", (state) => state.refetchPermissions);
383
+ const { formatMessage } = reactIntl.useIntl();
384
+ const titleId = React__namespace.useId();
385
+ const [updateLocale] = index.useUpdateLocaleMutation();
386
+ const handleSubmit = async ({ code: _code, ...data }, helpers) => {
387
+ try {
388
+ const res = await updateLocale({
389
+ id,
390
+ ...data
391
+ });
392
+ if ("error" in res) {
393
+ if (index.isBaseQueryError(res.error) && res.error.name === "ValidationError") {
394
+ helpers.setErrors(formatValidationErrors(res.error));
395
+ } else {
396
+ toggleNotification({ type: "danger", message: formatAPIError(res.error) });
397
+ }
398
+ return;
399
+ }
400
+ toggleNotification({
401
+ type: "success",
402
+ message: formatMessage({
403
+ id: index.getTranslation("Settings.locales.modal.edit.success"),
404
+ defaultMessage: "Updated locale"
405
+ })
406
+ });
407
+ refetchPermissions();
408
+ onClose();
409
+ } catch (err) {
410
+ toggleNotification({
411
+ type: "danger",
412
+ message: formatMessage({
413
+ id: "notification.error",
414
+ defaultMessage: "An error occurred, please try again"
415
+ })
416
+ });
417
+ }
418
+ };
419
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalLayout, { onClose, labelledBy: titleId, children: /* @__PURE__ */ jsxRuntime.jsxs(
420
+ strapiAdmin.Form,
421
+ {
422
+ method: "PUT",
423
+ onSubmit: handleSubmit,
424
+ initialValues: {
425
+ code,
426
+ name,
427
+ isDefault
428
+ },
429
+ validationSchema: LOCALE_SCHEMA,
430
+ children: [
431
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "bold", textColor: "neutral800", tag: "h2", id: titleId, children: formatMessage({
432
+ id: index.getTranslation("Settings.list.actions.edit"),
433
+ defaultMessage: "Edit a locale"
434
+ }) }) }),
435
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.ModalBody, { children: /* @__PURE__ */ jsxRuntime.jsxs(
436
+ designSystem.TabGroup,
437
+ {
438
+ label: formatMessage({
439
+ id: index.getTranslation("Settings.locales.modal.title"),
440
+ defaultMessage: "Configurations"
441
+ }),
442
+ variant: "simple",
443
+ children: [
444
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", children: [
445
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "h2", variant: "beta", children: formatMessage({
446
+ id: index.getTranslation("Settings.locales.modal.title"),
447
+ defaultMessage: "Configuration"
448
+ }) }),
449
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tabs, { children: [
450
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tab, { children: formatMessage({
451
+ id: index.getTranslation("Settings.locales.modal.base"),
452
+ defaultMessage: "Basic settings"
453
+ }) }),
454
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tab, { children: formatMessage({
455
+ id: index.getTranslation("Settings.locales.modal.advanced"),
456
+ defaultMessage: "Advanced settings"
457
+ }) })
458
+ ] })
459
+ ] }),
460
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, {}),
461
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 7, paddingBottom: 7, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.TabPanels, { children: [
462
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.TabPanel, { children: /* @__PURE__ */ jsxRuntime.jsx(BaseForm, { mode: "edit" }) }),
463
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.TabPanel, { children: /* @__PURE__ */ jsxRuntime.jsx(AdvancedForm, { isDefaultLocale: isDefault }) })
464
+ ] }) })
465
+ ]
466
+ }
467
+ ) }),
468
+ /* @__PURE__ */ jsxRuntime.jsx(
469
+ designSystem.ModalFooter,
470
+ {
471
+ startActions: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", onClick: onClose, children: formatMessage({ id: "app.components.Button.cancel", defaultMessage: "Cancel" }) }),
472
+ endActions: /* @__PURE__ */ jsxRuntime.jsx(SubmitButton, {})
473
+ }
474
+ )
475
+ ]
476
+ }
477
+ ) });
478
+ };
479
+ const LocaleTable = ({ locales = [], canDelete, canUpdate }) => {
480
+ const [editLocaleId, setEditLocaleId] = React__namespace.useState();
481
+ const { formatMessage } = reactIntl.useIntl();
482
+ const handleClick = (localeId) => () => {
483
+ if (canUpdate) {
484
+ setEditLocaleId(localeId);
485
+ }
486
+ };
487
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Table, { colCount: 4, rowCount: locales.length + 1, children: [
488
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Thead, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
489
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
490
+ id: index.getTranslation("Settings.locales.row.id"),
491
+ defaultMessage: "ID"
492
+ }) }) }),
493
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
494
+ id: index.getTranslation("Settings.locales.row.displayName"),
495
+ defaultMessage: "Display name"
496
+ }) }) }),
497
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
498
+ id: index.getTranslation("Settings.locales.row.default-locale"),
499
+ defaultMessage: "Default locale"
500
+ }) }) }),
501
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { children: "Actions" }) })
502
+ ] }) }),
503
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: locales.map((locale) => /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Fragment, { children: [
504
+ /* @__PURE__ */ jsxRuntime.jsxs(
505
+ designSystem.Tr,
506
+ {
507
+ onClick: handleClick(locale.id),
508
+ style: { cursor: canUpdate ? "pointer" : "default" },
509
+ children: [
510
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", children: locale.id }) }),
511
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", children: locale.name }) }),
512
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", children: locale.isDefault ? formatMessage({
513
+ id: index.getTranslation("Settings.locales.default"),
514
+ defaultMessage: "Default"
515
+ }) : null }) }),
516
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, justifyContent: "flex-end", onClick: (e) => e.stopPropagation(), children: [
517
+ canUpdate && /* @__PURE__ */ jsxRuntime.jsx(EditLocale, { ...locale }),
518
+ canDelete && !locale.isDefault && /* @__PURE__ */ jsxRuntime.jsx(DeleteLocale, { ...locale })
519
+ ] }) })
520
+ ]
521
+ }
522
+ ),
523
+ editLocaleId === locale.id ? /* @__PURE__ */ jsxRuntime.jsx(EditModal, { ...locale, onClose: () => setEditLocaleId(void 0) }) : null
524
+ ] }, locale.id)) })
525
+ ] });
526
+ };
527
+ const SettingsPage = () => {
528
+ const { formatMessage } = reactIntl.useIntl();
529
+ const { toggleNotification } = strapiAdmin.useNotification();
530
+ const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
531
+ const { data: locales, isLoading: isLoadingLocales, error } = index.useGetLocalesQuery();
532
+ const {
533
+ isLoading: isLoadingRBAC,
534
+ allowedActions: { canUpdate, canCreate, canDelete }
535
+ } = strapiAdmin.useRBAC(index.PERMISSIONS);
536
+ React__namespace.useEffect(() => {
537
+ if (error) {
538
+ toggleNotification({
539
+ type: "danger",
540
+ message: formatAPIError(error)
541
+ });
542
+ }
543
+ }, [error, formatAPIError, toggleNotification]);
544
+ const isLoading = isLoadingLocales || isLoadingRBAC;
545
+ if (isLoading) {
546
+ return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Loading, {});
547
+ }
548
+ if (error || !Array.isArray(locales)) {
549
+ return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Error, {});
550
+ }
551
+ return /* @__PURE__ */ jsxRuntime.jsxs(strapiAdmin.Page.Main, { tabIndex: -1, children: [
552
+ /* @__PURE__ */ jsxRuntime.jsx(
553
+ strapiAdmin.Layouts.Header,
554
+ {
555
+ primaryAction: /* @__PURE__ */ jsxRuntime.jsx(CreateLocale, { disabled: !canCreate }),
556
+ title: formatMessage({
557
+ id: index.getTranslation("plugin.name"),
558
+ defaultMessage: "Internationalization"
559
+ }),
560
+ subtitle: formatMessage({
561
+ id: index.getTranslation("Settings.list.description"),
562
+ defaultMessage: "Configure the settings"
563
+ })
564
+ }
565
+ ),
566
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Layouts.Content, { children: locales.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(LocaleTable, { locales, canDelete, canUpdate }) : /* @__PURE__ */ jsxRuntime.jsx(
567
+ designSystem.EmptyStateLayout,
568
+ {
569
+ icon: /* @__PURE__ */ jsxRuntime.jsx(symbols.EmptyDocuments, { width: void 0, height: void 0 }),
570
+ content: formatMessage({
571
+ id: index.getTranslation("Settings.list.empty.title"),
572
+ defaultMessage: "There are no locales"
573
+ }),
574
+ action: /* @__PURE__ */ jsxRuntime.jsx(CreateLocale, { disabled: !canCreate, variant: "secondary" })
575
+ }
576
+ ) })
577
+ ] });
578
+ };
579
+ const ProtectedSettingsPage = () => {
580
+ return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Protect, { permissions: index.PERMISSIONS.read, children: /* @__PURE__ */ jsxRuntime.jsx(SettingsPage, {}) });
581
+ };
582
+ exports.ProtectedSettingsPage = ProtectedSettingsPage;
583
+ exports.SettingsPage = SettingsPage;
584
+ //# sourceMappingURL=SettingsPage-BvzzUueI.js.map