@strapi/i18n 0.0.0-next.e1a19b9e52cdcb526515883c8289522a64c9871a → 0.0.0-next.e2e3ca14971ee768e1a227a209362264fd0132d4
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 +2 -2
- package/dist/admin/components/BulkLocaleActionModal.js.map +1 -1
- package/dist/admin/components/BulkLocaleActionModal.mjs +2 -2
- package/dist/admin/components/BulkLocaleActionModal.mjs.map +1 -1
- package/dist/admin/components/CMHeaderActions.js +294 -20
- package/dist/admin/components/CMHeaderActions.js.map +1 -1
- package/dist/admin/components/CMHeaderActions.mjs +298 -25
- package/dist/admin/components/CMHeaderActions.mjs.map +1 -1
- package/dist/admin/components/CreateLocale.js +11 -5
- package/dist/admin/components/CreateLocale.js.map +1 -1
- package/dist/admin/components/CreateLocale.mjs +12 -6
- package/dist/admin/components/CreateLocale.mjs.map +1 -1
- package/dist/admin/components/LocaleListCell.js +65 -45
- package/dist/admin/components/LocaleListCell.js.map +1 -1
- package/dist/admin/components/LocaleListCell.mjs +66 -46
- package/dist/admin/components/LocaleListCell.mjs.map +1 -1
- package/dist/admin/components/LocalePicker.js +18 -11
- package/dist/admin/components/LocalePicker.js.map +1 -1
- package/dist/admin/components/LocalePicker.mjs +19 -12
- package/dist/admin/components/LocalePicker.mjs.map +1 -1
- package/dist/admin/contentManagerHooks/editView.js +6 -3
- package/dist/admin/contentManagerHooks/editView.js.map +1 -1
- package/dist/admin/contentManagerHooks/editView.mjs +7 -4
- package/dist/admin/contentManagerHooks/editView.mjs.map +1 -1
- package/dist/admin/contentManagerHooks/listView.js +2 -1
- package/dist/admin/contentManagerHooks/listView.js.map +1 -1
- package/dist/admin/contentManagerHooks/listView.mjs +2 -1
- package/dist/admin/contentManagerHooks/listView.mjs.map +1 -1
- package/dist/admin/hooks/useAILocalizationJobsPolling.js +110 -0
- package/dist/admin/hooks/useAILocalizationJobsPolling.js.map +1 -0
- package/dist/admin/hooks/useAILocalizationJobsPolling.mjs +89 -0
- package/dist/admin/hooks/useAILocalizationJobsPolling.mjs.map +1 -0
- package/dist/admin/hooks/useI18n.js +4 -4
- package/dist/admin/hooks/useI18n.js.map +1 -1
- package/dist/admin/hooks/useI18n.mjs +4 -4
- package/dist/admin/hooks/useI18n.mjs.map +1 -1
- package/dist/admin/index.js +1 -0
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +2 -1
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/pages/SettingsPage.js +121 -46
- package/dist/admin/pages/SettingsPage.js.map +1 -1
- package/dist/admin/pages/SettingsPage.mjs +124 -30
- package/dist/admin/pages/SettingsPage.mjs.map +1 -1
- package/dist/admin/services/aiLocalizationJobs.js +26 -0
- package/dist/admin/services/aiLocalizationJobs.js.map +1 -0
- package/dist/admin/services/aiLocalizationJobs.mjs +24 -0
- package/dist/admin/services/aiLocalizationJobs.mjs.map +1 -0
- package/dist/admin/services/api.js +3 -1
- package/dist/admin/services/api.js.map +1 -1
- package/dist/admin/services/api.mjs +3 -1
- package/dist/admin/services/api.mjs.map +1 -1
- package/dist/admin/services/locales.js.map +1 -1
- package/dist/admin/services/locales.mjs.map +1 -1
- package/dist/admin/services/settings.js +30 -0
- package/dist/admin/services/settings.js.map +1 -0
- package/dist/admin/services/settings.mjs +27 -0
- package/dist/admin/services/settings.mjs.map +1 -0
- package/dist/admin/src/components/CMHeaderActions.d.ts +17 -4
- package/dist/admin/src/components/LocaleListCell.d.ts +2 -1
- package/dist/admin/src/hooks/useAILocalizationJobsPolling.d.ts +9 -0
- package/dist/admin/src/services/aiLocalizationJobs.d.ts +6 -0
- 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/translations/en.json.js +10 -0
- package/dist/admin/translations/en.json.js.map +1 -1
- package/dist/admin/translations/en.json.mjs +10 -0
- package/dist/admin/translations/en.json.mjs.map +1 -1
- package/dist/admin/utils/clean.js +2 -2
- package/dist/admin/utils/clean.js.map +1 -1
- package/dist/admin/utils/clean.mjs +2 -2
- package/dist/admin/utils/clean.mjs.map +1 -1
- package/dist/admin/utils/getTranslation.js.map +1 -1
- package/dist/admin/utils/getTranslation.mjs.map +1 -1
- package/dist/admin/utils/prefixPluginTranslations.js.map +1 -1
- package/dist/admin/utils/prefixPluginTranslations.mjs.map +1 -1
- package/dist/server/bootstrap.js +24 -8
- package/dist/server/bootstrap.js.map +1 -1
- package/dist/server/bootstrap.mjs +24 -8
- package/dist/server/bootstrap.mjs.map +1 -1
- package/dist/server/constants/iso-locales.json.js +4 -0
- package/dist/server/constants/iso-locales.json.js.map +1 -1
- package/dist/server/constants/iso-locales.json.mjs +4 -0
- package/dist/server/constants/iso-locales.json.mjs.map +1 -1
- package/dist/server/controllers/ai-localization-jobs.js +47 -0
- package/dist/server/controllers/ai-localization-jobs.js.map +1 -0
- package/dist/server/controllers/ai-localization-jobs.mjs +45 -0
- package/dist/server/controllers/ai-localization-jobs.mjs.map +1 -0
- package/dist/server/controllers/index.js +5 -1
- package/dist/server/controllers/index.js.map +1 -1
- package/dist/server/controllers/index.mjs +5 -1
- package/dist/server/controllers/index.mjs.map +1 -1
- 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/models/ai-localization-job.js +60 -0
- package/dist/server/models/ai-localization-job.js.map +1 -0
- package/dist/server/models/ai-localization-job.mjs +57 -0
- package/dist/server/models/ai-localization-job.mjs.map +1 -0
- package/dist/server/register.js +3 -1
- package/dist/server/register.js.map +1 -1
- package/dist/server/register.mjs +3 -1
- package/dist/server/register.mjs.map +1 -1
- package/dist/server/routes/admin.js +40 -0
- package/dist/server/routes/admin.js.map +1 -1
- package/dist/server/routes/admin.mjs +40 -0
- package/dist/server/routes/admin.mjs.map +1 -1
- package/dist/server/services/ai-localization-jobs.js +64 -0
- package/dist/server/services/ai-localization-jobs.js.map +1 -0
- package/dist/server/services/ai-localization-jobs.mjs +62 -0
- package/dist/server/services/ai-localization-jobs.mjs.map +1 -0
- package/dist/server/services/ai-localizations.js +268 -0
- package/dist/server/services/ai-localizations.js.map +1 -0
- package/dist/server/services/ai-localizations.mjs +266 -0
- package/dist/server/services/ai-localizations.mjs.map +1 -0
- package/dist/server/services/content-types.js.map +1 -1
- package/dist/server/services/content-types.mjs.map +1 -1
- package/dist/server/services/index.js +7 -1
- package/dist/server/services/index.js.map +1 -1
- package/dist/server/services/index.mjs +7 -1
- package/dist/server/services/index.mjs.map +1 -1
- 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/bootstrap.d.ts.map +1 -1
- package/dist/server/src/controllers/ai-localization-jobs.d.ts +17 -0
- package/dist/server/src/controllers/ai-localization-jobs.d.ts.map +1 -0
- package/dist/server/src/controllers/index.d.ts +10 -0
- package/dist/server/src/controllers/index.d.ts.map +1 -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 +44 -1
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/models/ai-localization-job.d.ts +5 -0
- package/dist/server/src/models/ai-localization-job.d.ts.map +1 -0
- package/dist/server/src/models/index.d.ts +5 -0
- package/dist/server/src/models/index.d.ts.map +1 -0
- package/dist/server/src/register.d.ts +1 -1
- package/dist/server/src/register.d.ts.map +1 -1
- package/dist/server/src/routes/admin.d.ts.map +1 -1
- package/dist/server/src/services/ai-localization-jobs.d.ts +26 -0
- package/dist/server/src/services/ai-localization-jobs.d.ts.map +1 -0
- package/dist/server/src/services/ai-localizations.d.ts +18 -0
- package/dist/server/src/services/ai-localizations.d.ts.map +1 -0
- package/dist/server/src/services/index.d.ts +33 -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 +7 -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.map +1 -1
- package/dist/server/utils/index.mjs.map +1 -1
- 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/ai-localization-jobs.d.ts +27 -0
- package/dist/shared/contracts/ai-localization-jobs.d.ts.map +1 -0
- package/dist/shared/contracts/settings.d.ts +40 -0
- package/dist/shared/contracts/shared.d.ts.map +1 -0
- package/package.json +11 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","sources":["../../server/src/register.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\n\nimport validateLocaleCreation from './controllers/validate-locale-creation';\nimport graphqlProvider from './graphql';\nimport { getService } from './utils';\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => {\n extendContentTypes(strapi);\n addContentManagerLocaleMiddleware(strapi);\n};\n\n// TODO: v5 if implemented in the CM => delete this middleware\n/**\n * Adds middleware on CM creation routes to use i18n locale passed in a specific param\n * @param {Strapi} strapi\n */\nconst addContentManagerLocaleMiddleware = (strapi: Core.Strapi) => {\n strapi.server.router.use('/content-manager/collection-types/:model', (ctx, next) => {\n if (ctx.method === 'POST' || ctx.method === 'PUT') {\n return validateLocaleCreation(ctx, next);\n }\n\n return next();\n });\n\n strapi.server.router.use('/content-manager/single-types/:model', (ctx, next) => {\n if (ctx.method === 'POST' || ctx.method === 'PUT') {\n return validateLocaleCreation(ctx, next);\n }\n\n return next();\n });\n};\n\n/**\n * Adds locale and localization fields to all content types\n * Even if content type is not localized, it will have these fields\n * @param {Strapi} strapi\n */\nconst extendContentTypes = (strapi: Core.Strapi) => {\n const { isLocalizedContentType } = getService('content-types');\n\n Object.values(strapi.contentTypes).forEach((contentType) => {\n const { attributes } = contentType;\n\n const isLocalized = isLocalizedContentType(contentType);\n\n _.set(attributes, 'locale', {\n writable: true,\n private: !isLocalized,\n configurable: false,\n visible: false,\n type: 'string',\n });\n\n _.set(attributes, 'localizations', {\n type: 'relation',\n relation: 'oneToMany',\n target: contentType.uid,\n writable: false,\n private: !isLocalized,\n configurable: false,\n visible: false,\n unstable_virtual: true,\n joinColumn: {\n name: 'document_id',\n referencedColumn: 'document_id',\n referencedTable: strapi.db.metadata.identifiers.getTableName(contentType.collectionName!),\n // ensure the population will not include the results we already loaded\n on({ results }: { results: any[] }) {\n return {\n id: {\n $notIn: results.map((r) => r.id),\n },\n };\n },\n },\n });\n });\n\n if (strapi.plugin('graphql')) {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n graphqlProvider({ strapi }).register();\n }\n};\n"],"names":["strapi","extendContentTypes","addContentManagerLocaleMiddleware","server","router","use","ctx","next","method","validateLocaleCreation","isLocalizedContentType","getService","Object","values","contentTypes","forEach","contentType","attributes","isLocalized","_","set","writable","private","configurable","visible","type","relation","target","uid","unstable_virtual","joinColumn","name","referencedColumn","referencedTable","db","metadata","identifiers","getTableName","collectionName","on","results","id","$notIn","map","r","plugin","graphqlProvider","register"],"mappings":"
|
|
1
|
+
{"version":3,"file":"register.js","sources":["../../server/src/register.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\n\nimport validateLocaleCreation from './controllers/validate-locale-creation';\nimport graphqlProvider from './graphql';\nimport { getService } from './utils';\nimport { aiLocalizationJob } from './models/ai-localization-job';\n\nexport default async ({ strapi }: { strapi: Core.Strapi }) => {\n strapi.get('models').add(aiLocalizationJob);\n\n extendContentTypes(strapi);\n addContentManagerLocaleMiddleware(strapi);\n};\n\n// TODO: v5 if implemented in the CM => delete this middleware\n/**\n * Adds middleware on CM creation routes to use i18n locale passed in a specific param\n * @param {Strapi} strapi\n */\nconst addContentManagerLocaleMiddleware = (strapi: Core.Strapi) => {\n strapi.server.router.use('/content-manager/collection-types/:model', (ctx, next) => {\n if (ctx.method === 'POST' || ctx.method === 'PUT') {\n return validateLocaleCreation(ctx, next);\n }\n\n return next();\n });\n\n strapi.server.router.use('/content-manager/single-types/:model', (ctx, next) => {\n if (ctx.method === 'POST' || ctx.method === 'PUT') {\n return validateLocaleCreation(ctx, next);\n }\n\n return next();\n });\n};\n\n/**\n * Adds locale and localization fields to all content types\n * Even if content type is not localized, it will have these fields\n * @param {Strapi} strapi\n */\nconst extendContentTypes = (strapi: Core.Strapi) => {\n const { isLocalizedContentType } = getService('content-types');\n\n Object.values(strapi.contentTypes).forEach((contentType) => {\n const { attributes } = contentType;\n\n const isLocalized = isLocalizedContentType(contentType);\n\n _.set(attributes, 'locale', {\n writable: true,\n private: !isLocalized,\n configurable: false,\n visible: false,\n type: 'string',\n });\n\n _.set(attributes, 'localizations', {\n type: 'relation',\n relation: 'oneToMany',\n target: contentType.uid,\n writable: false,\n private: !isLocalized,\n configurable: false,\n visible: false,\n unstable_virtual: true,\n joinColumn: {\n name: 'document_id',\n referencedColumn: 'document_id',\n referencedTable: strapi.db.metadata.identifiers.getTableName(contentType.collectionName!),\n // ensure the population will not include the results we already loaded\n on({ results }: { results: any[] }) {\n return {\n id: {\n $notIn: results.map((r) => r.id),\n },\n };\n },\n },\n });\n });\n\n if (strapi.plugin('graphql')) {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n graphqlProvider({ strapi }).register();\n }\n};\n"],"names":["strapi","get","add","aiLocalizationJob","extendContentTypes","addContentManagerLocaleMiddleware","server","router","use","ctx","next","method","validateLocaleCreation","isLocalizedContentType","getService","Object","values","contentTypes","forEach","contentType","attributes","isLocalized","_","set","writable","private","configurable","visible","type","relation","target","uid","unstable_virtual","joinColumn","name","referencedColumn","referencedTable","db","metadata","identifiers","getTableName","collectionName","on","results","id","$notIn","map","r","plugin","graphqlProvider","register"],"mappings":";;;;;;;;AAQA,eAAe,CAAA,OAAO,EAAEA,MAAM,EAA2B,GAAA;AACvDA,IAAAA,MAAAA,CAAOC,GAAG,CAAC,QAAUC,CAAAA,CAAAA,GAAG,CAACC,mCAAAA,CAAAA;IAEzBC,kBAAmBJ,CAAAA,MAAAA,CAAAA;IACnBK,iCAAkCL,CAAAA,MAAAA,CAAAA;AACpC,CAAA;AAEA;AACA;;;IAIA,MAAMK,oCAAoC,CAACL,MAAAA,GAAAA;IACzCA,MAAOM,CAAAA,MAAM,CAACC,MAAM,CAACC,GAAG,CAAC,0CAAA,EAA4C,CAACC,GAAKC,EAAAA,IAAAA,GAAAA;AACzE,QAAA,IAAID,IAAIE,MAAM,KAAK,UAAUF,GAAIE,CAAAA,MAAM,KAAK,KAAO,EAAA;AACjD,YAAA,OAAOC,uBAAuBH,GAAKC,EAAAA,IAAAA,CAAAA;AACrC;QAEA,OAAOA,IAAAA,EAAAA;AACT,KAAA,CAAA;IAEAV,MAAOM,CAAAA,MAAM,CAACC,MAAM,CAACC,GAAG,CAAC,sCAAA,EAAwC,CAACC,GAAKC,EAAAA,IAAAA,GAAAA;AACrE,QAAA,IAAID,IAAIE,MAAM,KAAK,UAAUF,GAAIE,CAAAA,MAAM,KAAK,KAAO,EAAA;AACjD,YAAA,OAAOC,uBAAuBH,GAAKC,EAAAA,IAAAA,CAAAA;AACrC;QAEA,OAAOA,IAAAA,EAAAA;AACT,KAAA,CAAA;AACF,CAAA;AAEA;;;;IAKA,MAAMN,qBAAqB,CAACJ,MAAAA,GAAAA;AAC1B,IAAA,MAAM,EAAEa,sBAAsB,EAAE,GAAGC,gBAAW,CAAA,eAAA,CAAA;AAE9CC,IAAAA,MAAAA,CAAOC,MAAM,CAAChB,MAAAA,CAAOiB,YAAY,CAAEC,CAAAA,OAAO,CAAC,CAACC,WAAAA,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2,8 +2,10 @@ import _ from 'lodash';
|
|
|
2
2
|
import validateLocaleCreation from './controllers/validate-locale-creation.mjs';
|
|
3
3
|
import graphqlProvider from './graphql.mjs';
|
|
4
4
|
import { getService } from './utils/index.mjs';
|
|
5
|
+
import { aiLocalizationJob } from './models/ai-localization-job.mjs';
|
|
5
6
|
|
|
6
|
-
var register = (({ strapi })=>{
|
|
7
|
+
var register = (async ({ strapi })=>{
|
|
8
|
+
strapi.get('models').add(aiLocalizationJob);
|
|
7
9
|
extendContentTypes(strapi);
|
|
8
10
|
addContentManagerLocaleMiddleware(strapi);
|
|
9
11
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.mjs","sources":["../../server/src/register.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\n\nimport validateLocaleCreation from './controllers/validate-locale-creation';\nimport graphqlProvider from './graphql';\nimport { getService } from './utils';\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => {\n extendContentTypes(strapi);\n addContentManagerLocaleMiddleware(strapi);\n};\n\n// TODO: v5 if implemented in the CM => delete this middleware\n/**\n * Adds middleware on CM creation routes to use i18n locale passed in a specific param\n * @param {Strapi} strapi\n */\nconst addContentManagerLocaleMiddleware = (strapi: Core.Strapi) => {\n strapi.server.router.use('/content-manager/collection-types/:model', (ctx, next) => {\n if (ctx.method === 'POST' || ctx.method === 'PUT') {\n return validateLocaleCreation(ctx, next);\n }\n\n return next();\n });\n\n strapi.server.router.use('/content-manager/single-types/:model', (ctx, next) => {\n if (ctx.method === 'POST' || ctx.method === 'PUT') {\n return validateLocaleCreation(ctx, next);\n }\n\n return next();\n });\n};\n\n/**\n * Adds locale and localization fields to all content types\n * Even if content type is not localized, it will have these fields\n * @param {Strapi} strapi\n */\nconst extendContentTypes = (strapi: Core.Strapi) => {\n const { isLocalizedContentType } = getService('content-types');\n\n Object.values(strapi.contentTypes).forEach((contentType) => {\n const { attributes } = contentType;\n\n const isLocalized = isLocalizedContentType(contentType);\n\n _.set(attributes, 'locale', {\n writable: true,\n private: !isLocalized,\n configurable: false,\n visible: false,\n type: 'string',\n });\n\n _.set(attributes, 'localizations', {\n type: 'relation',\n relation: 'oneToMany',\n target: contentType.uid,\n writable: false,\n private: !isLocalized,\n configurable: false,\n visible: false,\n unstable_virtual: true,\n joinColumn: {\n name: 'document_id',\n referencedColumn: 'document_id',\n referencedTable: strapi.db.metadata.identifiers.getTableName(contentType.collectionName!),\n // ensure the population will not include the results we already loaded\n on({ results }: { results: any[] }) {\n return {\n id: {\n $notIn: results.map((r) => r.id),\n },\n };\n },\n },\n });\n });\n\n if (strapi.plugin('graphql')) {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n graphqlProvider({ strapi }).register();\n }\n};\n"],"names":["strapi","extendContentTypes","addContentManagerLocaleMiddleware","server","router","use","ctx","next","method","validateLocaleCreation","isLocalizedContentType","getService","Object","values","contentTypes","forEach","contentType","attributes","isLocalized","_","set","writable","private","configurable","visible","type","relation","target","uid","unstable_virtual","joinColumn","name","referencedColumn","referencedTable","db","metadata","identifiers","getTableName","collectionName","on","results","id","$notIn","map","r","plugin","graphqlProvider","register"],"mappings":"
|
|
1
|
+
{"version":3,"file":"register.mjs","sources":["../../server/src/register.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\n\nimport validateLocaleCreation from './controllers/validate-locale-creation';\nimport graphqlProvider from './graphql';\nimport { getService } from './utils';\nimport { aiLocalizationJob } from './models/ai-localization-job';\n\nexport default async ({ strapi }: { strapi: Core.Strapi }) => {\n strapi.get('models').add(aiLocalizationJob);\n\n extendContentTypes(strapi);\n addContentManagerLocaleMiddleware(strapi);\n};\n\n// TODO: v5 if implemented in the CM => delete this middleware\n/**\n * Adds middleware on CM creation routes to use i18n locale passed in a specific param\n * @param {Strapi} strapi\n */\nconst addContentManagerLocaleMiddleware = (strapi: Core.Strapi) => {\n strapi.server.router.use('/content-manager/collection-types/:model', (ctx, next) => {\n if (ctx.method === 'POST' || ctx.method === 'PUT') {\n return validateLocaleCreation(ctx, next);\n }\n\n return next();\n });\n\n strapi.server.router.use('/content-manager/single-types/:model', (ctx, next) => {\n if (ctx.method === 'POST' || ctx.method === 'PUT') {\n return validateLocaleCreation(ctx, next);\n }\n\n return next();\n });\n};\n\n/**\n * Adds locale and localization fields to all content types\n * Even if content type is not localized, it will have these fields\n * @param {Strapi} strapi\n */\nconst extendContentTypes = (strapi: Core.Strapi) => {\n const { isLocalizedContentType } = getService('content-types');\n\n Object.values(strapi.contentTypes).forEach((contentType) => {\n const { attributes } = contentType;\n\n const isLocalized = isLocalizedContentType(contentType);\n\n _.set(attributes, 'locale', {\n writable: true,\n private: !isLocalized,\n configurable: false,\n visible: false,\n type: 'string',\n });\n\n _.set(attributes, 'localizations', {\n type: 'relation',\n relation: 'oneToMany',\n target: contentType.uid,\n writable: false,\n private: !isLocalized,\n configurable: false,\n visible: false,\n unstable_virtual: true,\n joinColumn: {\n name: 'document_id',\n referencedColumn: 'document_id',\n referencedTable: strapi.db.metadata.identifiers.getTableName(contentType.collectionName!),\n // ensure the population will not include the results we already loaded\n on({ results }: { results: any[] }) {\n return {\n id: {\n $notIn: results.map((r) => r.id),\n },\n };\n },\n },\n });\n });\n\n if (strapi.plugin('graphql')) {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n graphqlProvider({ strapi }).register();\n }\n};\n"],"names":["strapi","get","add","aiLocalizationJob","extendContentTypes","addContentManagerLocaleMiddleware","server","router","use","ctx","next","method","validateLocaleCreation","isLocalizedContentType","getService","Object","values","contentTypes","forEach","contentType","attributes","isLocalized","_","set","writable","private","configurable","visible","type","relation","target","uid","unstable_virtual","joinColumn","name","referencedColumn","referencedTable","db","metadata","identifiers","getTableName","collectionName","on","results","id","$notIn","map","r","plugin","graphqlProvider","register"],"mappings":";;;;;;AAQA,eAAe,CAAA,OAAO,EAAEA,MAAM,EAA2B,GAAA;AACvDA,IAAAA,MAAAA,CAAOC,GAAG,CAAC,QAAUC,CAA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A,OAAAA,EAAS,CAACJ,WAAAA;YACVK,YAAc,EAAA,KAAA;YACdC,OAAS,EAAA,KAAA;YACTC,IAAM,EAAA;AACR,SAAA,CAAA;QAEAN,CAAEC,CAAAA,GAAG,CAACH,UAAAA,EAAY,eAAiB,EAAA;YACjCQ,IAAM,EAAA,UAAA;YACNC,QAAU,EAAA,WAAA;AACVC,YAAAA,MAAAA,EAAQX,YAAYY,GAAG;YACvBP,QAAU,EAAA,KAAA;AACVC,YAAAA,OAAAA,EAAS,CAACJ,WAAAA;YACVK,YAAc,EAAA,KAAA;YACdC,OAAS,EAAA,KAAA;YACTK,gBAAkB,EAAA,IAAA;YAClBC,UAAY,EAAA;gBACVC,IAAM,EAAA,aAAA;gBACNC,gBAAkB,EAAA,aAAA;gBAClBC,eAAiBpC,EAAAA,MAAAA,CAAOqC,EAAE,CAACC,QAAQ,CAACC,WAAW,CAACC,YAAY,CAACrB,WAAAA,CAAYsB,cAAc,CAAA;;gBAEvFC,EAAG,CAAA,CAAA,EAAEC,OAAO,EAAsB,EAAA;oBAChC,OAAO;wBACLC,EAAI,EAAA;AACFC,4BAAAA,MAAAA,EAAQF,QAAQG,GAAG,CAAC,CAACC,CAAAA,GAAMA,EAAEH,EAAE;AACjC;AACF,qBAAA;AACF;AACF;AACF,SAAA,CAAA;AACF,KAAA,CAAA;IAEA,IAAI5C,MAAAA,CAAOgD,MAAM,CAAC,SAAY,CAAA,EAAA;;QAE5BC,eAAgB,CAAA;AAAEjD,YAAAA;AAAO,SAAA,CAAA,CAAGkD,QAAQ,EAAA;AACtC;AACF,CAAA;;;;"}
|
|
@@ -94,6 +94,46 @@ var admin = {
|
|
|
94
94
|
'admin::isAuthenticatedAdmin'
|
|
95
95
|
]
|
|
96
96
|
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
method: 'GET',
|
|
100
|
+
path: '/settings',
|
|
101
|
+
handler: 'settings.getSettings',
|
|
102
|
+
config: {
|
|
103
|
+
policies: [
|
|
104
|
+
'admin::isAuthenticatedAdmin'
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
method: 'PUT',
|
|
110
|
+
path: '/settings',
|
|
111
|
+
handler: 'settings.updateSettings',
|
|
112
|
+
config: {
|
|
113
|
+
policies: [
|
|
114
|
+
'admin::isAuthenticatedAdmin'
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
method: 'GET',
|
|
120
|
+
path: '/ai-localization-jobs/collection-types/:contentType/:documentId',
|
|
121
|
+
handler: 'ai-localization-jobs.getJobForCollectionType',
|
|
122
|
+
config: {
|
|
123
|
+
policies: [
|
|
124
|
+
'admin::isAuthenticatedAdmin'
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
method: 'GET',
|
|
130
|
+
path: '/ai-localization-jobs/single-types/:contentType',
|
|
131
|
+
handler: 'ai-localization-jobs.getJobForSingleType',
|
|
132
|
+
config: {
|
|
133
|
+
policies: [
|
|
134
|
+
'admin::isAuthenticatedAdmin'
|
|
135
|
+
]
|
|
136
|
+
}
|
|
97
137
|
}
|
|
98
138
|
]
|
|
99
139
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.js","sources":["../../../server/src/routes/admin.ts"],"sourcesContent":["export default {\n type: 'admin',\n routes: [\n {\n method: 'GET',\n path: '/iso-locales',\n handler: 'iso-locales.listIsoLocales',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.read'] },\n },\n ],\n },\n },\n {\n method: 'GET',\n path: '/locales',\n handler: 'locales.listLocales',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'POST',\n path: '/locales',\n handler: 'locales.createLocale',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.create'] },\n },\n ],\n },\n },\n {\n method: 'PUT',\n path: '/locales/:id',\n handler: 'locales.updateLocale',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.update'] },\n },\n ],\n },\n },\n {\n method: 'DELETE',\n path: '/locales/:id',\n handler: 'locales.deleteLocale',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.delete'] },\n },\n ],\n },\n },\n {\n method: 'POST',\n path: '/content-manager/actions/get-non-localized-fields',\n handler: 'content-types.getNonLocalizedAttributes',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n ],\n};\n"],"names":["type","routes","method","path","handler","config","policies","name","actions"],"mappings":";;AAAA,YAAe;IACbA,IAAM,EAAA,OAAA;IACNC,MAAQ,EAAA;AACN,QAAA;YACEC,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,cAAA;YACNC,OAAS,EAAA,4BAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AACR,oBAAA,6BAAA;AACA,oBAAA;wBACEC,IAAM,EAAA,wCAAA;wBACNF,MAAQ,EAAA;4BAAEG,OAAS,EAAA;AAAC,gCAAA;AAA2B;AAAC;AAClD;AACD;AACH;AACF,SAAA;AACA,QAAA;YACEN,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,UAAA;YACNC,OAAS,EAAA,qBAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AAAC,oBAAA;AAA8B;AAC3C;AACF,SAAA;AACA,QAAA;YACEJ,MAAQ,EAAA,MAAA;YACRC,IAAM,EAAA,UAAA;YACNC,OAAS,EAAA,sBAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AACR,oBAAA,6BAAA;AACA,oBAAA;wBACEC,IAAM,EAAA,wCAAA;wBACNF,MAAQ,EAAA;4BAAEG,OAAS,EAAA;AAAC,gCAAA;AAA6B;AAAC;AACpD;AACD;AACH;AACF,SAAA;AACA,QAAA;YACEN,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,cAAA;YACNC,OAAS,EAAA,sBAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AACR,oBAAA,6BAAA;AACA,oBAAA;wBACEC,IAAM,EAAA,wCAAA;wBACNF,MAAQ,EAAA;4BAAEG,OAAS,EAAA;AAAC,gCAAA;AAA6B;AAAC;AACpD;AACD;AACH;AACF,SAAA;AACA,QAAA;YACEN,MAAQ,EAAA,QAAA;YACRC,IAAM,EAAA,cAAA;YACNC,OAAS,EAAA,sBAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AACR,oBAAA,6BAAA;AACA,oBAAA;wBACEC,IAAM,EAAA,wCAAA;wBACNF,MAAQ,EAAA;4BAAEG,OAAS,EAAA;AAAC,gCAAA;AAA6B;AAAC;AACpD;AACD;AACH;AACF,SAAA;AACA,QAAA;YACEN,MAAQ,EAAA,MAAA;YACRC,IAAM,EAAA,mDAAA;YACNC,OAAS,EAAA,yCAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AAAC,oBAAA;AAA8B;AAC3C;AACF;AACD;AACH,CAAE;;;;"}
|
|
1
|
+
{"version":3,"file":"admin.js","sources":["../../../server/src/routes/admin.ts"],"sourcesContent":["export default {\n type: 'admin',\n routes: [\n {\n method: 'GET',\n path: '/iso-locales',\n handler: 'iso-locales.listIsoLocales',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.read'] },\n },\n ],\n },\n },\n {\n method: 'GET',\n path: '/locales',\n handler: 'locales.listLocales',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'POST',\n path: '/locales',\n handler: 'locales.createLocale',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.create'] },\n },\n ],\n },\n },\n {\n method: 'PUT',\n path: '/locales/:id',\n handler: 'locales.updateLocale',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.update'] },\n },\n ],\n },\n },\n {\n method: 'DELETE',\n path: '/locales/:id',\n handler: 'locales.deleteLocale',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.delete'] },\n },\n ],\n },\n },\n {\n method: 'POST',\n path: '/content-manager/actions/get-non-localized-fields',\n handler: 'content-types.getNonLocalizedAttributes',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'GET',\n path: '/settings',\n handler: 'settings.getSettings',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'PUT',\n path: '/settings',\n handler: 'settings.updateSettings',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'GET',\n path: '/ai-localization-jobs/collection-types/:contentType/:documentId',\n handler: 'ai-localization-jobs.getJobForCollectionType',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'GET',\n path: '/ai-localization-jobs/single-types/:contentType',\n handler: 'ai-localization-jobs.getJobForSingleType',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n ],\n};\n"],"names":["type","routes","method","path","handler","config","policies","name","actions"],"mappings":";;AAAA,YAAe;IACbA,IAAM,EAAA,OAAA;IACNC,MAAQ,EAAA;AACN,QAAA;YACEC,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,cAAA;YACNC,OAAS,EAAA,4BAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AACR,oBAAA,6BAAA;AACA,oBAAA;wBACEC,IAAM,EAAA,wC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B;AAC3C;AACF,SAAA;AACA,QAAA;YACEJ,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,WAAA;YACNC,OAAS,EAAA,sBAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AAAC,oBAAA;AAA8B;AAC3C;AACF,SAAA;AACA,QAAA;YACEJ,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,WAAA;YACNC,OAAS,EAAA,yBAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AAAC,oBAAA;AAA8B;AAC3C;AACF,SAAA;AACA,QAAA;YACEJ,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,iEAAA;YACNC,OAAS,EAAA,8CAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AAAC,oBAAA;AAA8B;AAC3C;AACF,SAAA;AACA,QAAA;YACEJ,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,iDAAA;YACNC,OAAS,EAAA,0CAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AAAC,oBAAA;AAA8B;AAC3C;AACF;AACD;AACH,CAAE;;;;"}
|
|
@@ -92,6 +92,46 @@ var admin = {
|
|
|
92
92
|
'admin::isAuthenticatedAdmin'
|
|
93
93
|
]
|
|
94
94
|
}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
method: 'GET',
|
|
98
|
+
path: '/settings',
|
|
99
|
+
handler: 'settings.getSettings',
|
|
100
|
+
config: {
|
|
101
|
+
policies: [
|
|
102
|
+
'admin::isAuthenticatedAdmin'
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
method: 'PUT',
|
|
108
|
+
path: '/settings',
|
|
109
|
+
handler: 'settings.updateSettings',
|
|
110
|
+
config: {
|
|
111
|
+
policies: [
|
|
112
|
+
'admin::isAuthenticatedAdmin'
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
method: 'GET',
|
|
118
|
+
path: '/ai-localization-jobs/collection-types/:contentType/:documentId',
|
|
119
|
+
handler: 'ai-localization-jobs.getJobForCollectionType',
|
|
120
|
+
config: {
|
|
121
|
+
policies: [
|
|
122
|
+
'admin::isAuthenticatedAdmin'
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
method: 'GET',
|
|
128
|
+
path: '/ai-localization-jobs/single-types/:contentType',
|
|
129
|
+
handler: 'ai-localization-jobs.getJobForSingleType',
|
|
130
|
+
config: {
|
|
131
|
+
policies: [
|
|
132
|
+
'admin::isAuthenticatedAdmin'
|
|
133
|
+
]
|
|
134
|
+
}
|
|
95
135
|
}
|
|
96
136
|
]
|
|
97
137
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.mjs","sources":["../../../server/src/routes/admin.ts"],"sourcesContent":["export default {\n type: 'admin',\n routes: [\n {\n method: 'GET',\n path: '/iso-locales',\n handler: 'iso-locales.listIsoLocales',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.read'] },\n },\n ],\n },\n },\n {\n method: 'GET',\n path: '/locales',\n handler: 'locales.listLocales',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'POST',\n path: '/locales',\n handler: 'locales.createLocale',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.create'] },\n },\n ],\n },\n },\n {\n method: 'PUT',\n path: '/locales/:id',\n handler: 'locales.updateLocale',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.update'] },\n },\n ],\n },\n },\n {\n method: 'DELETE',\n path: '/locales/:id',\n handler: 'locales.deleteLocale',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.delete'] },\n },\n ],\n },\n },\n {\n method: 'POST',\n path: '/content-manager/actions/get-non-localized-fields',\n handler: 'content-types.getNonLocalizedAttributes',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n ],\n};\n"],"names":["type","routes","method","path","handler","config","policies","name","actions"],"mappings":"AAAA,YAAe;IACbA,IAAM,EAAA,OAAA;IACNC,MAAQ,EAAA;AACN,QAAA;YACEC,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,cAAA;YACNC,OAAS,EAAA,4BAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AACR,oBAAA,6BAAA;AACA,oBAAA;wBACEC,IAAM,EAAA,wCAAA;wBACNF,MAAQ,EAAA;4BAAEG,OAAS,EAAA;AAAC,gCAAA;AAA2B;AAAC;AAClD;AACD;AACH;AACF,SAAA;AACA,QAAA;YACEN,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,UAAA;YACNC,OAAS,EAAA,qBAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AAAC,oBAAA;AAA8B;AAC3C;AACF,SAAA;AACA,QAAA;YACEJ,MAAQ,EAAA,MAAA;YACRC,IAAM,EAAA,UAAA;YACNC,OAAS,EAAA,sBAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AACR,oBAAA,6BAAA;AACA,oBAAA;wBACEC,IAAM,EAAA,wCAAA;wBACNF,MAAQ,EAAA;4BAAEG,OAAS,EAAA;AAAC,gCAAA;AAA6B;AAAC;AACpD;AACD;AACH;AACF,SAAA;AACA,QAAA;YACEN,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,cAAA;YACNC,OAAS,EAAA,sBAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AACR,oBAAA,6BAAA;AACA,oBAAA;wBACEC,IAAM,EAAA,wCAAA;wBACNF,MAAQ,EAAA;4BAAEG,OAAS,EAAA;AAAC,gCAAA;AAA6B;AAAC;AACpD;AACD;AACH;AACF,SAAA;AACA,QAAA;YACEN,MAAQ,EAAA,QAAA;YACRC,IAAM,EAAA,cAAA;YACNC,OAAS,EAAA,sBAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AACR,oBAAA,6BAAA;AACA,oBAAA;wBACEC,IAAM,EAAA,wCAAA;wBACNF,MAAQ,EAAA;4BAAEG,OAAS,EAAA;AAAC,gCAAA;AAA6B;AAAC;AACpD;AACD;AACH;AACF,SAAA;AACA,QAAA;YACEN,MAAQ,EAAA,MAAA;YACRC,IAAM,EAAA,mDAAA;YACNC,OAAS,EAAA,yCAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AAAC,oBAAA;AAA8B;AAC3C;AACF;AACD;AACH,CAAE;;;;"}
|
|
1
|
+
{"version":3,"file":"admin.mjs","sources":["../../../server/src/routes/admin.ts"],"sourcesContent":["export default {\n type: 'admin',\n routes: [\n {\n method: 'GET',\n path: '/iso-locales',\n handler: 'iso-locales.listIsoLocales',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.read'] },\n },\n ],\n },\n },\n {\n method: 'GET',\n path: '/locales',\n handler: 'locales.listLocales',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'POST',\n path: '/locales',\n handler: 'locales.createLocale',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.create'] },\n },\n ],\n },\n },\n {\n method: 'PUT',\n path: '/locales/:id',\n handler: 'locales.updateLocale',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.update'] },\n },\n ],\n },\n },\n {\n method: 'DELETE',\n path: '/locales/:id',\n handler: 'locales.deleteLocale',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n {\n name: 'plugin::content-manager.hasPermissions',\n config: { actions: ['plugin::i18n.locale.delete'] },\n },\n ],\n },\n },\n {\n method: 'POST',\n path: '/content-manager/actions/get-non-localized-fields',\n handler: 'content-types.getNonLocalizedAttributes',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'GET',\n path: '/settings',\n handler: 'settings.getSettings',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'PUT',\n path: '/settings',\n handler: 'settings.updateSettings',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'GET',\n path: '/ai-localization-jobs/collection-types/:contentType/:documentId',\n handler: 'ai-localization-jobs.getJobForCollectionType',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'GET',\n path: '/ai-localization-jobs/single-types/:contentType',\n handler: 'ai-localization-jobs.getJobForSingleType',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n ],\n};\n"],"names":["type","routes","method","path","handler","config","policies","name","actions"],"mappings":"AAAA,YAAe;IACbA,IAAM,EAAA,OAAA;IACNC,MAAQ,EAAA;AACN,QAAA;YACEC,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,cAAA;YACNC,OAAS,EAAA,4BAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AACR,oBAAA,6BAAA;AACA,oBAAA;wBACEC,IAAM,EAAA,wCAAA;wBACNF,MAAQ,EAAA;4BAAEG,OAAS,EAAA;AAAC,gCAAA;AAA2B;AAAC;AAClD;AACD;AACH;AACF,SAAA;AACA,QAAA;YACEN,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,UAAA;YACNC,OAAS,EAAA,qBAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AAAC,oBAAA;AAA8B;AAC3C;AACF,SAAA;AACA,QAAA;YACEJ,MAAQ,EAAA,M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NC,QAAU,EAAA;AAAC,oBAAA;AAA8B;AAC3C;AACF,SAAA;AACA,QAAA;YACEJ,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,iEAAA;YACNC,OAAS,EAAA,8CAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AAAC,oBAAA;AAA8B;AAC3C;AACF,SAAA;AACA,QAAA;YACEJ,MAAQ,EAAA,KAAA;YACRC,IAAM,EAAA,iDAAA;YACNC,OAAS,EAAA,0CAAA;YACTC,MAAQ,EAAA;gBACNC,QAAU,EAAA;AAAC,oBAAA;AAA8B;AAC3C;AACF;AACD;AACH,CAAE;;;;"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var aiLocalizationJob = require('../models/ai-localization-job.js');
|
|
4
|
+
|
|
5
|
+
const createAILocalizationJobsService = ({ strapi })=>({
|
|
6
|
+
/**
|
|
7
|
+
* Create a new AI localizations job or update an existing one for a document
|
|
8
|
+
* Ensures only one job exists per document
|
|
9
|
+
*/ async upsertJobForDocument ({ documentId, contentType, sourceLocale, targetLocales, status = 'processing' }) {
|
|
10
|
+
// Check if job already exists for this document
|
|
11
|
+
const existingJob = await this.getJobByDocument(contentType, documentId);
|
|
12
|
+
if (existingJob) {
|
|
13
|
+
strapi.log.info(`[AI Localizations Job] Updated existing job for document ${documentId} with status: ${status}`);
|
|
14
|
+
// Update existing job with new data and status
|
|
15
|
+
return strapi.db.query(aiLocalizationJob.AI_LOCALIZATION_JOB_UID).update({
|
|
16
|
+
where: {
|
|
17
|
+
id: existingJob.id
|
|
18
|
+
},
|
|
19
|
+
data: {
|
|
20
|
+
contentType,
|
|
21
|
+
sourceLocale,
|
|
22
|
+
targetLocales,
|
|
23
|
+
status,
|
|
24
|
+
updatedAt: new Date()
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
strapi.log.info(`[AI Localizations Job] Created new job for document ${documentId} with status: ${status}`);
|
|
29
|
+
// Create new AI localizations job
|
|
30
|
+
return strapi.db.query(aiLocalizationJob.AI_LOCALIZATION_JOB_UID).create({
|
|
31
|
+
data: {
|
|
32
|
+
contentType,
|
|
33
|
+
relatedDocumentId: documentId,
|
|
34
|
+
sourceLocale,
|
|
35
|
+
targetLocales,
|
|
36
|
+
status,
|
|
37
|
+
createdAt: new Date(),
|
|
38
|
+
updatedAt: new Date()
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* Get job by document ID
|
|
44
|
+
*/ async getJobByDocument (contentType, documentId) {
|
|
45
|
+
return strapi.db.query(aiLocalizationJob.AI_LOCALIZATION_JOB_UID).findOne({
|
|
46
|
+
where: {
|
|
47
|
+
relatedDocumentId: documentId,
|
|
48
|
+
contentType
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
/**
|
|
53
|
+
* Get job by content type
|
|
54
|
+
*/ async getJobByContentType (contentType) {
|
|
55
|
+
return strapi.db.query(aiLocalizationJob.AI_LOCALIZATION_JOB_UID).findOne({
|
|
56
|
+
where: {
|
|
57
|
+
contentType
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
exports.createAILocalizationJobsService = createAILocalizationJobsService;
|
|
64
|
+
//# sourceMappingURL=ai-localization-jobs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-localization-jobs.js","sources":["../../../server/src/services/ai-localization-jobs.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport { AI_LOCALIZATION_JOB_UID } from '../models/ai-localization-job';\nimport type { AILocalizationJobs } from '../../../shared/contracts/ai-localization-jobs';\n\nexport const createAILocalizationJobsService = ({ strapi }: { strapi: Core.Strapi }) => ({\n /**\n * Create a new AI localizations job or update an existing one for a document\n * Ensures only one job exists per document\n */\n async upsertJobForDocument({\n documentId,\n contentType,\n sourceLocale,\n targetLocales,\n status = 'processing',\n }: {\n documentId: string;\n contentType: string;\n sourceLocale: string;\n targetLocales: string[];\n status?: AILocalizationJobs['status'];\n }) {\n // Check if job already exists for this document\n const existingJob = await this.getJobByDocument(contentType, documentId);\n\n if (existingJob) {\n strapi.log.info(\n `[AI Localizations Job] Updated existing job for document ${documentId} with status: ${status}`\n );\n // Update existing job with new data and status\n return strapi.db.query(AI_LOCALIZATION_JOB_UID).update({\n where: { id: existingJob.id },\n data: {\n contentType,\n sourceLocale,\n targetLocales,\n status,\n updatedAt: new Date(),\n },\n });\n }\n\n strapi.log.info(\n `[AI Localizations Job] Created new job for document ${documentId} with status: ${status}`\n );\n // Create new AI localizations job\n return strapi.db.query(AI_LOCALIZATION_JOB_UID).create({\n data: {\n contentType,\n relatedDocumentId: documentId,\n sourceLocale,\n targetLocales,\n status,\n createdAt: new Date(),\n updatedAt: new Date(),\n },\n });\n },\n\n /**\n * Get job by document ID\n */\n async getJobByDocument(contentType: string, documentId: string) {\n return strapi.db.query(AI_LOCALIZATION_JOB_UID).findOne({\n where: {\n relatedDocumentId: documentId,\n contentType,\n },\n });\n },\n\n /**\n * Get job by content type\n */\n async getJobByContentType(contentType: string) {\n return strapi.db.query(AI_LOCALIZATION_JOB_UID).findOne({\n where: {\n contentType,\n },\n });\n },\n});\n"],"names":["createAILocalizationJobsService","strapi","upsertJobForDocument","documentId","contentType","sourceLocale","targetLocales","status","existingJob","getJobByDocument","log","info","db","query","AI_LOCALIZATION_JOB_UID","update","where","id","data","updatedAt","Date","create","relatedDocumentId","createdAt","findOne","getJobByContentType"],"mappings":";;;;MAIaA,+BAAkC,GAAA,CAAC,EAAEC,MAAM,EAA2B,IAAM;AACvF;;;AAGC,MACD,MAAMC,oBAAAA,CAAAA,CAAqB,EACzBC,UAAU,EACVC,WAAW,EACXC,YAAY,EACZC,aAAa,EACbC,MAAAA,GAAS,YAAY,EAOtB,EAAA;;AAEC,YAAA,MAAMC,cAAc,MAAM,IAAI,CAACC,gBAA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;AACF;AACF,aAAA,CAAA;AACF,SAAA;AAEA;;MAGA,MAAMqB,qBAAoBrB,WAAmB,EAAA;AAC3C,YAAA,OAAOH,OAAOW,EAAE,CAACC,KAAK,CAACC,yCAAAA,CAAAA,CAAyBU,OAAO,CAAC;gBACtDR,KAAO,EAAA;AACLZ,oBAAAA;AACF;AACF,aAAA,CAAA;AACF;AACF,KAAA;;;;"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { AI_LOCALIZATION_JOB_UID } from '../models/ai-localization-job.mjs';
|
|
2
|
+
|
|
3
|
+
const createAILocalizationJobsService = ({ strapi })=>({
|
|
4
|
+
/**
|
|
5
|
+
* Create a new AI localizations job or update an existing one for a document
|
|
6
|
+
* Ensures only one job exists per document
|
|
7
|
+
*/ async upsertJobForDocument ({ documentId, contentType, sourceLocale, targetLocales, status = 'processing' }) {
|
|
8
|
+
// Check if job already exists for this document
|
|
9
|
+
const existingJob = await this.getJobByDocument(contentType, documentId);
|
|
10
|
+
if (existingJob) {
|
|
11
|
+
strapi.log.info(`[AI Localizations Job] Updated existing job for document ${documentId} with status: ${status}`);
|
|
12
|
+
// Update existing job with new data and status
|
|
13
|
+
return strapi.db.query(AI_LOCALIZATION_JOB_UID).update({
|
|
14
|
+
where: {
|
|
15
|
+
id: existingJob.id
|
|
16
|
+
},
|
|
17
|
+
data: {
|
|
18
|
+
contentType,
|
|
19
|
+
sourceLocale,
|
|
20
|
+
targetLocales,
|
|
21
|
+
status,
|
|
22
|
+
updatedAt: new Date()
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
strapi.log.info(`[AI Localizations Job] Created new job for document ${documentId} with status: ${status}`);
|
|
27
|
+
// Create new AI localizations job
|
|
28
|
+
return strapi.db.query(AI_LOCALIZATION_JOB_UID).create({
|
|
29
|
+
data: {
|
|
30
|
+
contentType,
|
|
31
|
+
relatedDocumentId: documentId,
|
|
32
|
+
sourceLocale,
|
|
33
|
+
targetLocales,
|
|
34
|
+
status,
|
|
35
|
+
createdAt: new Date(),
|
|
36
|
+
updatedAt: new Date()
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* Get job by document ID
|
|
42
|
+
*/ async getJobByDocument (contentType, documentId) {
|
|
43
|
+
return strapi.db.query(AI_LOCALIZATION_JOB_UID).findOne({
|
|
44
|
+
where: {
|
|
45
|
+
relatedDocumentId: documentId,
|
|
46
|
+
contentType
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* Get job by content type
|
|
52
|
+
*/ async getJobByContentType (contentType) {
|
|
53
|
+
return strapi.db.query(AI_LOCALIZATION_JOB_UID).findOne({
|
|
54
|
+
where: {
|
|
55
|
+
contentType
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export { createAILocalizationJobsService };
|
|
62
|
+
//# sourceMappingURL=ai-localization-jobs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-localization-jobs.mjs","sources":["../../../server/src/services/ai-localization-jobs.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport { AI_LOCALIZATION_JOB_UID } from '../models/ai-localization-job';\nimport type { AILocalizationJobs } from '../../../shared/contracts/ai-localization-jobs';\n\nexport const createAILocalizationJobsService = ({ strapi }: { strapi: Core.Strapi }) => ({\n /**\n * Create a new AI localizations job or update an existing one for a document\n * Ensures only one job exists per document\n */\n async upsertJobForDocument({\n documentId,\n contentType,\n sourceLocale,\n targetLocales,\n status = 'processing',\n }: {\n documentId: string;\n contentType: string;\n sourceLocale: string;\n targetLocales: string[];\n status?: AILocalizationJobs['status'];\n }) {\n // Check if job already exists for this document\n const existingJob = await this.getJobByDocument(contentType, documentId);\n\n if (existingJob) {\n strapi.log.info(\n `[AI Localizations Job] Updated existing job for document ${documentId} with status: ${status}`\n );\n // Update existing job with new data and status\n return strapi.db.query(AI_LOCALIZATION_JOB_UID).update({\n where: { id: existingJob.id },\n data: {\n contentType,\n sourceLocale,\n targetLocales,\n status,\n updatedAt: new Date(),\n },\n });\n }\n\n strapi.log.info(\n `[AI Localizations Job] Created new job for document ${documentId} with status: ${status}`\n );\n // Create new AI localizations job\n return strapi.db.query(AI_LOCALIZATION_JOB_UID).create({\n data: {\n contentType,\n relatedDocumentId: documentId,\n sourceLocale,\n targetLocales,\n status,\n createdAt: new Date(),\n updatedAt: new Date(),\n },\n });\n },\n\n /**\n * Get job by document ID\n */\n async getJobByDocument(contentType: string, documentId: string) {\n return strapi.db.query(AI_LOCALIZATION_JOB_UID).findOne({\n where: {\n relatedDocumentId: documentId,\n contentType,\n },\n });\n },\n\n /**\n * Get job by content type\n */\n async getJobByContentType(contentType: string) {\n return strapi.db.query(AI_LOCALIZATION_JOB_UID).findOne({\n where: {\n contentType,\n },\n });\n },\n});\n"],"names":["createAILocalizationJobsService","strapi","upsertJobForDocument","documentId","contentType","sourceLocale","targetLocales","status","existingJob","getJobByDocument","log","info","db","query","AI_LOCALIZATION_JOB_UID","update","where","id","data","updatedAt","Date","create","relatedDocumentId","createdAt","findOne","getJobByContentType"],"mappings":";;MAIaA,+BAAkC,GAAA,CAAC,EAAEC,MAAM,EAA2B,IAAM;AACvF;;;AAGC,MACD,MAAMC,oBAAAA,CAAAA,CAAqB,EACzBC,UAAU,EACVC,WAAW,EACXC,YAAY,EACZC,aAAa,EACbC,MAAAA,GAAS,YAAY,EAOtB,EAAA;;AAEC,YAAA,MAAMC,cAAc,MAAM,IAAI,CAACC,gBAAgB,CAACL,WAAaD,EAAAA,UAAAA,CAAAA;AAE7D,YAAA,IAAIK,WAAa,EAAA;gBACfP,MAAOS,CAAAA,GAAG,CAACC,IAAI,CACb,CAAC,yDAAyD,EAAER,UAAAA,CAAW,cAAc,EAAEI,MAAQ,CAAA,CAAA,CAAA;;AAGjG,gBAAA,OAAON,OAAOW,EAAE,CAACC,KA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ACF,KAAA;;;;"}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('@strapi/utils');
|
|
4
|
+
var index = require('../utils/index.js');
|
|
5
|
+
|
|
6
|
+
const isLocalizedAttribute = (attribute)=>{
|
|
7
|
+
return attribute?.pluginOptions?.i18n?.localized === true;
|
|
8
|
+
};
|
|
9
|
+
const createAILocalizationsService = ({ strapi })=>{
|
|
10
|
+
// TODO: add a helper function to get the AI server URL
|
|
11
|
+
const aiServerUrl = process.env.STRAPI_AI_URL || 'https://strapi-ai.apps.strapi.io';
|
|
12
|
+
const aiLocalizationJobsService = index.getService('ai-localization-jobs');
|
|
13
|
+
const UNSUPPORTED_ATTRIBUTE_TYPES = [
|
|
14
|
+
'media',
|
|
15
|
+
'relation',
|
|
16
|
+
'boolean'
|
|
17
|
+
];
|
|
18
|
+
const IGNORED_FIELDS = [
|
|
19
|
+
'id',
|
|
20
|
+
'documentId',
|
|
21
|
+
'createdAt',
|
|
22
|
+
'updatedAt',
|
|
23
|
+
'updatedBy',
|
|
24
|
+
'localizations'
|
|
25
|
+
];
|
|
26
|
+
return {
|
|
27
|
+
// Async to avoid changing the signature later (there will be a db check in the future)
|
|
28
|
+
async isEnabled () {
|
|
29
|
+
// Check if user disabled AI features globally
|
|
30
|
+
const isAIEnabled = strapi.config.get('admin.ai.enabled', true);
|
|
31
|
+
if (!isAIEnabled) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
// Check if the user's license grants access to AI features
|
|
35
|
+
const hasAccess = strapi.ee.features.isEnabled('cms-ai');
|
|
36
|
+
if (!hasAccess) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const settings = index.getService('settings');
|
|
40
|
+
const aiSettings = await settings.getSettings();
|
|
41
|
+
if (!aiSettings?.aiLocalizations) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
},
|
|
46
|
+
/**
|
|
47
|
+
* Checks if there are localizations that need to be generated for the given document,
|
|
48
|
+
* and if so, calls the AI service and saves the results to the database.
|
|
49
|
+
* Works for both single and collection types, on create and update.
|
|
50
|
+
*/ async generateDocumentLocalizations ({ model, document }) {
|
|
51
|
+
const isFeatureEnabled = await this.isEnabled();
|
|
52
|
+
if (!isFeatureEnabled) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const schema = strapi.getModel(model);
|
|
56
|
+
const localeService = index.getService('locales');
|
|
57
|
+
// No localizations needed for content types with i18n disabled
|
|
58
|
+
const isLocalizedContentType = index.getService('content-types').isLocalizedContentType(schema);
|
|
59
|
+
if (!isLocalizedContentType) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
// Don't trigger localizations if the update is on a derived locale, only do it on the default
|
|
63
|
+
const defaultLocale = await localeService.getDefaultLocale();
|
|
64
|
+
if (document?.locale !== defaultLocale) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const documentId = document.documentId;
|
|
68
|
+
if (!documentId) {
|
|
69
|
+
strapi.log.warn(`AI Localizations: missing documentId for ${schema.uid}`);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const localizedRoots = new Set();
|
|
73
|
+
const translateableContent = await utils.traverseEntity(({ key, attribute, parent, path }, { remove })=>{
|
|
74
|
+
if (IGNORED_FIELDS.includes(key)) {
|
|
75
|
+
remove(key);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const hasLocalizedOption = attribute && isLocalizedAttribute(attribute);
|
|
79
|
+
if (attribute && UNSUPPORTED_ATTRIBUTE_TYPES.includes(attribute.type)) {
|
|
80
|
+
remove(key);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// If this field is localized, keep it (and mark as localized root if component/dz)
|
|
84
|
+
if (hasLocalizedOption) {
|
|
85
|
+
// If it's a component/dynamiczone, add to the set
|
|
86
|
+
if ([
|
|
87
|
+
'component',
|
|
88
|
+
'dynamiczone'
|
|
89
|
+
].includes(attribute.type)) {
|
|
90
|
+
localizedRoots.add(path.raw);
|
|
91
|
+
}
|
|
92
|
+
return; // keep
|
|
93
|
+
}
|
|
94
|
+
if (parent && localizedRoots.has(parent.path.raw)) {
|
|
95
|
+
// If parent exists in the localized roots set, keep it
|
|
96
|
+
// If this is also a component/dz, propagate the localized root flag
|
|
97
|
+
if ([
|
|
98
|
+
'component',
|
|
99
|
+
'dynamiczone'
|
|
100
|
+
].includes(attribute?.type ?? '')) {
|
|
101
|
+
localizedRoots.add(path.raw);
|
|
102
|
+
}
|
|
103
|
+
return; // keep
|
|
104
|
+
}
|
|
105
|
+
// Otherwise, remove the field
|
|
106
|
+
remove(key);
|
|
107
|
+
}, {
|
|
108
|
+
schema,
|
|
109
|
+
getModel: strapi.getModel.bind(strapi)
|
|
110
|
+
}, document);
|
|
111
|
+
if (Object.keys(translateableContent).length === 0) {
|
|
112
|
+
strapi.log.info(`AI Localizations: no translatable content for ${schema.uid} document ${documentId}`);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const localesList = await localeService.find();
|
|
116
|
+
const targetLocales = localesList.filter((l)=>l.code !== document.locale).map((l)=>l.code);
|
|
117
|
+
if (targetLocales.length === 0) {
|
|
118
|
+
strapi.log.info(`AI Localizations: no target locales for ${schema.uid} document ${documentId}`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
await aiLocalizationJobsService.upsertJobForDocument({
|
|
122
|
+
contentType: model,
|
|
123
|
+
documentId,
|
|
124
|
+
sourceLocale: document.locale,
|
|
125
|
+
targetLocales,
|
|
126
|
+
status: 'processing'
|
|
127
|
+
});
|
|
128
|
+
let token;
|
|
129
|
+
try {
|
|
130
|
+
const tokenData = await strapi.get('ai').getAiToken();
|
|
131
|
+
token = tokenData.token;
|
|
132
|
+
} catch (error) {
|
|
133
|
+
await aiLocalizationJobsService.upsertJobForDocument({
|
|
134
|
+
documentId,
|
|
135
|
+
contentType: model,
|
|
136
|
+
sourceLocale: document.locale,
|
|
137
|
+
targetLocales,
|
|
138
|
+
status: 'failed'
|
|
139
|
+
});
|
|
140
|
+
throw new Error('Failed to retrieve AI token', {
|
|
141
|
+
cause: error instanceof Error ? error : undefined
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Provide a schema to the LLM so that we can give it instructions about how to handle each
|
|
146
|
+
* type of attribute. Only keep essential schema data to avoid cluttering the context.
|
|
147
|
+
* Ignore fields that don't need to be localized.
|
|
148
|
+
* TODO: also provide a schema of all the referenced components
|
|
149
|
+
*/ const minimalContentTypeSchema = Object.fromEntries(Object.entries(schema.attributes)// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
150
|
+
.filter(([_, attr])=>{
|
|
151
|
+
const isLocalized = isLocalizedAttribute(attr);
|
|
152
|
+
const isSupportedType = !UNSUPPORTED_ATTRIBUTE_TYPES.includes(attr.type);
|
|
153
|
+
return isLocalized && isSupportedType;
|
|
154
|
+
}).map(([key, attr])=>{
|
|
155
|
+
const minimalAttribute = {
|
|
156
|
+
type: attr.type
|
|
157
|
+
};
|
|
158
|
+
if (attr.type === 'component') {
|
|
159
|
+
minimalAttribute.repeatable = attr.repeatable ?? false;
|
|
160
|
+
}
|
|
161
|
+
return [
|
|
162
|
+
key,
|
|
163
|
+
minimalAttribute
|
|
164
|
+
];
|
|
165
|
+
}));
|
|
166
|
+
strapi.log.http('Contacting AI Server for localizations generation');
|
|
167
|
+
const response = await fetch(`${aiServerUrl}/i18n/generate-localizations`, {
|
|
168
|
+
method: 'POST',
|
|
169
|
+
headers: {
|
|
170
|
+
'Content-Type': 'application/json',
|
|
171
|
+
Authorization: `Bearer ${token}`
|
|
172
|
+
},
|
|
173
|
+
body: JSON.stringify({
|
|
174
|
+
content: translateableContent,
|
|
175
|
+
sourceLocale: document.locale,
|
|
176
|
+
targetLocales,
|
|
177
|
+
contentTypeSchema: minimalContentTypeSchema
|
|
178
|
+
})
|
|
179
|
+
});
|
|
180
|
+
if (!response.ok) {
|
|
181
|
+
strapi.log.error(`AI Localizations request failed: ${response.status} ${response.statusText}`);
|
|
182
|
+
await aiLocalizationJobsService.upsertJobForDocument({
|
|
183
|
+
documentId,
|
|
184
|
+
contentType: model,
|
|
185
|
+
sourceLocale: document.locale,
|
|
186
|
+
targetLocales,
|
|
187
|
+
status: 'failed'
|
|
188
|
+
});
|
|
189
|
+
throw new Error(`AI Localizations request failed: ${response.statusText}`);
|
|
190
|
+
}
|
|
191
|
+
const aiResult = await response.json();
|
|
192
|
+
// Get all media field names dynamically from the schema
|
|
193
|
+
const mediaFields = Object.entries(schema.attributes)// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
194
|
+
.filter(([_, attr])=>attr.type === 'media').map(([key])=>key);
|
|
195
|
+
try {
|
|
196
|
+
await Promise.all(aiResult.localizations.map(async (localization)=>{
|
|
197
|
+
const { content, locale } = localization;
|
|
198
|
+
// Fetch the derived locale document
|
|
199
|
+
const derivedDoc = await strapi.documents(model).findOne({
|
|
200
|
+
documentId,
|
|
201
|
+
locale,
|
|
202
|
+
populate: mediaFields
|
|
203
|
+
});
|
|
204
|
+
// Merge AI content and media fields, works only on first level media fields (root level)
|
|
205
|
+
const mergedData = structuredClone(content);
|
|
206
|
+
for (const field of mediaFields){
|
|
207
|
+
// Only copy media if not already set in derived locale
|
|
208
|
+
if (!derivedDoc || !derivedDoc[field]) {
|
|
209
|
+
mergedData[field] = document[field];
|
|
210
|
+
} else {
|
|
211
|
+
mergedData[field] = derivedDoc[field];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
await strapi.documents(model).update({
|
|
215
|
+
documentId,
|
|
216
|
+
locale,
|
|
217
|
+
fields: [],
|
|
218
|
+
data: mergedData
|
|
219
|
+
});
|
|
220
|
+
await aiLocalizationJobsService.upsertJobForDocument({
|
|
221
|
+
documentId,
|
|
222
|
+
contentType: model,
|
|
223
|
+
sourceLocale: document.locale,
|
|
224
|
+
targetLocales,
|
|
225
|
+
status: 'completed'
|
|
226
|
+
});
|
|
227
|
+
}));
|
|
228
|
+
} catch (error) {
|
|
229
|
+
await aiLocalizationJobsService.upsertJobForDocument({
|
|
230
|
+
documentId,
|
|
231
|
+
contentType: model,
|
|
232
|
+
sourceLocale: document.locale,
|
|
233
|
+
targetLocales,
|
|
234
|
+
status: 'failed'
|
|
235
|
+
});
|
|
236
|
+
strapi.log.error('AI Localizations generation failed', error);
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
setupMiddleware () {
|
|
240
|
+
strapi.documents.use(async (context, next)=>{
|
|
241
|
+
const result = await next();
|
|
242
|
+
// Only trigger for the allowed actions
|
|
243
|
+
if (![
|
|
244
|
+
'create',
|
|
245
|
+
'update'
|
|
246
|
+
].includes(context.action)) {
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
// Check if AI localizations are enabled before triggering
|
|
250
|
+
const isEnabled = await this.isEnabled();
|
|
251
|
+
if (!isEnabled) {
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
// Don't await since localizations should be done in the background without blocking the request
|
|
255
|
+
strapi.plugin('i18n').service('ai-localizations').generateDocumentLocalizations({
|
|
256
|
+
model: context.contentType.uid,
|
|
257
|
+
document: result
|
|
258
|
+
}).catch((error)=>{
|
|
259
|
+
strapi.log.error('AI Localizations generation failed', error);
|
|
260
|
+
});
|
|
261
|
+
return result;
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
exports.createAILocalizationsService = createAILocalizationsService;
|
|
268
|
+
//# sourceMappingURL=ai-localizations.js.map
|