@strapi/i18n 0.0.0-experimental.e9144fc8a193f9875a2c0832d689c14001c79f00 → 0.0.0-experimental.e99215433ba1d6e5497350812df274f426dbdba3
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/dist/admin/components/BulkLocaleActionModal.js +262 -0
- package/dist/admin/components/BulkLocaleActionModal.js.map +1 -0
- package/dist/admin/components/BulkLocaleActionModal.mjs +260 -0
- package/dist/admin/components/BulkLocaleActionModal.mjs.map +1 -0
- package/dist/admin/components/CMHeaderActions.js +836 -0
- package/dist/admin/components/CMHeaderActions.js.map +1 -0
- package/dist/admin/components/CMHeaderActions.mjs +810 -0
- package/dist/admin/components/CMHeaderActions.mjs.map +1 -0
- package/dist/admin/components/CMListViewModalsAdditionalInformation.js +69 -0
- package/dist/admin/components/CMListViewModalsAdditionalInformation.js.map +1 -0
- package/dist/admin/components/CMListViewModalsAdditionalInformation.mjs +65 -0
- package/dist/admin/components/CMListViewModalsAdditionalInformation.mjs.map +1 -0
- package/dist/admin/components/CheckboxConfirmation.js +155 -0
- package/dist/admin/components/CheckboxConfirmation.js.map +1 -0
- package/dist/admin/components/CheckboxConfirmation.mjs +134 -0
- package/dist/admin/components/CheckboxConfirmation.mjs.map +1 -0
- package/dist/admin/components/CreateLocale.js +395 -0
- package/dist/admin/components/CreateLocale.js.map +1 -0
- package/dist/admin/components/CreateLocale.mjs +369 -0
- package/dist/admin/components/CreateLocale.mjs.map +1 -0
- package/dist/admin/components/DeleteLocale.js +90 -0
- package/dist/admin/components/DeleteLocale.js.map +1 -0
- package/dist/admin/components/DeleteLocale.mjs +69 -0
- package/dist/admin/components/DeleteLocale.mjs.map +1 -0
- package/dist/admin/components/EditLocale.js +212 -0
- package/dist/admin/components/EditLocale.js.map +1 -0
- package/dist/admin/components/EditLocale.mjs +190 -0
- package/dist/admin/components/EditLocale.mjs.map +1 -0
- package/dist/admin/components/LocaleListCell.js +102 -0
- package/dist/admin/components/LocaleListCell.js.map +1 -0
- package/dist/admin/components/LocaleListCell.mjs +100 -0
- package/dist/admin/components/LocaleListCell.mjs.map +1 -0
- package/dist/admin/components/LocalePicker.js +105 -0
- package/dist/admin/components/LocalePicker.js.map +1 -0
- package/dist/admin/components/LocalePicker.mjs +84 -0
- package/dist/admin/components/LocalePicker.mjs.map +1 -0
- package/dist/admin/components/LocaleTable.js +143 -0
- package/dist/admin/components/LocaleTable.js.map +1 -0
- package/dist/admin/components/LocaleTable.mjs +122 -0
- package/dist/admin/components/LocaleTable.mjs.map +1 -0
- package/dist/admin/constants.js +37 -0
- package/dist/admin/constants.js.map +1 -0
- package/dist/admin/constants.mjs +35 -0
- package/dist/admin/constants.mjs.map +1 -0
- package/dist/admin/contentManagerHooks/editView.js +109 -0
- package/dist/admin/contentManagerHooks/editView.js.map +1 -0
- package/dist/admin/contentManagerHooks/editView.mjs +88 -0
- package/dist/admin/contentManagerHooks/editView.mjs.map +1 -0
- package/dist/admin/contentManagerHooks/listView.js +44 -0
- package/dist/admin/contentManagerHooks/listView.js.map +1 -0
- package/dist/admin/contentManagerHooks/listView.mjs +42 -0
- package/dist/admin/contentManagerHooks/listView.mjs.map +1 -0
- package/dist/admin/contentReleasesHooks/releaseDetailsView.js +20 -0
- package/dist/admin/contentReleasesHooks/releaseDetailsView.js.map +1 -0
- package/dist/admin/contentReleasesHooks/releaseDetailsView.mjs +18 -0
- package/dist/admin/contentReleasesHooks/releaseDetailsView.mjs.map +1 -0
- package/dist/admin/hooks/useI18n.js +78 -0
- package/dist/admin/hooks/useI18n.js.map +1 -0
- package/dist/admin/hooks/useI18n.mjs +57 -0
- package/dist/admin/hooks/useI18n.mjs.map +1 -0
- package/dist/admin/index.js +221 -16
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +203 -15
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/middlewares/extendCTBAttributeInitialData.js +71 -0
- package/dist/admin/middlewares/extendCTBAttributeInitialData.js.map +1 -0
- package/dist/admin/middlewares/extendCTBAttributeInitialData.mjs +69 -0
- package/dist/admin/middlewares/extendCTBAttributeInitialData.mjs.map +1 -0
- package/dist/admin/middlewares/extendCTBInitialData.js +40 -0
- package/dist/admin/middlewares/extendCTBInitialData.js.map +1 -0
- package/dist/admin/middlewares/extendCTBInitialData.mjs +38 -0
- package/dist/admin/middlewares/extendCTBInitialData.mjs.map +1 -0
- package/dist/admin/middlewares/rbac-middleware.js +49 -0
- package/dist/admin/middlewares/rbac-middleware.js.map +1 -0
- package/dist/admin/middlewares/rbac-middleware.mjs +28 -0
- package/dist/admin/middlewares/rbac-middleware.mjs.map +1 -0
- package/dist/admin/pages/SettingsPage.js +182 -0
- package/dist/admin/pages/SettingsPage.js.map +1 -0
- package/dist/admin/pages/SettingsPage.mjs +179 -0
- package/dist/admin/pages/SettingsPage.mjs.map +1 -0
- package/dist/admin/pluginId.js +6 -0
- package/dist/admin/pluginId.js.map +1 -0
- package/dist/admin/pluginId.mjs +4 -0
- package/dist/admin/pluginId.mjs.map +1 -0
- package/dist/admin/services/api.js +14 -0
- package/dist/admin/services/api.js.map +1 -0
- package/dist/admin/services/api.mjs +12 -0
- package/dist/admin/services/api.mjs.map +1 -0
- package/dist/admin/services/locales.js +72 -0
- package/dist/admin/services/locales.js.map +1 -0
- package/dist/admin/services/locales.mjs +66 -0
- package/dist/admin/services/locales.mjs.map +1 -0
- package/dist/admin/services/relations.js +23 -0
- package/dist/admin/services/relations.js.map +1 -0
- package/dist/admin/services/relations.mjs +21 -0
- package/dist/admin/services/relations.mjs.map +1 -0
- package/dist/admin/services/settings.js +29 -0
- package/dist/admin/services/settings.js.map +1 -0
- package/dist/admin/services/settings.mjs +26 -0
- package/dist/admin/services/settings.mjs.map +1 -0
- package/dist/admin/src/components/CMHeaderActions.d.ts +7 -1
- package/dist/admin/src/components/LocaleListCell.d.ts +2 -1
- package/dist/admin/src/services/api.d.ts +1 -1
- package/dist/admin/src/services/locales.d.ts +1 -1
- package/dist/admin/src/services/relations.d.ts +1 -1
- package/dist/admin/src/services/settings.d.ts +5 -0
- package/dist/admin/src/utils/schemas.d.ts +642 -16
- package/dist/admin/{chunks/de-nEMWvIiY.js → translations/de.json.js} +2 -2
- package/dist/admin/translations/de.json.js.map +1 -0
- package/dist/admin/{chunks/de-Cm8mYdaO.js → translations/de.json.mjs} +1 -1
- package/dist/admin/translations/de.json.mjs.map +1 -0
- package/dist/admin/{chunks/dk-CYATLPVe.js → translations/dk.json.js} +2 -2
- package/dist/admin/translations/dk.json.js.map +1 -0
- package/dist/admin/{chunks/dk-BeUFOegB.js → translations/dk.json.mjs} +1 -1
- package/dist/admin/translations/dk.json.mjs.map +1 -0
- package/dist/admin/{chunks/en-CG5cUCbD.js → translations/en.json.js} +9 -2
- package/dist/admin/translations/en.json.js.map +1 -0
- package/dist/admin/{chunks/en-eWSaCeOb.js → translations/en.json.mjs} +8 -1
- package/dist/admin/translations/en.json.mjs.map +1 -0
- package/dist/admin/{chunks/es-CWsogTGm.js → translations/es.json.js} +2 -2
- package/dist/admin/translations/es.json.js.map +1 -0
- package/dist/admin/{chunks/es-DqF_IdAc.js → translations/es.json.mjs} +1 -1
- package/dist/admin/translations/es.json.mjs.map +1 -0
- package/dist/admin/{chunks/fr-CC7UFcYd.js → translations/fr.json.js} +2 -2
- package/dist/admin/translations/fr.json.js.map +1 -0
- package/dist/admin/{chunks/fr-CyARbZ3c.js → translations/fr.json.mjs} +1 -1
- package/dist/admin/translations/fr.json.mjs.map +1 -0
- package/dist/admin/{chunks/ko-XwGmfhoq.js → translations/ko.json.js} +2 -2
- package/dist/admin/translations/ko.json.js.map +1 -0
- package/dist/admin/{chunks/ko-Ax4NSedM.js → translations/ko.json.mjs} +1 -1
- package/dist/admin/translations/ko.json.mjs.map +1 -0
- package/dist/admin/{chunks/pl-B_vzY_ZB.js → translations/pl.json.js} +2 -2
- package/dist/admin/translations/pl.json.js.map +1 -0
- package/dist/admin/{chunks/pl-B-aqvMqL.js → translations/pl.json.mjs} +1 -1
- package/dist/admin/translations/pl.json.mjs.map +1 -0
- package/dist/admin/{chunks/ru-WzHcJV1f.js → translations/ru.json.js} +2 -2
- package/dist/admin/translations/ru.json.js.map +1 -0
- package/dist/admin/{chunks/ru-VkPjQ-Sk.js → translations/ru.json.mjs} +1 -1
- package/dist/admin/translations/ru.json.mjs.map +1 -0
- package/dist/admin/{chunks/tr-CcWp6u3w.js → translations/tr.json.js} +2 -2
- package/dist/admin/translations/tr.json.js.map +1 -0
- package/dist/admin/{chunks/tr-DcTR88c9.js → translations/tr.json.mjs} +1 -1
- package/dist/admin/translations/tr.json.mjs.map +1 -0
- package/dist/admin/translations/uk.json.js +82 -0
- package/dist/admin/translations/uk.json.js.map +1 -0
- package/dist/admin/translations/uk.json.mjs +80 -0
- package/dist/admin/translations/uk.json.mjs.map +1 -0
- package/dist/admin/{chunks/zh-Hans-DnU2bhri.js → translations/zh-Hans.json.js} +2 -2
- package/dist/admin/translations/zh-Hans.json.js.map +1 -0
- package/dist/admin/{chunks/zh-Hans-L3wsRegj.js → translations/zh-Hans.json.mjs} +1 -1
- package/dist/admin/translations/zh-Hans.json.mjs.map +1 -0
- package/dist/admin/{chunks/zh-C9So4SGq.js → translations/zh.json.js} +2 -2
- package/dist/admin/translations/zh.json.js.map +1 -0
- package/dist/admin/{chunks/zh-RZyMiPIs.js → translations/zh.json.mjs} +1 -1
- package/dist/admin/translations/zh.json.mjs.map +1 -0
- package/dist/admin/utils/baseQuery.js +8 -0
- package/dist/admin/utils/baseQuery.js.map +1 -0
- package/dist/admin/utils/baseQuery.mjs +6 -0
- package/dist/admin/utils/baseQuery.mjs.map +1 -0
- package/dist/admin/utils/clean.js +70 -0
- package/dist/admin/utils/clean.js.map +1 -0
- package/dist/admin/utils/clean.mjs +68 -0
- package/dist/admin/utils/clean.mjs.map +1 -0
- package/dist/admin/utils/fields.js +34 -0
- package/dist/admin/utils/fields.js.map +1 -0
- package/dist/admin/utils/fields.mjs +31 -0
- package/dist/admin/utils/fields.mjs.map +1 -0
- package/dist/admin/utils/getTranslation.js +8 -0
- package/dist/admin/utils/getTranslation.js.map +1 -0
- package/dist/admin/utils/getTranslation.mjs +6 -0
- package/dist/admin/utils/getTranslation.mjs.map +1 -0
- package/dist/admin/utils/prefixPluginTranslations.js +11 -0
- package/dist/admin/utils/prefixPluginTranslations.js.map +1 -0
- package/dist/admin/utils/prefixPluginTranslations.mjs +9 -0
- package/dist/admin/utils/prefixPluginTranslations.mjs.map +1 -0
- package/dist/admin/utils/schemas.js +74 -0
- package/dist/admin/utils/schemas.js.map +1 -0
- package/dist/admin/utils/schemas.mjs +72 -0
- package/dist/admin/utils/schemas.mjs.map +1 -0
- package/dist/admin/utils/strings.js +6 -0
- package/dist/admin/utils/strings.js.map +1 -0
- package/dist/admin/utils/strings.mjs +4 -0
- package/dist/admin/utils/strings.mjs.map +1 -0
- package/dist/server/bootstrap.js +79 -0
- package/dist/server/bootstrap.js.map +1 -0
- package/dist/server/bootstrap.mjs +77 -0
- package/dist/server/bootstrap.mjs.map +1 -0
- package/dist/server/constants/index.js +29 -0
- package/dist/server/constants/index.js.map +1 -0
- package/dist/server/constants/index.mjs +25 -0
- package/dist/server/constants/index.mjs.map +1 -0
- package/dist/server/constants/iso-locales.json.js +2427 -0
- package/dist/server/constants/iso-locales.json.js.map +1 -0
- package/dist/server/constants/iso-locales.json.mjs +2425 -0
- package/dist/server/constants/iso-locales.json.mjs.map +1 -0
- package/dist/server/content-types/index.js +10 -0
- package/dist/server/content-types/index.js.map +1 -0
- package/dist/server/content-types/index.mjs +8 -0
- package/dist/server/content-types/index.mjs.map +1 -0
- package/dist/server/content-types/locale/index.js +10 -0
- package/dist/server/content-types/locale/index.js.map +1 -0
- package/dist/server/content-types/locale/index.mjs +8 -0
- package/dist/server/content-types/locale/index.mjs.map +1 -0
- package/dist/server/content-types/locale/schema.json.js +46 -0
- package/dist/server/content-types/locale/schema.json.js.map +1 -0
- package/dist/server/content-types/locale/schema.json.mjs +38 -0
- package/dist/server/content-types/locale/schema.json.mjs.map +1 -0
- package/dist/server/controllers/content-types.js +76 -0
- package/dist/server/controllers/content-types.js.map +1 -0
- package/dist/server/controllers/content-types.mjs +74 -0
- package/dist/server/controllers/content-types.mjs.map +1 -0
- package/dist/server/controllers/index.js +16 -0
- package/dist/server/controllers/index.js.map +1 -0
- package/dist/server/controllers/index.mjs +14 -0
- package/dist/server/controllers/index.mjs.map +1 -0
- package/dist/server/controllers/iso-locales.js +13 -0
- package/dist/server/controllers/iso-locales.js.map +1 -0
- package/dist/server/controllers/iso-locales.mjs +11 -0
- package/dist/server/controllers/iso-locales.mjs.map +1 -0
- package/dist/server/controllers/locales.js +108 -0
- package/dist/server/controllers/locales.js.map +1 -0
- package/dist/server/controllers/locales.mjs +87 -0
- package/dist/server/controllers/locales.mjs.map +1 -0
- package/dist/server/controllers/settings.js +24 -0
- package/dist/server/controllers/settings.js.map +1 -0
- package/dist/server/controllers/settings.mjs +22 -0
- package/dist/server/controllers/settings.mjs.map +1 -0
- package/dist/server/controllers/validate-locale-creation.js +47 -0
- package/dist/server/controllers/validate-locale-creation.js.map +1 -0
- package/dist/server/controllers/validate-locale-creation.mjs +45 -0
- package/dist/server/controllers/validate-locale-creation.mjs.map +1 -0
- package/dist/server/domain/locale.js +11 -0
- package/dist/server/domain/locale.js.map +1 -0
- package/dist/server/domain/locale.mjs +9 -0
- package/dist/server/domain/locale.mjs.map +1 -0
- package/dist/server/graphql.js +115 -0
- package/dist/server/graphql.js.map +1 -0
- package/dist/server/graphql.mjs +113 -0
- package/dist/server/graphql.mjs.map +1 -0
- package/dist/server/index.js +10 -3712
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +7 -3691
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/register.js +79 -0
- package/dist/server/register.js.map +1 -0
- package/dist/server/register.mjs +77 -0
- package/dist/server/register.mjs.map +1 -0
- package/dist/server/routes/admin.js +122 -0
- package/dist/server/routes/admin.js.map +1 -0
- package/dist/server/routes/admin.mjs +120 -0
- package/dist/server/routes/admin.mjs.map +1 -0
- package/dist/server/routes/content-api.js +19 -0
- package/dist/server/routes/content-api.js.map +1 -0
- package/dist/server/routes/content-api.mjs +17 -0
- package/dist/server/routes/content-api.mjs.map +1 -0
- package/dist/server/routes/index.js +12 -0
- package/dist/server/routes/index.js.map +1 -0
- package/dist/server/routes/index.mjs +10 -0
- package/dist/server/routes/index.mjs.map +1 -0
- package/dist/server/routes/validation/locale.js +57 -0
- package/dist/server/routes/validation/locale.js.map +1 -0
- package/dist/server/routes/validation/locale.mjs +36 -0
- package/dist/server/routes/validation/locale.mjs.map +1 -0
- package/dist/server/services/ai-localizations.js +143 -0
- package/dist/server/services/ai-localizations.js.map +1 -0
- package/dist/server/services/ai-localizations.mjs +141 -0
- package/dist/server/services/ai-localizations.mjs.map +1 -0
- package/dist/server/services/content-types.js +157 -0
- package/dist/server/services/content-types.js.map +1 -0
- package/dist/server/services/content-types.mjs +155 -0
- package/dist/server/services/content-types.mjs.map +1 -0
- package/dist/server/services/index.js +26 -0
- package/dist/server/services/index.js.map +1 -0
- package/dist/server/services/index.mjs +24 -0
- package/dist/server/services/index.mjs.map +1 -0
- package/dist/server/services/iso-locales.js +12 -0
- package/dist/server/services/iso-locales.js.map +1 -0
- package/dist/server/services/iso-locales.mjs +10 -0
- package/dist/server/services/iso-locales.mjs.map +1 -0
- package/dist/server/services/locales.js +114 -0
- package/dist/server/services/locales.js.map +1 -0
- package/dist/server/services/locales.mjs +112 -0
- package/dist/server/services/locales.mjs.map +1 -0
- package/dist/server/services/localizations.js +68 -0
- package/dist/server/services/localizations.js.map +1 -0
- package/dist/server/services/localizations.mjs +66 -0
- package/dist/server/services/localizations.mjs.map +1 -0
- package/dist/server/services/metrics.js +30 -0
- package/dist/server/services/metrics.js.map +1 -0
- package/dist/server/services/metrics.mjs +28 -0
- package/dist/server/services/metrics.mjs.map +1 -0
- package/dist/server/services/permissions/actions.js +136 -0
- package/dist/server/services/permissions/actions.js.map +1 -0
- package/dist/server/services/permissions/actions.mjs +134 -0
- package/dist/server/services/permissions/actions.mjs.map +1 -0
- package/dist/server/services/permissions/engine.js +52 -0
- package/dist/server/services/permissions/engine.js.map +1 -0
- package/dist/server/services/permissions/engine.mjs +50 -0
- package/dist/server/services/permissions/engine.mjs.map +1 -0
- package/dist/server/services/permissions/sections-builder.js +45 -0
- package/dist/server/services/permissions/sections-builder.js.map +1 -0
- package/dist/server/services/permissions/sections-builder.mjs +43 -0
- package/dist/server/services/permissions/sections-builder.mjs.map +1 -0
- package/dist/server/services/permissions.js +14 -0
- package/dist/server/services/permissions.js.map +1 -0
- package/dist/server/services/permissions.mjs +12 -0
- package/dist/server/services/permissions.mjs.map +1 -0
- package/dist/server/services/sanitize/index.js +34 -0
- package/dist/server/services/sanitize/index.js.map +1 -0
- package/dist/server/services/sanitize/index.mjs +32 -0
- package/dist/server/services/sanitize/index.mjs.map +1 -0
- package/dist/server/services/settings.js +25 -0
- package/dist/server/services/settings.js.map +1 -0
- package/dist/server/services/settings.mjs +23 -0
- package/dist/server/services/settings.mjs.map +1 -0
- package/dist/server/src/controllers/index.d.ts +4 -0
- package/dist/server/src/controllers/index.d.ts.map +1 -1
- package/dist/server/src/controllers/settings.d.ts +7 -0
- package/dist/server/src/controllers/settings.d.ts.map +1 -0
- package/dist/server/src/index.d.ts +26 -7
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/routes/admin.d.ts.map +1 -1
- package/dist/server/src/routes/content-api.d.ts +5 -8
- package/dist/server/src/routes/content-api.d.ts.map +1 -1
- package/dist/server/src/routes/index.d.ts +3 -7
- package/dist/server/src/routes/index.d.ts.map +1 -1
- package/dist/server/src/routes/validation/index.d.ts +2 -0
- package/dist/server/src/routes/validation/index.d.ts.map +1 -0
- package/dist/server/src/routes/validation/locale.d.ts +41 -0
- package/dist/server/src/routes/validation/locale.d.ts.map +1 -0
- package/dist/server/src/services/ai-localizations.d.ts +17 -0
- package/dist/server/src/services/ai-localizations.d.ts.map +1 -0
- package/dist/server/src/services/index.d.ts +19 -0
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/settings.d.ts +13 -0
- package/dist/server/src/services/settings.d.ts.map +1 -0
- package/dist/server/src/utils/index.d.ts +5 -1
- package/dist/server/src/utils/index.d.ts.map +1 -1
- package/dist/server/src/validation/settings.d.ts +12 -0
- package/dist/server/src/validation/settings.d.ts.map +1 -0
- package/dist/server/utils/index.js +16 -0
- package/dist/server/utils/index.js.map +1 -0
- package/dist/server/utils/index.mjs +13 -0
- package/dist/server/utils/index.mjs.map +1 -0
- package/dist/server/validation/content-types.js +18 -0
- package/dist/server/validation/content-types.js.map +1 -0
- package/dist/server/validation/content-types.mjs +16 -0
- package/dist/server/validation/content-types.mjs.map +1 -0
- package/dist/server/validation/locales.js +23 -0
- package/dist/server/validation/locales.js.map +1 -0
- package/dist/server/validation/locales.mjs +20 -0
- package/dist/server/validation/locales.mjs.map +1 -0
- package/dist/server/validation/settings.js +11 -0
- package/dist/server/validation/settings.js.map +1 -0
- package/dist/server/validation/settings.mjs +9 -0
- package/dist/server/validation/settings.mjs.map +1 -0
- package/dist/shared/contracts/settings.d.ts +40 -0
- package/package.json +11 -9
- package/dist/admin/chunks/SettingsPage-B6ikxVOg.js +0 -820
- package/dist/admin/chunks/SettingsPage-B6ikxVOg.js.map +0 -1
- package/dist/admin/chunks/SettingsPage-Kg4GAThm.js +0 -797
- package/dist/admin/chunks/SettingsPage-Kg4GAThm.js.map +0 -1
- package/dist/admin/chunks/de-Cm8mYdaO.js.map +0 -1
- package/dist/admin/chunks/de-nEMWvIiY.js.map +0 -1
- package/dist/admin/chunks/dk-BeUFOegB.js.map +0 -1
- package/dist/admin/chunks/dk-CYATLPVe.js.map +0 -1
- package/dist/admin/chunks/en-CG5cUCbD.js.map +0 -1
- package/dist/admin/chunks/en-eWSaCeOb.js.map +0 -1
- package/dist/admin/chunks/es-CWsogTGm.js.map +0 -1
- package/dist/admin/chunks/es-DqF_IdAc.js.map +0 -1
- package/dist/admin/chunks/fr-CC7UFcYd.js.map +0 -1
- package/dist/admin/chunks/fr-CyARbZ3c.js.map +0 -1
- package/dist/admin/chunks/index-Dch-2xao.js +0 -2035
- package/dist/admin/chunks/index-Dch-2xao.js.map +0 -1
- package/dist/admin/chunks/index-DyvbIjH9.js +0 -2006
- package/dist/admin/chunks/index-DyvbIjH9.js.map +0 -1
- package/dist/admin/chunks/ko-Ax4NSedM.js.map +0 -1
- package/dist/admin/chunks/ko-XwGmfhoq.js.map +0 -1
- package/dist/admin/chunks/pl-B-aqvMqL.js.map +0 -1
- package/dist/admin/chunks/pl-B_vzY_ZB.js.map +0 -1
- package/dist/admin/chunks/ru-VkPjQ-Sk.js.map +0 -1
- package/dist/admin/chunks/ru-WzHcJV1f.js.map +0 -1
- package/dist/admin/chunks/tr-CcWp6u3w.js.map +0 -1
- package/dist/admin/chunks/tr-DcTR88c9.js.map +0 -1
- package/dist/admin/chunks/zh-C9So4SGq.js.map +0 -1
- package/dist/admin/chunks/zh-Hans-DnU2bhri.js.map +0 -1
- package/dist/admin/chunks/zh-Hans-L3wsRegj.js.map +0 -1
- package/dist/admin/chunks/zh-RZyMiPIs.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-localizations.mjs","sources":["../../../server/src/services/ai-localizations.ts"],"sourcesContent":["import type { Core, Modules, UID } from '@strapi/types';\nimport { traverseEntity } from '@strapi/utils';\nimport { getService } from '../utils';\n\nconst createAILocalizationsService = ({ strapi }: { strapi: Core.Strapi }) => {\n // TODO: add a helper function to get the AI server URL\n const aiServerUrl = process.env.STRAPI_AI_URL || 'https://strapi-ai.apps.strapi.io';\n\n return {\n // Async to avoid changing the signature later (there will be a db check in the future)\n async isEnabled() {\n // Check if future flag is enabled\n const isFutureFlagEnabled = strapi.features.future.isEnabled('unstableAILocalizations');\n if (!isFutureFlagEnabled) {\n return false;\n }\n\n // Check if user disabled AI features globally\n const isAIEnabled = strapi.config.get('admin.ai.enabled', true);\n if (!isAIEnabled) {\n return false;\n }\n\n // Check if the user's license grants access to AI features\n const hasAccess = strapi.ee.features.isEnabled('cms-ai');\n if (!hasAccess) {\n return false;\n }\n\n return true;\n },\n\n /**\n * Checks if there are localizations that need to be generated for the given document,\n * and if so, calls the AI service and saves the results to the database.\n * Works for both single and collection types, on create and update.\n */\n async generateDocumentLocalizations({\n model,\n document,\n }: {\n model: UID.ContentType;\n document: Modules.Documents.AnyDocument;\n }) {\n const schema = strapi.getModel(model);\n const localeService = getService('locales');\n\n // No localizations needed for content types with i18n disabled\n const isLocalizedContentType = getService('content-types').isLocalizedContentType(schema);\n if (!isLocalizedContentType) {\n return;\n }\n\n // Don't trigger localizations if the update is on a derived locale, only do it on the default\n const defaultLocale = await localeService.getDefaultLocale();\n if (document.locale !== defaultLocale) {\n return;\n }\n\n const isFeatureEnabled = await this.isEnabled();\n if (!isFeatureEnabled) {\n return;\n }\n\n const documentId = document.documentId;\n\n if (!documentId) {\n strapi.log.warn(`AI Localizations: missing documentId for ${schema.uid}`);\n return;\n }\n\n // Extract only the localized content from the document\n const translateableContent = await traverseEntity(\n ({ key, attribute }, { remove }) => {\n const hasLocalizedOption = attribute?.pluginOptions?.i18n?.localized === true;\n // Only keep fields that actually need to be localized\n // TODO: remove blocks from this list once the AI server can handle it reliably\n if (!hasLocalizedOption || ['media', 'blocks'].includes(attribute.type)) {\n remove(key);\n }\n },\n { schema, getModel: strapi.getModel.bind(strapi) },\n document\n );\n\n // Call the AI server to get the localized content\n const localesList = await localeService.find();\n const targetLocales = localesList\n .filter((l) => l.code !== document.locale)\n .map((l) => l.code);\n\n if (targetLocales.length === 0) {\n strapi.log.info(\n `AI Localizations: no target locales for ${schema.uid} document ${documentId}`\n );\n return;\n }\n\n let token: string;\n try {\n const tokenData = await strapi.service('admin::user').getAiToken();\n token = tokenData.token;\n } catch (error) {\n throw new Error('Failed to retrieve AI token', {\n cause: error instanceof Error ? error : undefined,\n });\n }\n\n strapi.log.http('Contacting AI Server for localizations generation');\n const response = await fetch(`${aiServerUrl}/i18n/generate-localizations`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${token}`,\n },\n body: JSON.stringify({\n content: translateableContent,\n sourceLocale: document.locale,\n targetLocales,\n }),\n });\n\n if (!response.ok) {\n strapi.log.error(\n `AI Localizations request failed: ${response.status} ${response.statusText}`\n );\n throw new Error(`AI Localizations request failed: ${response.statusText}`);\n }\n\n const aiResult = await response.json();\n\n // Get all media field names dynamically from the schema\n const mediaFields = Object.entries(schema.attributes)\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n .filter(([_, attr]) => attr.type === 'media')\n .map(([key]) => key);\n\n try {\n await Promise.allSettled(\n aiResult.localizations.map(async (localization: any) => {\n const { content, locale } = localization;\n\n // Fetch the derived locale document\n const derivedDoc = await strapi.documents(model).findOne({\n documentId,\n locale,\n populate: mediaFields,\n });\n\n // Merge AI content and media fields\n const mergedData = { ...content };\n for (const field of mediaFields) {\n // Only copy media if not already set in derived locale\n if (!derivedDoc || !derivedDoc[field]) {\n mergedData[field] = document[field];\n } else {\n mergedData[field] = derivedDoc[field];\n }\n }\n\n return strapi.documents(model).update({\n documentId,\n locale,\n fields: [],\n data: mergedData,\n });\n })\n );\n } catch (error) {\n strapi.log.error('AI Localizations generation failed', error);\n }\n },\n };\n};\n\nexport { createAILocalizationsService };\n"],"names":["createAILocalizationsService","strapi","aiServerUrl","process","env","STRAPI_AI_URL","isEnabled","isFutureFlagEnabled","features","future","isAIEnabled","config","get","hasAccess","ee","generateDocumentLocalizations","model","document","schema","getModel","localeService","getService","isLocalizedContentType","defaultLocale","getDefaultLocale","locale","isFeatureEnabled","documentId","log","warn","uid","translateableContent","traverseEntity","key","attribute","remove","hasLocalizedOption","pluginOptions","i18n","localized","includes","type","bind","localesList","find","targetLocales","filter","l","code","map","length","info","token","tokenData","service","getAiToken","error","Error","cause","undefined","http","response","fetch","method","headers","Authorization","body","JSON","stringify","content","sourceLocale","ok","status","statusText","aiResult","json","mediaFields","Object","entries","attributes","_","attr","Promise","allSettled","localizations","localization","derivedDoc","documents","findOne","populate","mergedData","field","update","fields","data"],"mappings":";;;AAIA,MAAMA,4BAA+B,GAAA,CAAC,EAAEC,MAAM,EAA2B,GAAA;;AAEvE,IAAA,MAAMC,WAAcC,GAAAA,OAAAA,CAAQC,GAAG,CAACC,aAAa,IAAI,kCAAA;IAEjD,OAAO;;QAEL,MAAMC,SAAAA,CAAAA,GAAAA;;AAEJ,YAAA,MAAMC,sBAAsBN,MAAOO,CAAAA,QAAQ,CAACC,MAAM,CAACH,SAAS,CAAC,yBAAA,CAAA;AAC7D,YAAA,IAAI,CAACC,mBAAqB,EAAA;gBACxB,OAAO,KAAA;AACT;;AAGA,YAAA,MAAMG,cAAcT,MAAOU,CAAAA,MAAM,CAACC,GAAG,CAAC,kBAAoB,EAAA,IAAA,CAAA;AAC1D,YAAA,IAAI,CAACF,WAAa,EAAA;gBAChB,OAAO,KAAA;AACT;;AAGA,YAAA,MAAMG,YAAYZ,MAAOa,CAAAA,EAAE,CAACN,QAAQ,CAACF,SAAS,CAAC,QAAA,CAAA;AAC/C,YAAA,IAAI,CAACO,SAAW,EAAA;gBACd,OAAO,KAAA;AACT;YAEA,OAAO,IAAA;AACT,SAAA;AAEA;;;;AAIC,QACD,MAAME,6BAA8B,CAAA,CAAA,EAClCC,KAAK,EACLC,QAAQ,EAIT,EAAA;YACC,MAAMC,MAAAA,GAASjB,MAAOkB,CAAAA,QAAQ,CAACH,KAAAA,CAAAA;AAC/B,YAAA,MAAMI,gBAAgBC,UAAW,CAAA,SAAA,CAAA;;AAGjC,YAAA,MAAMC,sBAAyBD,GAAAA,UAAAA,CAAW,eAAiBC,CAAAA,CAAAA,sBAAsB,CAACJ,MAAAA,CAAAA;AAClF,YAAA,IAAI,CAACI,sBAAwB,EAAA;AAC3B,gBAAA;AACF;;YAGA,MAAMC,aAAAA,GAAgB,MAAMH,aAAAA,CAAcI,gB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AA,EAAQ,EAAE;wBACVC,IAAMJ,EAAAA;AACR,qBAAA,CAAA;AACF,iBAAA,CAAA,CAAA;AAEJ,aAAA,CAAE,OAAOlC,KAAO,EAAA;AACdvD,gBAAAA,MAAAA,CAAO2B,GAAG,CAAC4B,KAAK,CAAC,oCAAsCA,EAAAA,KAAAA,CAAAA;AACzD;AACF;AACF,KAAA;AACF;;;;"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _ = require('lodash');
|
|
4
|
+
var fp = require('lodash/fp');
|
|
5
|
+
var utils = require('@strapi/utils');
|
|
6
|
+
var index = require('../utils/index.js');
|
|
7
|
+
|
|
8
|
+
const { isRelationalAttribute, getVisibleAttributes, isTypedAttribute, getScalarAttributes, getRelationalAttributes } = utils.contentTypes;
|
|
9
|
+
const { ApplicationError } = utils.errors;
|
|
10
|
+
const hasLocalizedOption = (modelOrAttribute)=>{
|
|
11
|
+
return fp.prop('pluginOptions.i18n.localized', modelOrAttribute) === true;
|
|
12
|
+
};
|
|
13
|
+
const getValidLocale = async (locale)=>{
|
|
14
|
+
const localesService = index.getService('locales');
|
|
15
|
+
if (fp.isNil(locale)) {
|
|
16
|
+
return localesService.getDefaultLocale();
|
|
17
|
+
}
|
|
18
|
+
const foundLocale = await localesService.findByCode(locale);
|
|
19
|
+
if (!foundLocale) {
|
|
20
|
+
throw new ApplicationError('Locale not found');
|
|
21
|
+
}
|
|
22
|
+
return locale;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Returns whether an attribute is localized or not
|
|
26
|
+
* @param {*} attribute
|
|
27
|
+
* @returns
|
|
28
|
+
*/ const isLocalizedAttribute = (attribute)=>{
|
|
29
|
+
return hasLocalizedOption(attribute) || isRelationalAttribute(attribute) || isTypedAttribute(attribute, 'uid');
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Returns whether a model is localized or not
|
|
33
|
+
* @param {*} model
|
|
34
|
+
* @returns
|
|
35
|
+
*/ const isLocalizedContentType = (model)=>{
|
|
36
|
+
return hasLocalizedOption(model);
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Returns the list of attribute names that are not localized
|
|
40
|
+
* @param {object} model
|
|
41
|
+
* @returns {string[]}
|
|
42
|
+
*/ const getNonLocalizedAttributes = (model)=>{
|
|
43
|
+
return getVisibleAttributes(model).filter((attrName)=>!isLocalizedAttribute(model.attributes[attrName]));
|
|
44
|
+
};
|
|
45
|
+
const removeId = (value)=>{
|
|
46
|
+
if (typeof value === 'object' && fp.has('id', value)) {
|
|
47
|
+
delete value.id;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const removeIds = (model)=>(entry)=>removeIdsMut(model, fp.cloneDeep(entry));
|
|
51
|
+
const removeIdsMut = (model, entry)=>{
|
|
52
|
+
if (fp.isNil(entry)) {
|
|
53
|
+
return entry;
|
|
54
|
+
}
|
|
55
|
+
removeId(entry);
|
|
56
|
+
_.forEach(model.attributes, (attr, attrName)=>{
|
|
57
|
+
const value = entry[attrName];
|
|
58
|
+
if (attr.type === 'dynamiczone' && fp.isArray(value)) {
|
|
59
|
+
value.forEach((compo)=>{
|
|
60
|
+
if (fp.has('__component', compo)) {
|
|
61
|
+
const model = strapi.components[compo.__component];
|
|
62
|
+
removeIdsMut(model, compo);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
} else if (attr.type === 'component') {
|
|
66
|
+
const model = strapi.components[attr.component];
|
|
67
|
+
if (fp.isArray(value)) {
|
|
68
|
+
value.forEach((compo)=>removeIdsMut(model, compo));
|
|
69
|
+
} else {
|
|
70
|
+
removeIdsMut(model, value);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return entry;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Returns a copy of an entry picking only its non localized attributes
|
|
78
|
+
* @param {object} model
|
|
79
|
+
* @param {object} entry
|
|
80
|
+
* @returns {object}
|
|
81
|
+
*/ const copyNonLocalizedAttributes = (model, entry)=>{
|
|
82
|
+
const nonLocalizedAttributes = getNonLocalizedAttributes(model);
|
|
83
|
+
return fp.pipe(fp.pick(nonLocalizedAttributes), removeIds(model))(entry);
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Returns the list of attribute names that are localized
|
|
87
|
+
* @param {object} model
|
|
88
|
+
* @returns {string[]}
|
|
89
|
+
*/ const getLocalizedAttributes = (model)=>{
|
|
90
|
+
return getVisibleAttributes(model).filter((attrName)=>isLocalizedAttribute(model.attributes[attrName]));
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Fill non localized fields of an entry if there are nil
|
|
94
|
+
* @param {Object} entry entry to fill
|
|
95
|
+
* @param {Object} relatedEntry values used to fill
|
|
96
|
+
* @param {Object} options
|
|
97
|
+
* @param {Object} options.model corresponding model
|
|
98
|
+
*/ const fillNonLocalizedAttributes = (entry, relatedEntry, { model })=>{
|
|
99
|
+
if (fp.isNil(relatedEntry)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const modelDef = strapi.getModel(model);
|
|
103
|
+
const relatedEntryCopy = copyNonLocalizedAttributes(modelDef, relatedEntry);
|
|
104
|
+
_.forEach(relatedEntryCopy, (value, field)=>{
|
|
105
|
+
if (fp.isNil(entry[field])) {
|
|
106
|
+
entry[field] = value;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* build the populate param to
|
|
112
|
+
* @param {String} modelUID uid of the model, could be of a content-type or a component
|
|
113
|
+
*/ const getNestedPopulateOfNonLocalizedAttributes = (modelUID)=>{
|
|
114
|
+
const schema = strapi.getModel(modelUID);
|
|
115
|
+
const scalarAttributes = getScalarAttributes(schema);
|
|
116
|
+
const nonLocalizedAttributes = getNonLocalizedAttributes(schema);
|
|
117
|
+
const allAttributes = [
|
|
118
|
+
...scalarAttributes,
|
|
119
|
+
...nonLocalizedAttributes
|
|
120
|
+
];
|
|
121
|
+
if (schema.modelType === 'component') {
|
|
122
|
+
// When called recursively on a non localized component we
|
|
123
|
+
// need to explicitly populate that components relations
|
|
124
|
+
allAttributes.push(...getRelationalAttributes(schema));
|
|
125
|
+
}
|
|
126
|
+
const currentAttributesToPopulate = allAttributes.filter((value, index, self)=>{
|
|
127
|
+
return self.indexOf(value) === index && self.lastIndexOf(value) === index;
|
|
128
|
+
});
|
|
129
|
+
const attributesToPopulate = [
|
|
130
|
+
...currentAttributesToPopulate
|
|
131
|
+
];
|
|
132
|
+
for (const attrName of currentAttributesToPopulate){
|
|
133
|
+
const attr = schema.attributes[attrName];
|
|
134
|
+
if (attr.type === 'component') {
|
|
135
|
+
const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(attr.component).map((nestedAttr)=>`${attrName}.${nestedAttr}`);
|
|
136
|
+
attributesToPopulate.push(...nestedPopulate);
|
|
137
|
+
} else if (attr.type === 'dynamiczone') {
|
|
138
|
+
attr.components.forEach((componentName)=>{
|
|
139
|
+
const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(componentName).map((nestedAttr)=>`${attrName}.${nestedAttr}`);
|
|
140
|
+
attributesToPopulate.push(...nestedPopulate);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return attributesToPopulate;
|
|
145
|
+
};
|
|
146
|
+
const contentTypes = ()=>({
|
|
147
|
+
isLocalizedContentType,
|
|
148
|
+
getValidLocale,
|
|
149
|
+
getLocalizedAttributes,
|
|
150
|
+
getNonLocalizedAttributes,
|
|
151
|
+
copyNonLocalizedAttributes,
|
|
152
|
+
fillNonLocalizedAttributes,
|
|
153
|
+
getNestedPopulateOfNonLocalizedAttributes
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
module.exports = contentTypes;
|
|
157
|
+
//# sourceMappingURL=content-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-types.js","sources":["../../../server/src/services/content-types.ts"],"sourcesContent":["import _ from 'lodash';\nimport { pick, pipe, has, prop, isNil, cloneDeep, isArray } from 'lodash/fp';\nimport { errors, contentTypes as contentTypeUtils } from '@strapi/utils';\nimport { getService } from '../utils';\n\nconst {\n isRelationalAttribute,\n getVisibleAttributes,\n isTypedAttribute,\n getScalarAttributes,\n getRelationalAttributes,\n} = contentTypeUtils;\nconst { ApplicationError } = errors;\n\nconst hasLocalizedOption = (modelOrAttribute: any) => {\n return prop('pluginOptions.i18n.localized', modelOrAttribute) === true;\n};\n\nconst getValidLocale = async (locale: any) => {\n const localesService = getService('locales');\n\n if (isNil(locale)) {\n return localesService.getDefaultLocale();\n }\n\n const foundLocale = await localesService.findByCode(locale);\n if (!foundLocale) {\n throw new ApplicationError('Locale not found');\n }\n\n return locale;\n};\n\n/**\n * Returns whether an attribute is localized or not\n * @param {*} attribute\n * @returns\n */\nconst isLocalizedAttribute = (attribute: any) => {\n return (\n hasLocalizedOption(attribute) ||\n isRelationalAttribute(attribute) ||\n isTypedAttribute(attribute, 'uid')\n );\n};\n\n/**\n * Returns whether a model is localized or not\n * @param {*} model\n * @returns\n */\nconst isLocalizedContentType = (model: any) => {\n return hasLocalizedOption(model);\n};\n\n/**\n * Returns the list of attribute names that are not localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getNonLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter(\n (attrName) => !isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\nconst removeId = (value: any) => {\n if (typeof value === 'object' && has('id', value)) {\n delete value.id;\n }\n};\n\nconst removeIds = (model: any) => (entry: any) => removeIdsMut(model, cloneDeep(entry));\n\nconst removeIdsMut = (model: any, entry: any) => {\n if (isNil(entry)) {\n return entry;\n }\n\n removeId(entry);\n\n _.forEach(model.attributes, (attr, attrName) => {\n const value = entry[attrName];\n if (attr.type === 'dynamiczone' && isArray(value)) {\n value.forEach((compo) => {\n if (has('__component', compo)) {\n const model = strapi.components[compo.__component];\n removeIdsMut(model, compo);\n }\n });\n } else if (attr.type === 'component') {\n const model = strapi.components[attr.component];\n if (isArray(value)) {\n value.forEach((compo) => removeIdsMut(model, compo));\n } else {\n removeIdsMut(model, value);\n }\n }\n });\n\n return entry;\n};\n\n/**\n * Returns a copy of an entry picking only its non localized attributes\n * @param {object} model\n * @param {object} entry\n * @returns {object}\n */\nconst copyNonLocalizedAttributes = (model: any, entry: any) => {\n const nonLocalizedAttributes = getNonLocalizedAttributes(model);\n\n return pipe(pick(nonLocalizedAttributes), removeIds(model))(entry);\n};\n\n/**\n * Returns the list of attribute names that are localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter((attrName) =>\n isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\n/**\n * Fill non localized fields of an entry if there are nil\n * @param {Object} entry entry to fill\n * @param {Object} relatedEntry values used to fill\n * @param {Object} options\n * @param {Object} options.model corresponding model\n */\nconst fillNonLocalizedAttributes = (entry: any, relatedEntry: any, { model }: any) => {\n if (isNil(relatedEntry)) {\n return;\n }\n\n const modelDef = strapi.getModel(model);\n const relatedEntryCopy = copyNonLocalizedAttributes(modelDef, relatedEntry);\n\n _.forEach(relatedEntryCopy, (value, field) => {\n if (isNil(entry[field])) {\n entry[field] = value;\n }\n });\n};\n\n/**\n * build the populate param to\n * @param {String} modelUID uid of the model, could be of a content-type or a component\n */\nconst getNestedPopulateOfNonLocalizedAttributes = (modelUID: any) => {\n const schema = strapi.getModel(modelUID);\n const scalarAttributes = getScalarAttributes(schema);\n const nonLocalizedAttributes = getNonLocalizedAttributes(schema);\n\n const allAttributes = [...scalarAttributes, ...nonLocalizedAttributes];\n if (schema.modelType === 'component') {\n // When called recursively on a non localized component we\n // need to explicitly populate that components relations\n allAttributes.push(...getRelationalAttributes(schema));\n }\n\n const currentAttributesToPopulate = allAttributes.filter((value, index, self) => {\n return self.indexOf(value) === index && self.lastIndexOf(value) === index;\n });\n\n const attributesToPopulate = [...currentAttributesToPopulate];\n for (const attrName of currentAttributesToPopulate) {\n const attr = schema.attributes[attrName];\n if (attr.type === 'component') {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(attr.component).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n } else if (attr.type === 'dynamiczone') {\n attr.components.forEach((componentName) => {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(componentName).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n });\n }\n }\n\n return attributesToPopulate;\n};\n\nconst contentTypes = () => ({\n isLocalizedContentType,\n getValidLocale,\n getLocalizedAttributes,\n getNonLocalizedAttributes,\n copyNonLocalizedAttributes,\n fillNonLocalizedAttributes,\n getNestedPopulateOfNonLocalizedAttributes,\n});\n\ntype ContentTypesService = typeof contentTypes;\n\nexport default contentTypes;\nexport { ContentTypesService };\n"],"names":["isRelationalAttribute","getVisibleAttributes","isTypedAttribute","getScalarAttributes","getRelationalAttributes","contentTypeUtils","ApplicationError","errors","hasLocalizedOption","modelOrAttribute","prop","getValidLocale","locale","localesService","getService","isNil","getDefaultLocale","foundLocale","findByCode","isLocalizedAttribute","attribute","isLocalizedContentType","model","getNonLocalizedAttributes","filter","attrName","attributes","removeId","value","has","id","removeIds","entry","removeIdsMut","cloneDeep","_","forEach","attr","type","isArray","compo","strapi","components","__component","component","copyNonLocalizedAttributes","nonLocalizedAttributes","pipe","pick","getLocalizedAttributes","fillNonLocalizedAttributes","relatedEntry","modelDef","getModel","relatedEntryCopy","field","getNestedPopulateOfNonLocalizedAttributes","modelUID","schema","scalarAttributes","allAttributes","modelType","push","currentAttributesToPopulate","index","self","indexOf","lastIndexOf","attributesToPopulate","nestedPopulate","map","nestedAttr","componentName","contentTypes"],"mappings":";;;;;;;AAKA,MAAM,EACJA,qBAAqB,EACrBC,oBAAoB,EACpBC,gBAAgB,EAChBC,mBAAmB,EACnBC,uBAAuB,EACxB,GAAGC,kBAA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;AACvB,gBAAA,MAAMH,cAAiBb,GAAAA,yCAAAA,CAA0CgB,aAAeF,CAAAA,CAAAA,GAAG,CACjF,CAACC,UAAe,GAAA,CAAC,EAAE9C,QAAAA,CAAS,CAAC,EAAE8C,WAAW,CAAC,CAAA;AAE7CH,gBAAAA,oBAAAA,CAAqBN,IAAI,CAAIO,GAAAA,cAAAA,CAAAA;AAC/B,aAAA,CAAA;AACF;AACF;IAEA,OAAOD,oBAAAA;AACT,CAAA;AAEMK,MAAAA,YAAAA,GAAe,KAAO;AAC1BpD,QAAAA,sBAAAA;AACAV,QAAAA,cAAAA;AACAsC,QAAAA,sBAAAA;AACA1B,QAAAA,yBAAAA;AACAsB,QAAAA,0BAAAA;AACAK,QAAAA,0BAAAA;AACAM,QAAAA;KACF;;;;"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { isNil, pipe, pick, prop, cloneDeep, isArray, has } from 'lodash/fp';
|
|
3
|
+
import { contentTypes as contentTypes$1, errors } from '@strapi/utils';
|
|
4
|
+
import { getService } from '../utils/index.mjs';
|
|
5
|
+
|
|
6
|
+
const { isRelationalAttribute, getVisibleAttributes, isTypedAttribute, getScalarAttributes, getRelationalAttributes } = contentTypes$1;
|
|
7
|
+
const { ApplicationError } = errors;
|
|
8
|
+
const hasLocalizedOption = (modelOrAttribute)=>{
|
|
9
|
+
return prop('pluginOptions.i18n.localized', modelOrAttribute) === true;
|
|
10
|
+
};
|
|
11
|
+
const getValidLocale = async (locale)=>{
|
|
12
|
+
const localesService = getService('locales');
|
|
13
|
+
if (isNil(locale)) {
|
|
14
|
+
return localesService.getDefaultLocale();
|
|
15
|
+
}
|
|
16
|
+
const foundLocale = await localesService.findByCode(locale);
|
|
17
|
+
if (!foundLocale) {
|
|
18
|
+
throw new ApplicationError('Locale not found');
|
|
19
|
+
}
|
|
20
|
+
return locale;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Returns whether an attribute is localized or not
|
|
24
|
+
* @param {*} attribute
|
|
25
|
+
* @returns
|
|
26
|
+
*/ const isLocalizedAttribute = (attribute)=>{
|
|
27
|
+
return hasLocalizedOption(attribute) || isRelationalAttribute(attribute) || isTypedAttribute(attribute, 'uid');
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Returns whether a model is localized or not
|
|
31
|
+
* @param {*} model
|
|
32
|
+
* @returns
|
|
33
|
+
*/ const isLocalizedContentType = (model)=>{
|
|
34
|
+
return hasLocalizedOption(model);
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Returns the list of attribute names that are not localized
|
|
38
|
+
* @param {object} model
|
|
39
|
+
* @returns {string[]}
|
|
40
|
+
*/ const getNonLocalizedAttributes = (model)=>{
|
|
41
|
+
return getVisibleAttributes(model).filter((attrName)=>!isLocalizedAttribute(model.attributes[attrName]));
|
|
42
|
+
};
|
|
43
|
+
const removeId = (value)=>{
|
|
44
|
+
if (typeof value === 'object' && has('id', value)) {
|
|
45
|
+
delete value.id;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const removeIds = (model)=>(entry)=>removeIdsMut(model, cloneDeep(entry));
|
|
49
|
+
const removeIdsMut = (model, entry)=>{
|
|
50
|
+
if (isNil(entry)) {
|
|
51
|
+
return entry;
|
|
52
|
+
}
|
|
53
|
+
removeId(entry);
|
|
54
|
+
_.forEach(model.attributes, (attr, attrName)=>{
|
|
55
|
+
const value = entry[attrName];
|
|
56
|
+
if (attr.type === 'dynamiczone' && isArray(value)) {
|
|
57
|
+
value.forEach((compo)=>{
|
|
58
|
+
if (has('__component', compo)) {
|
|
59
|
+
const model = strapi.components[compo.__component];
|
|
60
|
+
removeIdsMut(model, compo);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
} else if (attr.type === 'component') {
|
|
64
|
+
const model = strapi.components[attr.component];
|
|
65
|
+
if (isArray(value)) {
|
|
66
|
+
value.forEach((compo)=>removeIdsMut(model, compo));
|
|
67
|
+
} else {
|
|
68
|
+
removeIdsMut(model, value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return entry;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Returns a copy of an entry picking only its non localized attributes
|
|
76
|
+
* @param {object} model
|
|
77
|
+
* @param {object} entry
|
|
78
|
+
* @returns {object}
|
|
79
|
+
*/ const copyNonLocalizedAttributes = (model, entry)=>{
|
|
80
|
+
const nonLocalizedAttributes = getNonLocalizedAttributes(model);
|
|
81
|
+
return pipe(pick(nonLocalizedAttributes), removeIds(model))(entry);
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Returns the list of attribute names that are localized
|
|
85
|
+
* @param {object} model
|
|
86
|
+
* @returns {string[]}
|
|
87
|
+
*/ const getLocalizedAttributes = (model)=>{
|
|
88
|
+
return getVisibleAttributes(model).filter((attrName)=>isLocalizedAttribute(model.attributes[attrName]));
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Fill non localized fields of an entry if there are nil
|
|
92
|
+
* @param {Object} entry entry to fill
|
|
93
|
+
* @param {Object} relatedEntry values used to fill
|
|
94
|
+
* @param {Object} options
|
|
95
|
+
* @param {Object} options.model corresponding model
|
|
96
|
+
*/ const fillNonLocalizedAttributes = (entry, relatedEntry, { model })=>{
|
|
97
|
+
if (isNil(relatedEntry)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const modelDef = strapi.getModel(model);
|
|
101
|
+
const relatedEntryCopy = copyNonLocalizedAttributes(modelDef, relatedEntry);
|
|
102
|
+
_.forEach(relatedEntryCopy, (value, field)=>{
|
|
103
|
+
if (isNil(entry[field])) {
|
|
104
|
+
entry[field] = value;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* build the populate param to
|
|
110
|
+
* @param {String} modelUID uid of the model, could be of a content-type or a component
|
|
111
|
+
*/ const getNestedPopulateOfNonLocalizedAttributes = (modelUID)=>{
|
|
112
|
+
const schema = strapi.getModel(modelUID);
|
|
113
|
+
const scalarAttributes = getScalarAttributes(schema);
|
|
114
|
+
const nonLocalizedAttributes = getNonLocalizedAttributes(schema);
|
|
115
|
+
const allAttributes = [
|
|
116
|
+
...scalarAttributes,
|
|
117
|
+
...nonLocalizedAttributes
|
|
118
|
+
];
|
|
119
|
+
if (schema.modelType === 'component') {
|
|
120
|
+
// When called recursively on a non localized component we
|
|
121
|
+
// need to explicitly populate that components relations
|
|
122
|
+
allAttributes.push(...getRelationalAttributes(schema));
|
|
123
|
+
}
|
|
124
|
+
const currentAttributesToPopulate = allAttributes.filter((value, index, self)=>{
|
|
125
|
+
return self.indexOf(value) === index && self.lastIndexOf(value) === index;
|
|
126
|
+
});
|
|
127
|
+
const attributesToPopulate = [
|
|
128
|
+
...currentAttributesToPopulate
|
|
129
|
+
];
|
|
130
|
+
for (const attrName of currentAttributesToPopulate){
|
|
131
|
+
const attr = schema.attributes[attrName];
|
|
132
|
+
if (attr.type === 'component') {
|
|
133
|
+
const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(attr.component).map((nestedAttr)=>`${attrName}.${nestedAttr}`);
|
|
134
|
+
attributesToPopulate.push(...nestedPopulate);
|
|
135
|
+
} else if (attr.type === 'dynamiczone') {
|
|
136
|
+
attr.components.forEach((componentName)=>{
|
|
137
|
+
const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(componentName).map((nestedAttr)=>`${attrName}.${nestedAttr}`);
|
|
138
|
+
attributesToPopulate.push(...nestedPopulate);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return attributesToPopulate;
|
|
143
|
+
};
|
|
144
|
+
const contentTypes = ()=>({
|
|
145
|
+
isLocalizedContentType,
|
|
146
|
+
getValidLocale,
|
|
147
|
+
getLocalizedAttributes,
|
|
148
|
+
getNonLocalizedAttributes,
|
|
149
|
+
copyNonLocalizedAttributes,
|
|
150
|
+
fillNonLocalizedAttributes,
|
|
151
|
+
getNestedPopulateOfNonLocalizedAttributes
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
export { contentTypes as default };
|
|
155
|
+
//# sourceMappingURL=content-types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-types.mjs","sources":["../../../server/src/services/content-types.ts"],"sourcesContent":["import _ from 'lodash';\nimport { pick, pipe, has, prop, isNil, cloneDeep, isArray } from 'lodash/fp';\nimport { errors, contentTypes as contentTypeUtils } from '@strapi/utils';\nimport { getService } from '../utils';\n\nconst {\n isRelationalAttribute,\n getVisibleAttributes,\n isTypedAttribute,\n getScalarAttributes,\n getRelationalAttributes,\n} = contentTypeUtils;\nconst { ApplicationError } = errors;\n\nconst hasLocalizedOption = (modelOrAttribute: any) => {\n return prop('pluginOptions.i18n.localized', modelOrAttribute) === true;\n};\n\nconst getValidLocale = async (locale: any) => {\n const localesService = getService('locales');\n\n if (isNil(locale)) {\n return localesService.getDefaultLocale();\n }\n\n const foundLocale = await localesService.findByCode(locale);\n if (!foundLocale) {\n throw new ApplicationError('Locale not found');\n }\n\n return locale;\n};\n\n/**\n * Returns whether an attribute is localized or not\n * @param {*} attribute\n * @returns\n */\nconst isLocalizedAttribute = (attribute: any) => {\n return (\n hasLocalizedOption(attribute) ||\n isRelationalAttribute(attribute) ||\n isTypedAttribute(attribute, 'uid')\n );\n};\n\n/**\n * Returns whether a model is localized or not\n * @param {*} model\n * @returns\n */\nconst isLocalizedContentType = (model: any) => {\n return hasLocalizedOption(model);\n};\n\n/**\n * Returns the list of attribute names that are not localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getNonLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter(\n (attrName) => !isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\nconst removeId = (value: any) => {\n if (typeof value === 'object' && has('id', value)) {\n delete value.id;\n }\n};\n\nconst removeIds = (model: any) => (entry: any) => removeIdsMut(model, cloneDeep(entry));\n\nconst removeIdsMut = (model: any, entry: any) => {\n if (isNil(entry)) {\n return entry;\n }\n\n removeId(entry);\n\n _.forEach(model.attributes, (attr, attrName) => {\n const value = entry[attrName];\n if (attr.type === 'dynamiczone' && isArray(value)) {\n value.forEach((compo) => {\n if (has('__component', compo)) {\n const model = strapi.components[compo.__component];\n removeIdsMut(model, compo);\n }\n });\n } else if (attr.type === 'component') {\n const model = strapi.components[attr.component];\n if (isArray(value)) {\n value.forEach((compo) => removeIdsMut(model, compo));\n } else {\n removeIdsMut(model, value);\n }\n }\n });\n\n return entry;\n};\n\n/**\n * Returns a copy of an entry picking only its non localized attributes\n * @param {object} model\n * @param {object} entry\n * @returns {object}\n */\nconst copyNonLocalizedAttributes = (model: any, entry: any) => {\n const nonLocalizedAttributes = getNonLocalizedAttributes(model);\n\n return pipe(pick(nonLocalizedAttributes), removeIds(model))(entry);\n};\n\n/**\n * Returns the list of attribute names that are localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter((attrName) =>\n isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\n/**\n * Fill non localized fields of an entry if there are nil\n * @param {Object} entry entry to fill\n * @param {Object} relatedEntry values used to fill\n * @param {Object} options\n * @param {Object} options.model corresponding model\n */\nconst fillNonLocalizedAttributes = (entry: any, relatedEntry: any, { model }: any) => {\n if (isNil(relatedEntry)) {\n return;\n }\n\n const modelDef = strapi.getModel(model);\n const relatedEntryCopy = copyNonLocalizedAttributes(modelDef, relatedEntry);\n\n _.forEach(relatedEntryCopy, (value, field) => {\n if (isNil(entry[field])) {\n entry[field] = value;\n }\n });\n};\n\n/**\n * build the populate param to\n * @param {String} modelUID uid of the model, could be of a content-type or a component\n */\nconst getNestedPopulateOfNonLocalizedAttributes = (modelUID: any) => {\n const schema = strapi.getModel(modelUID);\n const scalarAttributes = getScalarAttributes(schema);\n const nonLocalizedAttributes = getNonLocalizedAttributes(schema);\n\n const allAttributes = [...scalarAttributes, ...nonLocalizedAttributes];\n if (schema.modelType === 'component') {\n // When called recursively on a non localized component we\n // need to explicitly populate that components relations\n allAttributes.push(...getRelationalAttributes(schema));\n }\n\n const currentAttributesToPopulate = allAttributes.filter((value, index, self) => {\n return self.indexOf(value) === index && self.lastIndexOf(value) === index;\n });\n\n const attributesToPopulate = [...currentAttributesToPopulate];\n for (const attrName of currentAttributesToPopulate) {\n const attr = schema.attributes[attrName];\n if (attr.type === 'component') {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(attr.component).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n } else if (attr.type === 'dynamiczone') {\n attr.components.forEach((componentName) => {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(componentName).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n });\n }\n }\n\n return attributesToPopulate;\n};\n\nconst contentTypes = () => ({\n isLocalizedContentType,\n getValidLocale,\n getLocalizedAttributes,\n getNonLocalizedAttributes,\n copyNonLocalizedAttributes,\n fillNonLocalizedAttributes,\n getNestedPopulateOfNonLocalizedAttributes,\n});\n\ntype ContentTypesService = typeof contentTypes;\n\nexport default contentTypes;\nexport { ContentTypesService };\n"],"names":["isRelationalAttribute","getVisibleAttributes","isTypedAttribute","getScalarAttributes","getRelationalAttributes","contentTypeUtils","ApplicationError","errors","hasLocalizedOption","modelOrAttribute","prop","getValidLocale","locale","localesService","getService","isNil","getDefaultLocale","foundLocale","findByCode","isLocalizedAttribute","attribute","isLocalizedContentType","model","getNonLocalizedAttributes","filter","attrName","attributes","removeId","value","has","id","removeIds","entry","removeIdsMut","cloneDeep","_","forEach","attr","type","isArray","compo","strapi","components","__component","component","copyNonLocalizedAttributes","nonLocalizedAttributes","pipe","pick","getLocalizedAttributes","fillNonLocalizedAttributes","relatedEntry","modelDef","getModel","relatedEntryCopy","field","getNestedPopulateOfNonLocalizedAttributes","modelUID","schema","scalarAttributes","allAttributes","modelType","push","currentAttributesToPopulate","index","self","indexOf","lastIndexOf","attributesToPopulate","nestedPopulate","map","nestedAttr","componentName","contentTypes"],"mappings":";;;;;AAKA,MAAM,EACJA,qBAAqB,EACrBC,oBAAoB,EACpBC,gBAAgB,EAChBC,mBAAmB,EACnBC,uBAAuB,EACxB,GAAGC,cAAAA;AACJ,MAAM,EAAEC,gBAAgB,EAAE,GAAGC,MAAAA;AAE7B,MAAMC,qBAAqB,CAACC,gBAAAA,GAAAA;IAC1B,OAAOC,IAAAA,CAAK,gCAAgCD,gBAAsB,CAAA,KAAA,IAAA;AACpE,CAAA;AAEA,MAAME,iBAAiB,OAAOC,MAAAA,GAAAA;AAC5B,IAAA,MAAMC,iBAAiBC,UAAW,CAAA,SAAA,CAAA;AAElC,IAAA,IAAIC,MAAMH,MAAS,CAAA,EAAA;AACjB,QAAA,OAAOC,eAAeG,gBAAgB,EAAA;AACxC;AAEA,IAAA,MAAMC,WAAc,GAAA,MAAMJ,cAAeK,CAAAA,UAAU,CAACN,MAAAA,CAAAA;AACpD,IAAA,IAAI,CAACK,WAAa,EAAA;AAChB,QAAA,MAAM,IAAIX,gBAAiB,CAAA,kBAAA,CAAA;AAC7B;IAEA,OAAOM,MAAAA;AACT,CAAA;AAEA;;;;IAKA,MAAMO,uBAAuB,CAACC,SAAAA,GAAAA;AAC5B,IAAA,OACEZ,kBAAmBY,CAAAA,SAAAA,CAAAA,IACnBpB,qBAAsBoB,CAAAA,SAAAA,CAAAA,IACtBlB,iBAAiBkB,SAAW,EAAA,KAAA,CAAA;AAEhC,CAAA;AAEA;;;;IAKA,MAAMC,yBAAyB,CAACC,KAAAA,GAAAA;AAC9B,IAAA,OAAOd,kBAAmBc,CAAAA,KAAAA,CAAAA;AAC5B,CAAA;AAEA;;;;IAKA,MAAMC,4BAA4B,CAACD,KAAAA,GAAAA;IACjC,OAAOrB,oBAAAA,CAAqBqB,KAAOE,CAAAA,CAAAA,MAAM,CACvC,CAACC,QA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CAAC,CAAA;AAE7CH,YAAAA,oBAAAA,CAAqBN,IAAI,CAAIO,GAAAA,cAAAA,CAAAA;AAC/B,SAAA,MAAO,IAAIhC,IAAAA,CAAKC,IAAI,KAAK,aAAe,EAAA;AACtCD,YAAAA,IAAAA,CAAKK,UAAU,CAACN,OAAO,CAAC,CAACoC,aAAAA,GAAAA;AACvB,gBAAA,MAAMH,cAAiBb,GAAAA,yCAAAA,CAA0CgB,aAAeF,CAAAA,CAAAA,GAAG,CACjF,CAACC,UAAe,GAAA,CAAC,EAAE9C,QAAAA,CAAS,CAAC,EAAE8C,WAAW,CAAC,CAAA;AAE7CH,gBAAAA,oBAAAA,CAAqBN,IAAI,CAAIO,GAAAA,cAAAA,CAAAA;AAC/B,aAAA,CAAA;AACF;AACF;IAEA,OAAOD,oBAAAA;AACT,CAAA;AAEMK,MAAAA,YAAAA,GAAe,KAAO;AAC1BpD,QAAAA,sBAAAA;AACAV,QAAAA,cAAAA;AACAsC,QAAAA,sBAAAA;AACA1B,QAAAA,yBAAAA;AACAsB,QAAAA,0BAAAA;AACAK,QAAAA,0BAAAA;AACAM,QAAAA;KACF;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var permissions = require('./permissions.js');
|
|
4
|
+
var metrics = require('./metrics.js');
|
|
5
|
+
var localizations = require('./localizations.js');
|
|
6
|
+
var locales = require('./locales.js');
|
|
7
|
+
var isoLocales = require('./iso-locales.js');
|
|
8
|
+
var contentTypes = require('./content-types.js');
|
|
9
|
+
var index = require('./sanitize/index.js');
|
|
10
|
+
var settings = require('./settings.js');
|
|
11
|
+
var aiLocalizations = require('./ai-localizations.js');
|
|
12
|
+
|
|
13
|
+
var services = {
|
|
14
|
+
permissions,
|
|
15
|
+
metrics,
|
|
16
|
+
localizations,
|
|
17
|
+
locales,
|
|
18
|
+
sanitize: index,
|
|
19
|
+
'iso-locales': isoLocales,
|
|
20
|
+
'content-types': contentTypes,
|
|
21
|
+
'ai-localizations': aiLocalizations.createAILocalizationsService,
|
|
22
|
+
settings: settings.createSettingsService
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
module.exports = services;
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../server/src/services/index.ts"],"sourcesContent":["import permissions from './permissions';\nimport metrics from './metrics';\nimport localizations from './localizations';\nimport locales from './locales';\nimport isoLocales from './iso-locales';\nimport contentTypes from './content-types';\nimport sanitize from './sanitize';\nimport { createSettingsService } from './settings';\nimport { createAILocalizationsService } from './ai-localizations';\n\nexport default {\n permissions,\n metrics,\n localizations,\n locales,\n sanitize,\n 'iso-locales': isoLocales,\n 'content-types': contentTypes,\n 'ai-localizations': createAILocalizationsService,\n settings: createSettingsService,\n};\n"],"names":["permissions","metrics","localizations","locales","sanitize","isoLocales","contentTypes","createAILocalizationsService","settings","createSettingsService"],"mappings":";;;;;;;;;;;;AAUA,eAAe;AACbA,IAAAA,WAAAA;AACAC,IAAAA,OAAAA;AACAC,IAAAA,aAAAA;AACAC,IAAAA,OAAAA;AACAC,cAAAA,KAAAA;IACA,aAAeC,EAAAA,UAAAA;IACf,eAAiBC,EAAAA,YAAAA;IACjB,kBAAoBC,EAAAA,4CAAAA;IACpBC,QAAUC,EAAAA;AACZ,CAAE;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import permissions from './permissions.mjs';
|
|
2
|
+
import metrics from './metrics.mjs';
|
|
3
|
+
import localizations from './localizations.mjs';
|
|
4
|
+
import locales from './locales.mjs';
|
|
5
|
+
import isoLocalesService from './iso-locales.mjs';
|
|
6
|
+
import contentTypes from './content-types.mjs';
|
|
7
|
+
import sanitize from './sanitize/index.mjs';
|
|
8
|
+
import { createSettingsService } from './settings.mjs';
|
|
9
|
+
import { createAILocalizationsService } from './ai-localizations.mjs';
|
|
10
|
+
|
|
11
|
+
var services = {
|
|
12
|
+
permissions,
|
|
13
|
+
metrics,
|
|
14
|
+
localizations,
|
|
15
|
+
locales,
|
|
16
|
+
sanitize,
|
|
17
|
+
'iso-locales': isoLocalesService,
|
|
18
|
+
'content-types': contentTypes,
|
|
19
|
+
'ai-localizations': createAILocalizationsService,
|
|
20
|
+
settings: createSettingsService
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { services as default };
|
|
24
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../server/src/services/index.ts"],"sourcesContent":["import permissions from './permissions';\nimport metrics from './metrics';\nimport localizations from './localizations';\nimport locales from './locales';\nimport isoLocales from './iso-locales';\nimport contentTypes from './content-types';\nimport sanitize from './sanitize';\nimport { createSettingsService } from './settings';\nimport { createAILocalizationsService } from './ai-localizations';\n\nexport default {\n permissions,\n metrics,\n localizations,\n locales,\n sanitize,\n 'iso-locales': isoLocales,\n 'content-types': contentTypes,\n 'ai-localizations': createAILocalizationsService,\n settings: createSettingsService,\n};\n"],"names":["permissions","metrics","localizations","locales","sanitize","isoLocales","contentTypes","createAILocalizationsService","settings","createSettingsService"],"mappings":";;;;;;;;;;AAUA,eAAe;AACbA,IAAAA,WAAAA;AACAC,IAAAA,OAAAA;AACAC,IAAAA,aAAAA;AACAC,IAAAA,OAAAA;AACAC,IAAAA,QAAAA;IACA,aAAeC,EAAAA,iBAAAA;IACf,eAAiBC,EAAAA,YAAAA;IACjB,kBAAoBC,EAAAA,4BAAAA;IACpBC,QAAUC,EAAAA;AACZ,CAAE;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../constants/index.js');
|
|
4
|
+
var isoLocales = require('../constants/iso-locales.json.js');
|
|
5
|
+
|
|
6
|
+
const getIsoLocales = ()=>isoLocales;
|
|
7
|
+
const isoLocalesService = ()=>({
|
|
8
|
+
getIsoLocales
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
module.exports = isoLocalesService;
|
|
12
|
+
//# sourceMappingURL=iso-locales.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iso-locales.js","sources":["../../../server/src/services/iso-locales.ts"],"sourcesContent":["import { isoLocales } from '../constants';\n\nconst getIsoLocales = () => isoLocales;\n\nconst isoLocalesService = () => ({\n getIsoLocales,\n});\n\ntype ISOLocalesService = typeof isoLocalesService;\n\nexport default isoLocalesService;\nexport type { ISOLocalesService };\n"],"names":["getIsoLocales","isoLocales","isoLocalesService"],"mappings":";;;;;AAEA,MAAMA,gBAAgB,IAAMC,UAAAA;AAEtBC,MAAAA,iBAAAA,GAAoB,KAAO;AAC/BF,QAAAA;KACF;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import '../constants/index.mjs';
|
|
2
|
+
import isoLocales from '../constants/iso-locales.json.mjs';
|
|
3
|
+
|
|
4
|
+
const getIsoLocales = ()=>isoLocales;
|
|
5
|
+
const isoLocalesService = ()=>({
|
|
6
|
+
getIsoLocales
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export { isoLocalesService as default };
|
|
10
|
+
//# sourceMappingURL=iso-locales.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iso-locales.mjs","sources":["../../../server/src/services/iso-locales.ts"],"sourcesContent":["import { isoLocales } from '../constants';\n\nconst getIsoLocales = () => isoLocales;\n\nconst isoLocalesService = () => ({\n getIsoLocales,\n});\n\ntype ISOLocalesService = typeof isoLocalesService;\n\nexport default isoLocalesService;\nexport type { ISOLocalesService };\n"],"names":["getIsoLocales","isoLocales","isoLocalesService"],"mappings":";;;AAEA,MAAMA,gBAAgB,IAAMC,UAAAA;AAEtBC,MAAAA,iBAAAA,GAAoB,KAAO;AAC/BF,QAAAA;KACF;;;;"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fp = require('lodash/fp');
|
|
4
|
+
var index$1 = require('../constants/index.js');
|
|
5
|
+
var index = require('../utils/index.js');
|
|
6
|
+
|
|
7
|
+
const find = (params = {})=>strapi.db.query('plugin::i18n.locale').findMany({
|
|
8
|
+
where: params
|
|
9
|
+
});
|
|
10
|
+
const findById = (id)=>strapi.db.query('plugin::i18n.locale').findOne({
|
|
11
|
+
where: {
|
|
12
|
+
id
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
const findByCode = (code)=>strapi.db.query('plugin::i18n.locale').findOne({
|
|
16
|
+
where: {
|
|
17
|
+
code
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const count = (params = {})=>strapi.db.query('plugin::i18n.locale').count({
|
|
21
|
+
where: params
|
|
22
|
+
});
|
|
23
|
+
const create = async (locale)=>{
|
|
24
|
+
const result = await strapi.db.query('plugin::i18n.locale').create({
|
|
25
|
+
data: locale
|
|
26
|
+
});
|
|
27
|
+
index.getService('metrics').sendDidUpdateI18nLocalesEvent();
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
const update = async (params, updates)=>{
|
|
31
|
+
const result = await strapi.db.query('plugin::i18n.locale').update({
|
|
32
|
+
where: params,
|
|
33
|
+
data: updates
|
|
34
|
+
});
|
|
35
|
+
index.getService('metrics').sendDidUpdateI18nLocalesEvent();
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
const deleteFn = async ({ id })=>{
|
|
39
|
+
const localeToDelete = await findById(id);
|
|
40
|
+
if (localeToDelete) {
|
|
41
|
+
await deleteAllLocalizedEntriesFor({
|
|
42
|
+
locale: localeToDelete.code
|
|
43
|
+
});
|
|
44
|
+
const result = await strapi.db.query('plugin::i18n.locale').delete({
|
|
45
|
+
where: {
|
|
46
|
+
id
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
index.getService('metrics').sendDidUpdateI18nLocalesEvent();
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
return localeToDelete;
|
|
53
|
+
};
|
|
54
|
+
const setDefaultLocale = ({ code })=>index.getCoreStore().set({
|
|
55
|
+
key: 'default_locale',
|
|
56
|
+
value: code
|
|
57
|
+
});
|
|
58
|
+
const getDefaultLocale = ()=>index.getCoreStore().get({
|
|
59
|
+
key: 'default_locale'
|
|
60
|
+
});
|
|
61
|
+
const setIsDefault = async (locales)=>{
|
|
62
|
+
if (fp.isNil(locales)) {
|
|
63
|
+
return locales;
|
|
64
|
+
}
|
|
65
|
+
const actualDefault = await getDefaultLocale();
|
|
66
|
+
if (Array.isArray(locales)) {
|
|
67
|
+
return locales.map((locale)=>({
|
|
68
|
+
...locale,
|
|
69
|
+
isDefault: actualDefault === locale.code
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
// single locale
|
|
73
|
+
return {
|
|
74
|
+
...locales,
|
|
75
|
+
isDefault: actualDefault === locales.code
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const initDefaultLocale = async ()=>{
|
|
79
|
+
const existingLocalesNb = await strapi.db.query('plugin::i18n.locale').count();
|
|
80
|
+
if (existingLocalesNb === 0) {
|
|
81
|
+
await create(index$1.DEFAULT_LOCALE);
|
|
82
|
+
await setDefaultLocale({
|
|
83
|
+
code: index$1.DEFAULT_LOCALE.code
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const deleteAllLocalizedEntriesFor = async ({ locale })=>{
|
|
88
|
+
const { isLocalizedContentType } = index.getService('content-types');
|
|
89
|
+
const localizedModels = Object.values(strapi.contentTypes).filter(isLocalizedContentType);
|
|
90
|
+
for (const model of localizedModels){
|
|
91
|
+
// FIXME: delete many content & their associations
|
|
92
|
+
await strapi.db.query(model.uid).deleteMany({
|
|
93
|
+
where: {
|
|
94
|
+
locale
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const locales = ()=>({
|
|
100
|
+
find,
|
|
101
|
+
findById,
|
|
102
|
+
findByCode,
|
|
103
|
+
create,
|
|
104
|
+
update,
|
|
105
|
+
count,
|
|
106
|
+
setDefaultLocale,
|
|
107
|
+
getDefaultLocale,
|
|
108
|
+
setIsDefault,
|
|
109
|
+
delete: deleteFn,
|
|
110
|
+
initDefaultLocale
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
module.exports = locales;
|
|
114
|
+
//# sourceMappingURL=locales.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locales.js","sources":["../../../server/src/services/locales.ts"],"sourcesContent":["import { isNil } from 'lodash/fp';\nimport { DEFAULT_LOCALE } from '../constants';\nimport { getService, getCoreStore } from '../utils';\n\nconst find = (params: any = {}) =>\n strapi.db.query('plugin::i18n.locale').findMany({ where: params });\n\nconst findById = (id: any) => strapi.db.query('plugin::i18n.locale').findOne({ where: { id } });\n\nconst findByCode = (code: any) =>\n strapi.db.query('plugin::i18n.locale').findOne({ where: { code } });\n\nconst count = (params: any = {}) => strapi.db.query('plugin::i18n.locale').count({ where: params });\n\nconst create = async (locale: any) => {\n const result = await strapi.db.query('plugin::i18n.locale').create({ data: locale });\n\n getService('metrics').sendDidUpdateI18nLocalesEvent();\n\n return result;\n};\n\nconst update = async (params: any, updates: any) => {\n const result = await strapi.db\n .query('plugin::i18n.locale')\n .update({ where: params, data: updates });\n\n getService('metrics').sendDidUpdateI18nLocalesEvent();\n\n return result;\n};\n\nconst deleteFn = async ({ id }: any) => {\n const localeToDelete = await findById(id);\n\n if (localeToDelete) {\n await deleteAllLocalizedEntriesFor({ locale: localeToDelete.code });\n const result = await strapi.db.query('plugin::i18n.locale').delete({ where: { id } });\n\n getService('metrics').sendDidUpdateI18nLocalesEvent();\n\n return result;\n }\n\n return localeToDelete;\n};\n\nconst setDefaultLocale = ({ code }: any) =>\n getCoreStore().set({ key: 'default_locale', value: code });\n\nconst getDefaultLocale = () => getCoreStore().get({ key: 'default_locale' });\n\nconst setIsDefault = async (locales: any) => {\n if (isNil(locales)) {\n return locales;\n }\n\n const actualDefault = await getDefaultLocale();\n\n if (Array.isArray(locales)) {\n return locales.map((locale) => ({ ...locale, isDefault: actualDefault === locale.code }));\n }\n // single locale\n return { ...locales, isDefault: actualDefault === locales.code };\n};\n\nconst initDefaultLocale = async () => {\n const existingLocalesNb = await strapi.db.query('plugin::i18n.locale').count();\n if (existingLocalesNb === 0) {\n await create(DEFAULT_LOCALE);\n await setDefaultLocale({ code: DEFAULT_LOCALE.code });\n }\n};\n\nconst deleteAllLocalizedEntriesFor = async ({ locale }: any) => {\n const { isLocalizedContentType } = getService('content-types');\n\n const localizedModels = Object.values(strapi.contentTypes).filter(isLocalizedContentType);\n\n for (const model of localizedModels) {\n // FIXME: delete many content & their associations\n await strapi.db.query(model.uid).deleteMany({ where: { locale } });\n }\n};\n\nconst locales = () => ({\n find,\n findById,\n findByCode,\n create,\n update,\n count,\n setDefaultLocale,\n getDefaultLocale,\n setIsDefault,\n delete: deleteFn,\n initDefaultLocale,\n});\n\ntype LocaleService = typeof locales;\n\nexport default locales;\nexport type { LocaleService };\n"],"names":["find","params","strapi","db","query","findMany","where","findById","id","findOne","findByCode","code","count","create","locale","result","data","getService","sendDidUpdateI18nLocalesEvent","update","updates","deleteFn","localeToDelete","deleteAllLocalizedEntriesFor","delete","setDefaultLocale","getCoreStore","set","key","value","getDefaultLocale","get","setIsDefault","locales","isNil","actualDefault","Array","isArray","map","isDefault","initDefaultLocale","existingLocalesNb","DEFAULT_LOCALE","isLocalizedContentType","localizedModels","Object","values","contentTypes","filter","model","uid","deleteMany"],"mappings":";;;;;;AAIA,MAAMA,IAAO,GAAA,CAACC,MAAc,GAAA,EAAE,GAC5BC,MAAOC,CAAAA,EAAE,CAACC,KAAK,CAAC,qBAAA,CAAA,CAAuBC,QAAQ,CAAC;QAAEC,KAAOL,EAAAA;AAAO,KAAA,CAAA;AAElE,MAAMM,QAAAA,GAAW,CAACC,EAAAA,GAAYN,MAAOC,CAAAA,EAAE,CAACC,KAAK,CAAC,qBAAuBK,CAAAA,C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