@strapi/i18n 5.55.1 → 5.57.0
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/contentManagerHooks/editView.js +0 -1
- package/dist/admin/contentManagerHooks/editView.js.map +1 -1
- package/dist/admin/contentManagerHooks/editView.mjs +0 -1
- package/dist/admin/contentManagerHooks/editView.mjs.map +1 -1
- package/dist/server/bootstrap.js +2 -2
- package/dist/server/bootstrap.js.map +1 -1
- package/dist/server/bootstrap.mjs +1 -1
- package/dist/server/bootstrap.mjs.map +1 -1
- package/dist/server/controllers/content-types.js +11 -11
- package/dist/server/controllers/content-types.js.map +1 -1
- package/dist/server/controllers/content-types.mjs +11 -11
- package/dist/server/controllers/content-types.mjs.map +1 -1
- package/dist/server/controllers/locales.js +2 -2
- package/dist/server/controllers/locales.js.map +1 -1
- package/dist/server/controllers/locales.mjs +2 -2
- package/dist/server/controllers/locales.mjs.map +1 -1
- package/dist/server/controllers/validate-locale-creation.js +1 -2
- package/dist/server/controllers/validate-locale-creation.js.map +1 -1
- package/dist/server/controllers/validate-locale-creation.mjs +1 -2
- package/dist/server/controllers/validate-locale-creation.mjs.map +1 -1
- package/dist/server/graphql.js +4 -4
- package/dist/server/graphql.js.map +1 -1
- package/dist/server/graphql.mjs +2 -2
- package/dist/server/graphql.mjs.map +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/localization.js +36 -0
- package/dist/server/localization.js.map +1 -0
- package/dist/server/localization.mjs +34 -0
- package/dist/server/localization.mjs.map +1 -0
- package/dist/server/register.js +2 -0
- package/dist/server/register.js.map +1 -1
- package/dist/server/register.mjs +2 -0
- package/dist/server/register.mjs.map +1 -1
- package/dist/server/services/ai-translations-strapi-managed.js +1 -1
- package/dist/server/services/ai-translations-strapi-managed.js.map +1 -1
- package/dist/server/services/ai-translations-strapi-managed.mjs +1 -1
- package/dist/server/services/ai-translations-strapi-managed.mjs.map +1 -1
- package/dist/server/services/ai-translations.js +2 -0
- package/dist/server/services/ai-translations.js.map +1 -1
- package/dist/server/services/ai-translations.mjs +2 -0
- package/dist/server/services/ai-translations.mjs.map +1 -1
- package/dist/server/services/content-types.js +12 -12
- package/dist/server/services/content-types.js.map +1 -1
- package/dist/server/services/content-types.mjs +11 -11
- package/dist/server/services/content-types.mjs.map +1 -1
- package/dist/server/services/fill-from-locale.js +5 -6
- package/dist/server/services/fill-from-locale.js.map +1 -1
- package/dist/server/services/fill-from-locale.mjs +5 -6
- package/dist/server/services/fill-from-locale.mjs.map +1 -1
- package/dist/server/services/locales.js +1 -2
- package/dist/server/services/locales.js.map +1 -1
- package/dist/server/services/locales.mjs +1 -2
- package/dist/server/services/locales.mjs.map +1 -1
- package/dist/server/services/localizations.js +4 -4
- package/dist/server/services/localizations.js.map +1 -1
- package/dist/server/services/localizations.mjs +1 -1
- package/dist/server/services/localizations.mjs.map +1 -1
- package/dist/server/services/metrics.js +1 -2
- package/dist/server/services/metrics.js.map +1 -1
- package/dist/server/services/metrics.mjs +1 -2
- package/dist/server/services/metrics.mjs.map +1 -1
- package/dist/server/services/permissions/actions.js +5 -5
- package/dist/server/services/permissions/actions.js.map +1 -1
- package/dist/server/services/permissions/actions.mjs +5 -5
- package/dist/server/services/permissions/actions.mjs.map +1 -1
- package/dist/server/services/permissions/sections-builder.js +2 -2
- package/dist/server/services/permissions/sections-builder.js.map +1 -1
- package/dist/server/services/permissions/sections-builder.mjs +1 -1
- package/dist/server/services/permissions/sections-builder.mjs.map +1 -1
- package/dist/server/services/sanitize/index.js +2 -2
- package/dist/server/services/sanitize/index.js.map +1 -1
- package/dist/server/services/sanitize/index.mjs +1 -1
- package/dist/server/services/sanitize/index.mjs.map +1 -1
- package/dist/server/src/controllers/content-types.d.ts.map +1 -1
- package/dist/server/src/controllers/validate-locale-creation.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +1 -2
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/localization.d.ts +4 -0
- package/dist/server/src/localization.d.ts.map +1 -0
- package/dist/server/src/register.d.ts.map +1 -1
- package/dist/server/src/services/ai-translations.d.ts.map +1 -1
- package/dist/server/src/services/fill-from-locale.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/locales.d.ts.map +1 -1
- package/dist/server/src/services/metrics.d.ts.map +1 -1
- package/dist/server/src/validation/content-types.d.ts.map +1 -1
- package/dist/server/src/validation/locales.d.ts.map +1 -1
- package/dist/server/validation/content-types.js +1 -2
- package/dist/server/validation/content-types.js.map +1 -1
- package/dist/server/validation/content-types.mjs +1 -2
- package/dist/server/validation/content-types.mjs.map +1 -1
- package/dist/server/validation/locales.js +1 -2
- package/dist/server/validation/locales.js.map +1 -1
- package/dist/server/validation/locales.mjs +1 -2
- package/dist/server/validation/locales.mjs.map +1 -1
- package/package.json +12 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-locale-creation.js","sources":["../../../server/src/controllers/validate-locale-creation.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"validate-locale-creation.js","sources":["../../../server/src/controllers/validate-locale-creation.ts"],"sourcesContent":["import { errors } from '@strapi/utils';\nimport type { Core, Struct } from '@strapi/types';\nimport { getService } from '../utils';\n\nconst { ApplicationError } = errors;\n\n// TODO: v5 if implemented in the CM => delete this middleware\nconst validateLocaleCreation: Core.MiddlewareHandler = async (ctx, next) => {\n const { model } = ctx.params;\n const { query } = ctx.request;\n\n // Prevent empty body\n if (!ctx.request.body) {\n ctx.request.body = {};\n }\n\n const body = ctx.request.body as any;\n\n const { getValidLocale, isLocalizedContentType } = getService('content-types');\n\n const modelDef = strapi.getModel(model) as Struct.ContentTypeSchema;\n\n if (!isLocalizedContentType(modelDef)) {\n return next();\n }\n\n // Prevent empty string locale\n const locale = query?.locale || body?.locale || undefined;\n\n // cleanup to avoid creating duplicates in single types\n ctx.request.query = {};\n\n let entityLocale;\n try {\n entityLocale = await getValidLocale(locale);\n } catch {\n throw new ApplicationError(\"This locale doesn't exist\");\n }\n\n body.locale = entityLocale;\n\n if (modelDef.kind === 'singleType') {\n const entity = await strapi.entityService.findMany(modelDef.uid, {\n locale: entityLocale,\n } as any); // TODO: add this type to entityService\n\n ctx.request.query.locale = body.locale;\n\n // updating\n if (entity) {\n return next();\n }\n }\n\n return next();\n};\n\nexport default validateLocaleCreation;\n"],"names":["ApplicationError","errors","validateLocaleCreation","ctx","next","model","params","query","request","body","getValidLocale","isLocalizedContentType","getService","modelDef","strapi","getModel","locale","undefined","entityLocale","kind","entity","entityService","findMany","uid"],"mappings":";;;;;AAIA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,YAAAA;AAE7B;AACA,MAAMC,sBAAAA,GAAiD,OAAOC,GAAAA,EAAKC,IAAAA,GAAAA;AACjE,IAAA,MAAM,EAAEC,KAAK,EAAE,GAAGF,IAAIG,MAAM;AAC5B,IAAA,MAAM,EAAEC,KAAK,EAAE,GAAGJ,IAAIK,OAAO;;AAG7B,IAAA,IAAI,CAACL,GAAAA,CAAIK,OAAO,CAACC,IAAI,EAAE;AACrBN,QAAAA,GAAAA,CAAIK,OAAO,CAACC,IAAI,GAAG,EAAC;AACtB,IAAA;AAEA,IAAA,MAAMA,IAAAA,GAAON,GAAAA,CAAIK,OAAO,CAACC,IAAI;AAE7B,IAAA,MAAM,EAAEC,cAAc,EAAEC,sBAAsB,EAAE,GAAGC,gBAAAA,CAAW,eAAA,CAAA;IAE9D,MAAMC,QAAAA,GAAWC,MAAAA,CAAOC,QAAQ,CAACV,KAAAA,CAAAA;IAEjC,IAAI,CAACM,uBAAuBE,QAAAA,CAAAA,EAAW;QACrC,OAAOT,IAAAA,EAAAA;AACT,IAAA;;AAGA,IAAA,MAAMY,MAAAA,GAAST,KAAAA,EAAOS,MAAAA,IAAUP,IAAAA,EAAMO,MAAAA,IAAUC,SAAAA;;AAGhDd,IAAAA,GAAAA,CAAIK,OAAO,CAACD,KAAK,GAAG,EAAC;IAErB,IAAIW,YAAAA;IACJ,IAAI;AACFA,QAAAA,YAAAA,GAAe,MAAMR,cAAAA,CAAeM,MAAAA,CAAAA;AACtC,IAAA,CAAA,CAAE,OAAM;AACN,QAAA,MAAM,IAAIhB,gBAAAA,CAAiB,2BAAA,CAAA;AAC7B,IAAA;AAEAS,IAAAA,IAAAA,CAAKO,MAAM,GAAGE,YAAAA;IAEd,IAAIL,QAAAA,CAASM,IAAI,KAAK,YAAA,EAAc;QAClC,MAAMC,MAAAA,GAAS,MAAMN,MAAAA,CAAOO,aAAa,CAACC,QAAQ,CAACT,QAAAA,CAASU,GAAG,EAAE;YAC/DP,MAAAA,EAAQE;AACV,SAAA,CAAA,CAAA;AAEAf,QAAAA,GAAAA,CAAIK,OAAO,CAACD,KAAK,CAACS,MAAM,GAAGP,KAAKO,MAAM;;AAGtC,QAAA,IAAII,MAAAA,EAAQ;YACV,OAAOhB,IAAAA,EAAAA;AACT,QAAA;AACF,IAAA;IAEA,OAAOA,IAAAA,EAAAA;AACT;;;;"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { get } from 'lodash/fp';
|
|
2
1
|
import { errors } from '@strapi/utils';
|
|
3
2
|
import { getService } from '../utils/index.mjs';
|
|
4
3
|
|
|
@@ -18,7 +17,7 @@ const validateLocaleCreation = async (ctx, next)=>{
|
|
|
18
17
|
return next();
|
|
19
18
|
}
|
|
20
19
|
// Prevent empty string locale
|
|
21
|
-
const locale =
|
|
20
|
+
const locale = query?.locale || body?.locale || undefined;
|
|
22
21
|
// cleanup to avoid creating duplicates in single types
|
|
23
22
|
ctx.request.query = {};
|
|
24
23
|
let entityLocale;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-locale-creation.mjs","sources":["../../../server/src/controllers/validate-locale-creation.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"validate-locale-creation.mjs","sources":["../../../server/src/controllers/validate-locale-creation.ts"],"sourcesContent":["import { errors } from '@strapi/utils';\nimport type { Core, Struct } from '@strapi/types';\nimport { getService } from '../utils';\n\nconst { ApplicationError } = errors;\n\n// TODO: v5 if implemented in the CM => delete this middleware\nconst validateLocaleCreation: Core.MiddlewareHandler = async (ctx, next) => {\n const { model } = ctx.params;\n const { query } = ctx.request;\n\n // Prevent empty body\n if (!ctx.request.body) {\n ctx.request.body = {};\n }\n\n const body = ctx.request.body as any;\n\n const { getValidLocale, isLocalizedContentType } = getService('content-types');\n\n const modelDef = strapi.getModel(model) as Struct.ContentTypeSchema;\n\n if (!isLocalizedContentType(modelDef)) {\n return next();\n }\n\n // Prevent empty string locale\n const locale = query?.locale || body?.locale || undefined;\n\n // cleanup to avoid creating duplicates in single types\n ctx.request.query = {};\n\n let entityLocale;\n try {\n entityLocale = await getValidLocale(locale);\n } catch {\n throw new ApplicationError(\"This locale doesn't exist\");\n }\n\n body.locale = entityLocale;\n\n if (modelDef.kind === 'singleType') {\n const entity = await strapi.entityService.findMany(modelDef.uid, {\n locale: entityLocale,\n } as any); // TODO: add this type to entityService\n\n ctx.request.query.locale = body.locale;\n\n // updating\n if (entity) {\n return next();\n }\n }\n\n return next();\n};\n\nexport default validateLocaleCreation;\n"],"names":["ApplicationError","errors","validateLocaleCreation","ctx","next","model","params","query","request","body","getValidLocale","isLocalizedContentType","getService","modelDef","strapi","getModel","locale","undefined","entityLocale","kind","entity","entityService","findMany","uid"],"mappings":";;;AAIA,MAAM,EAAEA,gBAAgB,EAAE,GAAGC,MAAAA;AAE7B;AACA,MAAMC,sBAAAA,GAAiD,OAAOC,GAAAA,EAAKC,IAAAA,GAAAA;AACjE,IAAA,MAAM,EAAEC,KAAK,EAAE,GAAGF,IAAIG,MAAM;AAC5B,IAAA,MAAM,EAAEC,KAAK,EAAE,GAAGJ,IAAIK,OAAO;;AAG7B,IAAA,IAAI,CAACL,GAAAA,CAAIK,OAAO,CAACC,IAAI,EAAE;AACrBN,QAAAA,GAAAA,CAAIK,OAAO,CAACC,IAAI,GAAG,EAA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var _ = require('lodash');
|
|
4
4
|
var utils = require('@strapi/utils');
|
|
5
5
|
|
|
6
6
|
const { ValidationError } = utils.errors;
|
|
@@ -60,13 +60,13 @@ const getLocaleScalar = ({ nexus })=>{
|
|
|
60
60
|
return nexus.scalarType({
|
|
61
61
|
name: LOCALE_SCALAR_TYPENAME,
|
|
62
62
|
description: 'A string used to identify an i18n locale',
|
|
63
|
-
serialize:
|
|
64
|
-
parseValue:
|
|
63
|
+
serialize: _.identity,
|
|
64
|
+
parseValue: _.identity,
|
|
65
65
|
parseLiteral (ast) {
|
|
66
66
|
if (ast.kind !== 'StringValue') {
|
|
67
67
|
throw new ValidationError('Locale cannot represent non string type');
|
|
68
68
|
}
|
|
69
|
-
const isValidLocale = ast.value === '*' || locales.find(
|
|
69
|
+
const isValidLocale = ast.value === '*' || locales.find(_.matchesProperty('code', ast.value));
|
|
70
70
|
if (!isValidLocale) {
|
|
71
71
|
throw new ValidationError('Unknown locale supplied');
|
|
72
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.js","sources":["../../server/src/graphql.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"graphql.js","sources":["../../server/src/graphql.ts"],"sourcesContent":["import { matchesProperty, identity } from 'lodash';\nimport { errors } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nconst { ValidationError } = errors;\n\nconst LOCALE_SCALAR_TYPENAME = 'I18NLocaleCode';\nconst LOCALE_ARG_PLUGIN_NAME = 'I18NLocaleArg';\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => ({\n register() {\n const { service: getGraphQLService } = strapi.plugin('graphql');\n const { service: getI18NService } = strapi.plugin('i18n');\n\n const { isLocalizedContentType } = getI18NService('content-types');\n\n const extensionService = getGraphQLService('extension');\n\n extensionService.shadowCRUD('plugin::i18n.locale').disableMutations();\n\n // Disable unwanted fields for localized content types\n Object.entries(strapi.contentTypes).forEach(([uid, ct]) => {\n if (isLocalizedContentType(ct)) {\n // Disable locale field in localized inputs\n extensionService.shadowCRUD(uid).field('locale').disableInput();\n\n // Disable localizations field in localized inputs\n extensionService.shadowCRUD(uid).field('localizations').disableInput();\n }\n });\n\n extensionService.use(({ nexus, typeRegistry }: any) => {\n const i18nLocaleArgPlugin = getI18nLocaleArgPlugin({ nexus, typeRegistry });\n const i18nLocaleScalar = getLocaleScalar({ nexus });\n return {\n plugins: [i18nLocaleArgPlugin],\n types: [i18nLocaleScalar],\n\n resolversConfig: {\n // Modify the default scope associated to find and findOne locale queries to match the actual action name\n 'Query.i18NLocale': { auth: { scope: 'plugin::i18n.locales.listLocales' } },\n 'Query.i18NLocales': { auth: { scope: 'plugin::i18n.locales.listLocales' } },\n },\n };\n });\n },\n});\n\nconst getLocaleScalar = ({ nexus }: any) => {\n const { service: getI18NService } = strapi.plugin('i18n');\n\n const locales = getI18NService('iso-locales').getIsoLocales();\n\n return nexus.scalarType({\n name: LOCALE_SCALAR_TYPENAME,\n\n description: 'A string used to identify an i18n locale',\n\n serialize: identity,\n parseValue: identity,\n\n parseLiteral(ast: any) {\n if (ast.kind !== 'StringValue') {\n throw new ValidationError('Locale cannot represent non string type');\n }\n\n const isValidLocale = ast.value === '*' || locales.find(matchesProperty('code', ast.value));\n\n if (!isValidLocale) {\n throw new ValidationError('Unknown locale supplied');\n }\n\n return ast.value;\n },\n });\n};\n\nconst getI18nLocaleArgPlugin = ({ nexus, typeRegistry }: any) => {\n const { service: getI18NService } = strapi.plugin('i18n');\n\n const { isLocalizedContentType } = getI18NService('content-types');\n\n return nexus.plugin({\n name: LOCALE_ARG_PLUGIN_NAME,\n\n onAddOutputField(config: any) {\n // Add the locale arg to the queries on localized CTs\n\n const { parentType } = config;\n\n // Only target queries or mutations\n if (parentType !== 'Query' && parentType !== 'Mutation') {\n return;\n }\n\n let contentType;\n\n if (config?.extensions?.strapi?.contentType) {\n contentType = config.extensions.strapi.contentType;\n } else {\n const registryType = typeRegistry.get(config.type);\n\n if (!registryType) {\n return;\n }\n\n contentType = registryType.config.contentType;\n }\n\n // Ignore non-localized content types\n if (!isLocalizedContentType(contentType)) {\n return;\n }\n\n if (!config.args) {\n config.args = {};\n }\n\n config.args.locale = nexus.arg({\n type: LOCALE_SCALAR_TYPENAME,\n description: 'The locale to use for the query',\n });\n },\n });\n};\n"],"names":["ValidationError","errors","LOCALE_SCALAR_TYPENAME","LOCALE_ARG_PLUGIN_NAME","strapi","register","service","getGraphQLService","plugin","getI18NService","isLocalizedContentType","extensionService","shadowCRUD","disableMutations","Object","entries","contentTypes","forEach","uid","ct","field","disableInput","use","nexus","typeRegistry","i18nLocaleArgPlugin","getI18nLocaleArgPlugin","i18nLocaleScalar","getLocaleScalar","plugins","types","resolversConfig","auth","scope","locales","getIsoLocales","scalarType","name","description","serialize","identity","parseValue","parseLiteral","ast","kind","isValidLocale","value","find","matchesProperty","onAddOutputField","config","parentType","contentType","extensions","registryType","get","type","args","locale","arg"],"mappings":";;;;;AAIA,MAAM,EAAEA,eAAe,EAAE,GAAGC,YAAAA;AAE5B,MAAMC,sBAAAA,GAAyB,gBAAA;AAC/B,MAAMC,sBAAAA,GAAyB,eAAA;AAE/B,sBAAe,CAAA,CAAC,EAAEC,QAAAA,OAAM,EAA2B,IAAM;AACvDC,QAAAA,QAAAA,CAAAA,GAAAA;AACE,YAAA,MAAM,EAAEC,OAAAA,EAASC,iBAAiB,EAAE,GAAGH,OAAAA,CAAOI,MAAM,CAAC,SAAA,CAAA;AACrD,YAAA,MAAM,EAAEF,OAAAA,EAASG,cAAc,EAAE,GAAGL,OAAAA,CAAOI,MAAM,CAAC,MAAA,CAAA;AAElD,YAAA,MAAM,EAAEE,sBAAsB,EAAE,GAAGD,cAAAA,CAAe,eAAA,CAAA;AAElD,YAAA,MAAME,mBAAmBJ,iBAAAA,CAAkB,WAAA,CAAA;YAE3CI,gBAAAA,CAAiBC,UAAU,CAAC,qBAAA,CAAA,CAAuBC,gBAAgB,EAAA;;YAGnEC,MAAAA,CAAOC,OAAO,CAACX,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,EAAQG,UAAAA,EAAYjD,MAAAA,EAAQgD,WAAAA,EAAa;AAC3CA,gBAAAA,WAAAA,GAAcF,MAAAA,CAAOG,UAAU,CAACjD,MAAM,CAACgD,WAAW;YACpD,CAAA,MAAO;AACL,gBAAA,MAAME,YAAAA,GAAe9B,YAAAA,CAAa+B,GAAG,CAACL,OAAOM,IAAI,CAAA;AAEjD,gBAAA,IAAI,CAACF,YAAAA,EAAc;AACjB,oBAAA;AACF,gBAAA;gBAEAF,WAAAA,GAAcE,YAAAA,CAAaJ,MAAM,CAACE,WAAW;AAC/C,YAAA;;YAGA,IAAI,CAAC1C,uBAAuB0C,WAAAA,CAAAA,EAAc;AACxC,gBAAA;AACF,YAAA;YAEA,IAAI,CAACF,MAAAA,CAAOO,IAAI,EAAE;gBAChBP,MAAAA,CAAOO,IAAI,GAAG,EAAC;AACjB,YAAA;AAEAP,YAAAA,MAAAA,CAAOO,IAAI,CAACC,MAAM,GAAGnC,KAAAA,CAAMoC,GAAG,CAAC;gBAC7BH,IAAAA,EAAMtD,sBAAAA;gBACNoC,WAAAA,EAAa;AACf,aAAA,CAAA;AACF,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
package/dist/server/graphql.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { identity,
|
|
1
|
+
import { identity, matchesProperty } from 'lodash';
|
|
2
2
|
import { errors } from '@strapi/utils';
|
|
3
3
|
|
|
4
4
|
const { ValidationError } = errors;
|
|
@@ -64,7 +64,7 @@ const getLocaleScalar = ({ nexus })=>{
|
|
|
64
64
|
if (ast.kind !== 'StringValue') {
|
|
65
65
|
throw new ValidationError('Locale cannot represent non string type');
|
|
66
66
|
}
|
|
67
|
-
const isValidLocale = ast.value === '*' || locales.find(
|
|
67
|
+
const isValidLocale = ast.value === '*' || locales.find(matchesProperty('code', ast.value));
|
|
68
68
|
if (!isValidLocale) {
|
|
69
69
|
throw new ValidationError('Unknown locale supplied');
|
|
70
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.mjs","sources":["../../server/src/graphql.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"graphql.mjs","sources":["../../server/src/graphql.ts"],"sourcesContent":["import { matchesProperty, identity } from 'lodash';\nimport { errors } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nconst { ValidationError } = errors;\n\nconst LOCALE_SCALAR_TYPENAME = 'I18NLocaleCode';\nconst LOCALE_ARG_PLUGIN_NAME = 'I18NLocaleArg';\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => ({\n register() {\n const { service: getGraphQLService } = strapi.plugin('graphql');\n const { service: getI18NService } = strapi.plugin('i18n');\n\n const { isLocalizedContentType } = getI18NService('content-types');\n\n const extensionService = getGraphQLService('extension');\n\n extensionService.shadowCRUD('plugin::i18n.locale').disableMutations();\n\n // Disable unwanted fields for localized content types\n Object.entries(strapi.contentTypes).forEach(([uid, ct]) => {\n if (isLocalizedContentType(ct)) {\n // Disable locale field in localized inputs\n extensionService.shadowCRUD(uid).field('locale').disableInput();\n\n // Disable localizations field in localized inputs\n extensionService.shadowCRUD(uid).field('localizations').disableInput();\n }\n });\n\n extensionService.use(({ nexus, typeRegistry }: any) => {\n const i18nLocaleArgPlugin = getI18nLocaleArgPlugin({ nexus, typeRegistry });\n const i18nLocaleScalar = getLocaleScalar({ nexus });\n return {\n plugins: [i18nLocaleArgPlugin],\n types: [i18nLocaleScalar],\n\n resolversConfig: {\n // Modify the default scope associated to find and findOne locale queries to match the actual action name\n 'Query.i18NLocale': { auth: { scope: 'plugin::i18n.locales.listLocales' } },\n 'Query.i18NLocales': { auth: { scope: 'plugin::i18n.locales.listLocales' } },\n },\n };\n });\n },\n});\n\nconst getLocaleScalar = ({ nexus }: any) => {\n const { service: getI18NService } = strapi.plugin('i18n');\n\n const locales = getI18NService('iso-locales').getIsoLocales();\n\n return nexus.scalarType({\n name: LOCALE_SCALAR_TYPENAME,\n\n description: 'A string used to identify an i18n locale',\n\n serialize: identity,\n parseValue: identity,\n\n parseLiteral(ast: any) {\n if (ast.kind !== 'StringValue') {\n throw new ValidationError('Locale cannot represent non string type');\n }\n\n const isValidLocale = ast.value === '*' || locales.find(matchesProperty('code', ast.value));\n\n if (!isValidLocale) {\n throw new ValidationError('Unknown locale supplied');\n }\n\n return ast.value;\n },\n });\n};\n\nconst getI18nLocaleArgPlugin = ({ nexus, typeRegistry }: any) => {\n const { service: getI18NService } = strapi.plugin('i18n');\n\n const { isLocalizedContentType } = getI18NService('content-types');\n\n return nexus.plugin({\n name: LOCALE_ARG_PLUGIN_NAME,\n\n onAddOutputField(config: any) {\n // Add the locale arg to the queries on localized CTs\n\n const { parentType } = config;\n\n // Only target queries or mutations\n if (parentType !== 'Query' && parentType !== 'Mutation') {\n return;\n }\n\n let contentType;\n\n if (config?.extensions?.strapi?.contentType) {\n contentType = config.extensions.strapi.contentType;\n } else {\n const registryType = typeRegistry.get(config.type);\n\n if (!registryType) {\n return;\n }\n\n contentType = registryType.config.contentType;\n }\n\n // Ignore non-localized content types\n if (!isLocalizedContentType(contentType)) {\n return;\n }\n\n if (!config.args) {\n config.args = {};\n }\n\n config.args.locale = nexus.arg({\n type: LOCALE_SCALAR_TYPENAME,\n description: 'The locale to use for the query',\n });\n },\n });\n};\n"],"names":["ValidationError","errors","LOCALE_SCALAR_TYPENAME","LOCALE_ARG_PLUGIN_NAME","strapi","register","service","getGraphQLService","plugin","getI18NService","isLocalizedContentType","extensionService","shadowCRUD","disableMutations","Object","entries","contentTypes","forEach","uid","ct","field","disableInput","use","nexus","typeRegistry","i18nLocaleArgPlugin","getI18nLocaleArgPlugin","i18nLocaleScalar","getLocaleScalar","plugins","types","resolversConfig","auth","scope","locales","getIsoLocales","scalarType","name","description","serialize","identity","parseValue","parseLiteral","ast","kind","isValidLocale","value","find","matchesProperty","onAddOutputField","config","parentType","contentType","extensions","registryType","get","type","args","locale","arg"],"mappings":";;;AAIA,MAAM,EAAEA,eAAe,E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AG,CAAC;gBAC7BH,IAAAA,EAAMtD,sBAAAA;gBACNoC,WAAAA,EAAa;AACf,aAAA,CAAA;AACF,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../server/src/index.ts"],"sourcesContent":["import bootstrap from './bootstrap';\nimport register from './register';\nimport contentTypes from './content-types';\nimport services from './services';\nimport routes from './routes';\nimport controllers from './controllers';\n\nexport
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../server/src/index.ts"],"sourcesContent":["import bootstrap from './bootstrap';\nimport register from './register';\nimport contentTypes from './content-types';\nimport services from './services';\nimport routes from './routes';\nimport controllers from './controllers';\n\nexport default () => ({\n register,\n bootstrap,\n routes,\n controllers,\n contentTypes,\n services,\n});\n"],"names":["register","bootstrap","routes","controllers","contentTypes","services"],"mappings":";;;;;;;;;AAOA,YAAe,CAAA,KAAO;AACpBA,QAAAA,QAAAA;AACAC,QAAAA,SAAAA;AACAC,gBAAAA,OAAAA;AACAC,qBAAAA,OAAAA;AACAC,sBAAAA,OAAAA;AACAC,kBAAAA;AACF,KAAA,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../server/src/index.ts"],"sourcesContent":["import bootstrap from './bootstrap';\nimport register from './register';\nimport contentTypes from './content-types';\nimport services from './services';\nimport routes from './routes';\nimport controllers from './controllers';\n\nexport
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../server/src/index.ts"],"sourcesContent":["import bootstrap from './bootstrap';\nimport register from './register';\nimport contentTypes from './content-types';\nimport services from './services';\nimport routes from './routes';\nimport controllers from './controllers';\n\nexport default () => ({\n register,\n bootstrap,\n routes,\n controllers,\n contentTypes,\n services,\n});\n"],"names":["register","bootstrap","routes","controllers","contentTypes","services"],"mappings":";;;;;;;AAOA,YAAe,CAAA,KAAO;AACpBA,QAAAA,QAAAA;AACAC,QAAAA,SAAAA;AACAC,QAAAA,MAAAA;AACAC,QAAAA,WAAAA;AACAC,QAAAA,YAAAA;AACAC,QAAAA;AACF,KAAA,CAAC;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/** Adapts i18n services to core's capability without resolving them before registration finishes. */ const createLocalizationProvider = (strapi)=>{
|
|
4
|
+
const getContentTypesService = ()=>strapi.plugin('i18n').service('content-types');
|
|
5
|
+
const getLocalesService = ()=>strapi.plugin('i18n').service('locales');
|
|
6
|
+
return {
|
|
7
|
+
isLocalizedContentType (model) {
|
|
8
|
+
return getContentTypesService().isLocalizedContentType(model);
|
|
9
|
+
},
|
|
10
|
+
async getDefaultLocale () {
|
|
11
|
+
// The core store is untyped: only a code string is a default locale
|
|
12
|
+
const value = await getLocalesService().getDefaultLocale();
|
|
13
|
+
return typeof value === 'string' ? value : null;
|
|
14
|
+
},
|
|
15
|
+
async getLocales () {
|
|
16
|
+
const locales = await getLocalesService().find();
|
|
17
|
+
// Stored names are optional, but core consumers need a display name for every locale.
|
|
18
|
+
return (locales ?? []).map(({ code, name })=>({
|
|
19
|
+
code,
|
|
20
|
+
name: name ?? code
|
|
21
|
+
}));
|
|
22
|
+
},
|
|
23
|
+
getNestedPopulateOfNonLocalizedAttributes (modelUID) {
|
|
24
|
+
return getContentTypesService().getNestedPopulateOfNonLocalizedAttributes(modelUID);
|
|
25
|
+
},
|
|
26
|
+
getNonLocalizedAttributes (model) {
|
|
27
|
+
return getContentTypesService().getNonLocalizedAttributes(model);
|
|
28
|
+
},
|
|
29
|
+
fillNonLocalizedAttributes (entry, relatedEntry, options) {
|
|
30
|
+
getContentTypesService().fillNonLocalizedAttributes(entry, relatedEntry, options);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.createLocalizationProvider = createLocalizationProvider;
|
|
36
|
+
//# sourceMappingURL=localization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.js","sources":["../../server/src/localization.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\nimport type { ContentTypesService } from './services/content-types';\nimport type { LocaleService } from './services/locales';\n\n/** Adapts i18n services to core's capability without resolving them before registration finishes. */\nexport const createLocalizationProvider = (strapi: Core.Strapi): Modules.Localization.Provider => {\n const getContentTypesService = () =>\n strapi.plugin('i18n').service<ReturnType<ContentTypesService>>('content-types');\n const getLocalesService = () =>\n strapi.plugin('i18n').service<ReturnType<LocaleService>>('locales');\n\n return {\n isLocalizedContentType(model) {\n return getContentTypesService().isLocalizedContentType(model);\n },\n async getDefaultLocale() {\n // The core store is untyped: only a code string is a default locale\n const value: unknown = await getLocalesService().getDefaultLocale();\n return typeof value === 'string' ? value : null;\n },\n async getLocales() {\n const locales: Array<{ code: string; name: string | null }> | null | undefined =\n await getLocalesService().find();\n\n // Stored names are optional, but core consumers need a display name for every locale.\n return (locales ?? []).map(({ code, name }) => ({ code, name: name ?? code }));\n },\n getNestedPopulateOfNonLocalizedAttributes(modelUID) {\n return getContentTypesService().getNestedPopulateOfNonLocalizedAttributes(modelUID);\n },\n getNonLocalizedAttributes(model) {\n return getContentTypesService().getNonLocalizedAttributes(model);\n },\n fillNonLocalizedAttributes(entry, relatedEntry, options) {\n getContentTypesService().fillNonLocalizedAttributes(entry, relatedEntry, options);\n },\n };\n};\n"],"names":["createLocalizationProvider","strapi","getContentTypesService","plugin","service","getLocalesService","isLocalizedContentType","model","getDefaultLocale","value","getLocales","locales","find","map","code","name","getNestedPopulateOfNonLocalizedAttributes","modelUID","getNonLocalizedAttributes","fillNonLocalizedAttributes","entry","relatedEntry","options"],"mappings":";;AAIA,sGACO,MAAMA,0BAAAA,GAA6B,CAACC,MAAAA,GAAAA;AACzC,IAAA,MAAMC,yBAAyB,IAC7BD,MAAAA,CAAOE,MAAM,CAAC,MAAA,CAAA,CAAQC,OAAO,CAAkC,eAAA,CAAA;AACjE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F;;;;"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Adapts i18n services to core's capability without resolving them before registration finishes. */ const createLocalizationProvider = (strapi)=>{
|
|
2
|
+
const getContentTypesService = ()=>strapi.plugin('i18n').service('content-types');
|
|
3
|
+
const getLocalesService = ()=>strapi.plugin('i18n').service('locales');
|
|
4
|
+
return {
|
|
5
|
+
isLocalizedContentType (model) {
|
|
6
|
+
return getContentTypesService().isLocalizedContentType(model);
|
|
7
|
+
},
|
|
8
|
+
async getDefaultLocale () {
|
|
9
|
+
// The core store is untyped: only a code string is a default locale
|
|
10
|
+
const value = await getLocalesService().getDefaultLocale();
|
|
11
|
+
return typeof value === 'string' ? value : null;
|
|
12
|
+
},
|
|
13
|
+
async getLocales () {
|
|
14
|
+
const locales = await getLocalesService().find();
|
|
15
|
+
// Stored names are optional, but core consumers need a display name for every locale.
|
|
16
|
+
return (locales ?? []).map(({ code, name })=>({
|
|
17
|
+
code,
|
|
18
|
+
name: name ?? code
|
|
19
|
+
}));
|
|
20
|
+
},
|
|
21
|
+
getNestedPopulateOfNonLocalizedAttributes (modelUID) {
|
|
22
|
+
return getContentTypesService().getNestedPopulateOfNonLocalizedAttributes(modelUID);
|
|
23
|
+
},
|
|
24
|
+
getNonLocalizedAttributes (model) {
|
|
25
|
+
return getContentTypesService().getNonLocalizedAttributes(model);
|
|
26
|
+
},
|
|
27
|
+
fillNonLocalizedAttributes (entry, relatedEntry, options) {
|
|
28
|
+
getContentTypesService().fillNonLocalizedAttributes(entry, relatedEntry, options);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { createLocalizationProvider };
|
|
34
|
+
//# sourceMappingURL=localization.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.mjs","sources":["../../server/src/localization.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\nimport type { ContentTypesService } from './services/content-types';\nimport type { LocaleService } from './services/locales';\n\n/** Adapts i18n services to core's capability without resolving them before registration finishes. */\nexport const createLocalizationProvider = (strapi: Core.Strapi): Modules.Localization.Provider => {\n const getContentTypesService = () =>\n strapi.plugin('i18n').service<ReturnType<ContentTypesService>>('content-types');\n const getLocalesService = () =>\n strapi.plugin('i18n').service<ReturnType<LocaleService>>('locales');\n\n return {\n isLocalizedContentType(model) {\n return getContentTypesService().isLocalizedContentType(model);\n },\n async getDefaultLocale() {\n // The core store is untyped: only a code string is a default locale\n const value: unknown = await getLocalesService().getDefaultLocale();\n return typeof value === 'string' ? value : null;\n },\n async getLocales() {\n const locales: Array<{ code: string; name: string | null }> | null | undefined =\n await getLocalesService().find();\n\n // Stored names are optional, but core consumers need a display name for every locale.\n return (locales ?? []).map(({ code, name }) => ({ code, name: name ?? code }));\n },\n getNestedPopulateOfNonLocalizedAttributes(modelUID) {\n return getContentTypesService().getNestedPopulateOfNonLocalizedAttributes(modelUID);\n },\n getNonLocalizedAttributes(model) {\n return getContentTypesService().getNonLocalizedAttributes(model);\n },\n fillNonLocalizedAttributes(entry, relatedEntry, options) {\n getContentTypesService().fillNonLocalizedAttributes(entry, relatedEntry, options);\n },\n };\n};\n"],"names":["createLocalizationProvider","strapi","getContentTypesService","plugin","service","getLocalesService","isLocalizedContentType","model","getDefaultLocale","value","getLocales","locales","find","map","code","name","getNestedPopulateOfNonLocalizedAttributes","modelUID","getNonLocalizedAttributes","fillNonLocalizedAttributes","entry","relatedEntry","options"],"mappings":"AAIA,sGACO,MAAMA,0BAAAA,GAA6B,CAACC,MAAAA,GAAAA;AACzC,IAAA,MAAMC,yBAAyB,IAC7BD,MAAAA,CAAOE,MAAM,CAAC,MAAA,CAAA,CAAQC,OAAO,CAAkC,eAAA,CAAA;AACjE,IAAA,MAAMC,oBAAoB,IACxBJ,MAAAA,CAAOE,MAAM,CAAC,MAAA,CAAA,CAAQC,OAAO,CAA4B,SAAA,CAAA;IAE3D,OAAO;AACLE,QAAAA,sBAAAA,CAAAA,CAAuBC,KAAK,EAAA;YAC1B,OAAOL,sBAAAA,EAAAA,CAAyBI,sBAAsB,CAACC,KAAAA,CAAAA;AACzD,QAAA,CAAA;QACA,MAAMC,gBAAAA,CAAAA,GAAAA;;YAEJ,MAAMC,KAAAA,GAAiB,MAAMJ,iBAAAA,EAAAA,CAAoBG,gBAAgB,EAAA;YACjE,OAAO,OAAOC,KAAAA,KAAU,QAAA,GAAWA,KAAAA,GAAQ,IAAA;AAC7C,QAAA,CAAA;QACA,MAAMC,UAAAA,CAAAA,GAAAA;YACJ,MAAMC,OAAAA,GACJ,MAAMN,iBAAAA,EAAAA,CAAoBO,IAAI,EAAA;;AAGhC,YAAA,OAAO,CAACD,OAAAA,IAAW,EAAE,EAAEE,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAEC,IAAI,EAAE,IAAM;AAAED,oBAAAA,IAAAA;AAAMC,oBAAAA,IAAAA,EAAMA,IAAAA,IAAQD;iBAAK,CAAA,CAAA;AAC7E,QAAA,CAAA;AACAE,QAAAA,yCAAAA,CAAAA,CAA0CC,QAAQ,EAAA;YAChD,OAAOf,sBAAAA,EAAAA,CAAyBc,yCAAyC,CAACC,QAAAA,CAAAA;AAC5E,QAAA,CAAA;AACAC,QAAAA,yBAAAA,CAAAA,CAA0BX,KAAK,EAAA;YAC7B,OAAOL,sBAAAA,EAAAA,CAAyBgB,yBAAyB,CAACX,KAAAA,CAAAA;AAC5D,QAAA,CAAA;AACAY,QAAAA,0BAAAA,CAAAA,CAA2BC,KAAK,EAAEC,YAAY,EAAEC,OAAO,EAAA;YACrDpB,sBAAAA,EAAAA,CAAyBiB,0BAA0B,CAACC,KAAAA,EAAOC,YAAAA,EAAcC,OAAAA,CAAAA;AAC3E,QAAA;AACF,KAAA;AACF;;;;"}
|
package/dist/server/register.js
CHANGED
|
@@ -5,12 +5,14 @@ var validateLocaleCreation = require('./controllers/validate-locale-creation.js'
|
|
|
5
5
|
var graphql = require('./graphql.js');
|
|
6
6
|
var index = require('./utils/index.js');
|
|
7
7
|
var aiLocalizationJob = require('./models/ai-localization-job.js');
|
|
8
|
+
var localization = require('./localization.js');
|
|
8
9
|
|
|
9
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
11
|
|
|
11
12
|
var ___default = /*#__PURE__*/_interopDefault(_);
|
|
12
13
|
|
|
13
14
|
var register = (async ({ strapi })=>{
|
|
15
|
+
strapi.localization.register(localization.createLocalizationProvider(strapi));
|
|
14
16
|
strapi.get('models').add(aiLocalizationJob.aiLocalizationJob);
|
|
15
17
|
extendContentTypes(strapi);
|
|
16
18
|
addContentManagerLocaleMiddleware(strapi);
|
|
@@ -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';\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 strapi\n .hook('strapi::content-types.afterSync')\n .register(({ oldContentTypes, contentTypes }: any) =>\n getService('permissions').actions.repairPermissionsForNewlyLocalizedTypes({\n oldContentTypes,\n contentTypes,\n })\n );\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","hook","
|
|
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';\nimport { createLocalizationProvider } from './localization';\n\nexport default async ({ strapi }: { strapi: Core.Strapi }) => {\n strapi.localization.register(createLocalizationProvider(strapi));\n strapi.get('models').add(aiLocalizationJob);\n\n extendContentTypes(strapi);\n addContentManagerLocaleMiddleware(strapi);\n\n strapi\n .hook('strapi::content-types.afterSync')\n .register(({ oldContentTypes, contentTypes }: any) =>\n getService('permissions').actions.repairPermissionsForNewlyLocalizedTypes({\n oldContentTypes,\n contentTypes,\n })\n );\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","localization","register","createLocalizationProvider","get","add","aiLocalizationJob","extendContentTypes","addContentManagerLocaleMiddleware","hook","oldContentTypes","contentTypes","getService","actions","repairPermissionsForNewlyLocalizedTypes","server","router","use","ctx","next","method","validateLocaleCreation","isLocalizedContentType","Object","values","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"],"mappings":";;;;;;;;;;;;;AASA,eAAe,CAAA,OAAO,EAAEA,MAAM,EAA2B,GAAA;AACvDA,IAAAA,MAAAA,CAAOC,YAAY,CAACC,QAAQ,CAACC,uCAAAA,CAA2BH,MAAAA,CAAAA,CAAAA;AACxDA,IAAAA,MAAAA,CAAOI,GAAG,CAAC,QAAA,CAAA,CAAUC,GAAG,CAACC,mCAAAA,CAAAA;IAEzBC,kBAAAA,CAAmBP,MAAAA,CAAAA;IACnBQ,iCAAAA,CAAkCR,MAAAA,CAAAA;AAElCA,IAAAA,MAAAA,CACGS,IAAI,CAAC,iCAAA,CAAA,CACLP,QAAQ,CAAC,CAAC,EAAEQ,eAAe,EAAEC,YAAY,EAAO,GAC/CC,gBAAAA,CAAW,eAAeC,OAAO,CAACC,uCAAuC,CAAC;AACxEJ,YAAAA,eAAAA;AACAC,YAAAA;AACF,SAAA,CAAA,CAAA;AAEN,CAAA;AAEA;AACA;;;IAIA,MAAMH,oCAAoC,CAACR,MAAAA,GAAAA;IACzCA,MAAAA,CAAOe,MAAM,CAACC,MAAM,CAACC,GAAG,CAAC,0CAAA,EAA4C,CAACC,GAAAA,EAAKC,IAAAA,GAAAA;AACzE,QAAA,IAAID,IAAIE,MAAM,KAAK,UAAUF,GAAAA,CAAIE,MAAM,KAAK,KAAA,EAAO;AACjD,YAAA,OAAOC,uBAAuBH,GAAAA,EAAKC,IAAAA,CAAAA;AACrC,QAAA;QAEA,OAAOA,IAAAA,EAAAA;AACT,IAAA,CAAA,CAAA;IAEAnB,MAAAA,CAAOe,MAAM,CAACC,MAAM,CAACC,GAAG,CAAC,sCAAA,EAAwC,CAACC,GAAAA,EAAKC,IAAAA,GAAAA;AACrE,QAAA,IAAID,IAAIE,MAAM,KAAK,UAAUF,GAAAA,CAAI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AAAA,CAAG,EAAEC,OAAO,EAAsB,EAAA;oBAChC,OAAO;wBACLC,EAAAA,EAAI;AACFC,4BAAAA,MAAAA,EAAQF,QAAQG,GAAG,CAAC,CAACC,CAAAA,GAAMA,EAAEH,EAAE;AACjC;AACF,qBAAA;AACF,gBAAA;AACF;AACF,SAAA,CAAA;AACF,IAAA,CAAA,CAAA;IAEA,IAAInD,MAAAA,CAAOuD,MAAM,CAAC,SAAA,CAAA,EAAY;;QAE5BC,OAAAA,CAAgB;AAAExD,YAAAA;AAAO,SAAA,CAAA,CAAGE,QAAQ,EAAA;AACtC,IAAA;AACF,CAAA;;;;"}
|
package/dist/server/register.mjs
CHANGED
|
@@ -3,8 +3,10 @@ import validateLocaleCreation from './controllers/validate-locale-creation.mjs';
|
|
|
3
3
|
import graphqlProvider from './graphql.mjs';
|
|
4
4
|
import { getService } from './utils/index.mjs';
|
|
5
5
|
import { aiLocalizationJob } from './models/ai-localization-job.mjs';
|
|
6
|
+
import { createLocalizationProvider } from './localization.mjs';
|
|
6
7
|
|
|
7
8
|
var register = (async ({ strapi })=>{
|
|
9
|
+
strapi.localization.register(createLocalizationProvider(strapi));
|
|
8
10
|
strapi.get('models').add(aiLocalizationJob);
|
|
9
11
|
extendContentTypes(strapi);
|
|
10
12
|
addContentManagerLocaleMiddleware(strapi);
|
|
@@ -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';\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 strapi\n .hook('strapi::content-types.afterSync')\n .register(({ oldContentTypes, contentTypes }: any) =>\n getService('permissions').actions.repairPermissionsForNewlyLocalizedTypes({\n oldContentTypes,\n contentTypes,\n })\n );\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","hook","
|
|
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';\nimport { createLocalizationProvider } from './localization';\n\nexport default async ({ strapi }: { strapi: Core.Strapi }) => {\n strapi.localization.register(createLocalizationProvider(strapi));\n strapi.get('models').add(aiLocalizationJob);\n\n extendContentTypes(strapi);\n addContentManagerLocaleMiddleware(strapi);\n\n strapi\n .hook('strapi::content-types.afterSync')\n .register(({ oldContentTypes, contentTypes }: any) =>\n getService('permissions').actions.repairPermissionsForNewlyLocalizedTypes({\n oldContentTypes,\n contentTypes,\n })\n );\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","localization","register","createLocalizationProvider","get","add","aiLocalizationJob","extendContentTypes","addContentManagerLocaleMiddleware","hook","oldContentTypes","contentTypes","getService","actions","repairPermissionsForNewlyLocalizedTypes","server","router","use","ctx","next","method","validateLocaleCreation","isLocalizedContentType","Object","values","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"],"mappings":";;;;;;;AASA,eAAe,CAAA,OAAO,EAAEA,MAAM,EAA2B,GAAA;AACvDA,IAAAA,MAAAA,CAAOC,YAAY,CAACC,QAAQ,CAACC,0BAAAA,CAA2BH,MAAAA,CAAAA,CAAAA;AACxDA,IAAAA,MAAAA,CAAOI,GAAG,CAAC,QAAA,CAAA,CAAUC,GAAG,CAACC,iBAAAA,CAAAA;IAEzBC,kBAAAA,CAAmBP,MAAAA,CAAAA;IACnBQ,iCAAAA,CAAkCR,MAAAA,CAAAA;AAElCA,IAAAA,MAAAA,CACGS,IAAI,CAAC,iCAAA,CAAA,CACLP,QAAQ,CAAC,CAAC,EAAEQ,eAAe,EAAEC,YAAY,EAAO,GAC/CC,UAAAA,CAAW,eAAeC,OAAO,CAACC,uCAAuC,CAAC;AACxEJ,YAAAA,eAAAA;AACAC,YAAAA;AACF,SAAA,CAAA,CAAA;AAEN,CAAA;AAEA;AACA;;;IAIA,MAAMH,oCAAoC,CAACR,MAAAA,GAAAA;IACzCA,MAAAA,CAAOe,MAAM,CAACC,MAAM,CAACC,GAA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C,QAAAA,EAAU,WAAA;AACVC,YAAAA,MAAAA,EAAQX,YAAYY,GAAG;YACvBP,QAAAA,EAAU,KAAA;AACVC,YAAAA,OAAAA,EAAS,CAACJ,WAAAA;YACVK,YAAAA,EAAc,KAAA;YACdC,OAAAA,EAAS,KAAA;YACTK,gBAAAA,EAAkB,IAAA;YAClBC,UAAAA,EAAY;gBACVC,IAAAA,EAAM,aAAA;gBACNC,gBAAAA,EAAkB,aAAA;gBAClBC,eAAAA,EAAiB3C,MAAAA,CAAO4C,EAAE,CAACC,QAAQ,CAACC,WAAW,CAACC,YAAY,CAACrB,WAAAA,CAAYsB,cAAc,CAAA;;gBAEvFC,EAAAA,CAAAA,CAAG,EAAEC,OAAO,EAAsB,EAAA;oBAChC,OAAO;wBACLC,EAAAA,EAAI;AACFC,4BAAAA,MAAAA,EAAQF,QAAQG,GAAG,CAAC,CAACC,CAAAA,GAAMA,EAAEH,EAAE;AACjC;AACF,qBAAA;AACF,gBAAA;AACF;AACF,SAAA,CAAA;AACF,IAAA,CAAA,CAAA;IAEA,IAAInD,MAAAA,CAAOuD,MAAM,CAAC,SAAA,CAAA,EAAY;;QAE5BC,eAAAA,CAAgB;AAAExD,YAAAA;AAAO,SAAA,CAAA,CAAGE,QAAQ,EAAA;AACtC,IAAA;AACF,CAAA;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const createStrapiManagedAiTranslationsProvider = ({ strapi })=>{
|
|
4
|
-
// TODO: add a helper function to get the AI server URL
|
|
4
|
+
// TODO(ai): add a helper function to get the AI server URL
|
|
5
5
|
const aiServerUrl = process.env.STRAPI_AI_URL || 'https://strapi-ai.apps.strapi.io';
|
|
6
6
|
const getAiToken = async ()=>{
|
|
7
7
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-translations-strapi-managed.js","sources":["../../../server/src/services/ai-translations-strapi-managed.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nimport type { AiTranslationsProvider } from './ai-translations';\n\nconst createStrapiManagedAiTranslationsProvider = ({\n strapi,\n}: {\n strapi: Core.Strapi;\n}): AiTranslationsProvider => {\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 const getAiToken = async () => {\n try {\n const { token } = await strapi.ai.admin.getAiToken();\n return token;\n } catch (error) {\n throw new Error('Failed to retrieve AI token', {\n cause: error instanceof Error ? error : undefined,\n });\n }\n };\n\n return {\n name: 'strapi-managed',\n\n async generateTranslations({ sourceLocale, targetLocales, content, contentTypeSchema }) {\n const token = await getAiToken();\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,\n sourceLocale,\n targetLocales,\n contentTypeSchema,\n }),\n });\n\n if (!response.ok) {\n strapi.log.error(\n `AI Localizations request failed: ${response.status} ${response.statusText}`\n );\n\n throw new Error(`AI Localizations request failed: ${response.statusText}`);\n }\n\n return (await response.json()) as Awaited<\n ReturnType<AiTranslationsProvider['generateTranslations']>\n >;\n },\n };\n};\n\nexport { createStrapiManagedAiTranslationsProvider };\n"],"names":["createStrapiManagedAiTranslationsProvider","strapi","aiServerUrl","process","env","STRAPI_AI_URL","getAiToken","token","ai","admin","error","Error","cause","undefined","name","generateTranslations","sourceLocale","targetLocales","content","contentTypeSchema","log","http","response","fetch","method","headers","Authorization","body","JSON","stringify","ok","status","statusText","json"],"mappings":";;AAIA,MAAMA,yCAAAA,GAA4C,CAAC,EACjDC,MAAM,EAGP,GAAA;;AAEC,IAAA,MAAMC,WAAAA,GAAcC,OAAAA,CAAQC,GAAG,CAACC,aAAa,IAAI,kCAAA;AAEjD,IAAA,MAAMC,UAAAA,GAAa,UAAA;QACjB,IAAI;YACF,MAAM,EAAEC,KAAK,E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EA,OAAQ,MAAMV,SAASW,IAAI,EAAA;AAG7B,QAAA;AACF,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"ai-translations-strapi-managed.js","sources":["../../../server/src/services/ai-translations-strapi-managed.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nimport type { AiTranslationsProvider } from './ai-translations';\n\nconst createStrapiManagedAiTranslationsProvider = ({\n strapi,\n}: {\n strapi: Core.Strapi;\n}): AiTranslationsProvider => {\n // TODO(ai): 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 const getAiToken = async () => {\n try {\n const { token } = await strapi.ai.admin.getAiToken();\n return token;\n } catch (error) {\n throw new Error('Failed to retrieve AI token', {\n cause: error instanceof Error ? error : undefined,\n });\n }\n };\n\n return {\n name: 'strapi-managed',\n\n async generateTranslations({ sourceLocale, targetLocales, content, contentTypeSchema }) {\n const token = await getAiToken();\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,\n sourceLocale,\n targetLocales,\n contentTypeSchema,\n }),\n });\n\n if (!response.ok) {\n strapi.log.error(\n `AI Localizations request failed: ${response.status} ${response.statusText}`\n );\n\n throw new Error(`AI Localizations request failed: ${response.statusText}`);\n }\n\n return (await response.json()) as Awaited<\n ReturnType<AiTranslationsProvider['generateTranslations']>\n >;\n },\n };\n};\n\nexport { createStrapiManagedAiTranslationsProvider };\n"],"names":["createStrapiManagedAiTranslationsProvider","strapi","aiServerUrl","process","env","STRAPI_AI_URL","getAiToken","token","ai","admin","error","Error","cause","undefined","name","generateTranslations","sourceLocale","targetLocales","content","contentTypeSchema","log","http","response","fetch","method","headers","Authorization","body","JSON","stringify","ok","status","statusText","json"],"mappings":";;AAIA,MAAMA,yCAAAA,GAA4C,CAAC,EACjDC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AAM,CAAC,CAAC,EAAET,QAAAA,CAASU,UAAU,CAAA,CAAE,CAAA;AAG9E,gBAAA,MAAM,IAAIrB,KAAAA,CAAM,CAAC,iCAAiC,EAAEW,QAAAA,CAASU,UAAU,CAAA,CAAE,CAAA;AAC3E,YAAA;YAEA,OAAQ,MAAMV,SAASW,IAAI,EAAA;AAG7B,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const createStrapiManagedAiTranslationsProvider = ({ strapi })=>{
|
|
2
|
-
// TODO: add a helper function to get the AI server URL
|
|
2
|
+
// TODO(ai): add a helper function to get the AI server URL
|
|
3
3
|
const aiServerUrl = process.env.STRAPI_AI_URL || 'https://strapi-ai.apps.strapi.io';
|
|
4
4
|
const getAiToken = async ()=>{
|
|
5
5
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-translations-strapi-managed.mjs","sources":["../../../server/src/services/ai-translations-strapi-managed.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nimport type { AiTranslationsProvider } from './ai-translations';\n\nconst createStrapiManagedAiTranslationsProvider = ({\n strapi,\n}: {\n strapi: Core.Strapi;\n}): AiTranslationsProvider => {\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 const getAiToken = async () => {\n try {\n const { token } = await strapi.ai.admin.getAiToken();\n return token;\n } catch (error) {\n throw new Error('Failed to retrieve AI token', {\n cause: error instanceof Error ? error : undefined,\n });\n }\n };\n\n return {\n name: 'strapi-managed',\n\n async generateTranslations({ sourceLocale, targetLocales, content, contentTypeSchema }) {\n const token = await getAiToken();\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,\n sourceLocale,\n targetLocales,\n contentTypeSchema,\n }),\n });\n\n if (!response.ok) {\n strapi.log.error(\n `AI Localizations request failed: ${response.status} ${response.statusText}`\n );\n\n throw new Error(`AI Localizations request failed: ${response.statusText}`);\n }\n\n return (await response.json()) as Awaited<\n ReturnType<AiTranslationsProvider['generateTranslations']>\n >;\n },\n };\n};\n\nexport { createStrapiManagedAiTranslationsProvider };\n"],"names":["createStrapiManagedAiTranslationsProvider","strapi","aiServerUrl","process","env","STRAPI_AI_URL","getAiToken","token","ai","admin","error","Error","cause","undefined","name","generateTranslations","sourceLocale","targetLocales","content","contentTypeSchema","log","http","response","fetch","method","headers","Authorization","body","JSON","stringify","ok","status","statusText","json"],"mappings":"AAIA,MAAMA,yCAAAA,GAA4C,CAAC,EACjDC,MAAM,EAGP,GAAA;;AAEC,IAAA,MAAMC,WAAAA,GAAcC,OAAAA,CAAQC,GAAG,CAACC,aAAa,IAAI,kCAAA;AAEjD,IAAA,MAAMC,UAAAA,GAAa,UAAA;QACjB,IAAI;YACF,MAAM,EAAEC,KAAK,EAAE,GAAG,MAAMN,OAAOO,EAAE,CAACC,KAAK,CAACH,UAAU,EAAA;YAClD,OAAOC,KAAAA;AACT,QAAA,CAAA,CAAE,OAAOG,KAAAA,EAAO;YACd,MAAM,IAAIC,MAAM,6BAAA,EAA+B;gBAC7CC,KAAAA,EAAOF,KAAAA,YAAiBC,QAAQD,KAAAA,GAAQG;AAC1C,aAAA,CAAA;AACF,QAAA;AACF,IAAA,CAAA;IAEA,OAAO;QACLC,IAAAA,EAAM,gBAAA;QAEN,MAAMC,oBAAAA,CAAAA,CAAqB,EAAEC,YAAY,EAAEC,aAAa,EAAEC,OAAO,EAAEC,iBAAiB,EAAE,EAAA;AACpF,YAAA,MAAMZ,QAAQ,MAAMD,UAAAA,EAAAA;YAEpBL,MAAAA,CAAOmB,GAAG,CAACC,IAAI,CAAC,mDAAA,CAAA;AAChB,YAAA,MAAMC,WAAW,MAAMC,KAAAA,CAAM,GAAGrB,WAAAA,CAAY,4BAA4B,CAAC,EAAE;gBACzEsB,MAAAA,EAAQ,MAAA;gBACRC,OAAAA,EAAS;oBACP,cAAA,EAAgB,kBAAA;oBAChBC,aAAAA,EAAe,CAAC,OAAO,EAAEnB,KAAAA,CAAAA;AAC3B,iBAAA;gBACAoB,IAAAA,EAAMC,IAAAA,CAAKC,SAAS,CAAC;AACnBX,oBAAAA,OAAAA;AACAF,oBAAAA,YAAAA;AACAC,oBAAAA,aAAAA;AACAE,oBAAAA;AACF,iBAAA;AACF,aAAA,CAAA;YAEA,IAAI,CAACG,QAAAA,CAASQ,EAAE,EAAE;AAChB7B,gBAAAA,MAAAA,CAAOmB,GAAG,CAACV,KAAK,CACd,CAAC,iCAAiC,EAAEY,QAAAA,CAASS,MAAM,CAAC,CAAC,EAAET,QAAAA,CAASU,UAAU,CAAA,CAAE,CAAA;AAG9E,gBAAA,MAAM,IAAIrB,KAAAA,CAAM,CAAC,iCAAiC,EAAEW,QAAAA,CAASU,UAAU,CAAA,CAAE,CAAA;AAC3E,YAAA;YAEA,OAAQ,MAAMV,SAASW,IAAI,EAAA;AAG7B,QAAA;AACF,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"ai-translations-strapi-managed.mjs","sources":["../../../server/src/services/ai-translations-strapi-managed.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nimport type { AiTranslationsProvider } from './ai-translations';\n\nconst createStrapiManagedAiTranslationsProvider = ({\n strapi,\n}: {\n strapi: Core.Strapi;\n}): AiTranslationsProvider => {\n // TODO(ai): 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 const getAiToken = async () => {\n try {\n const { token } = await strapi.ai.admin.getAiToken();\n return token;\n } catch (error) {\n throw new Error('Failed to retrieve AI token', {\n cause: error instanceof Error ? error : undefined,\n });\n }\n };\n\n return {\n name: 'strapi-managed',\n\n async generateTranslations({ sourceLocale, targetLocales, content, contentTypeSchema }) {\n const token = await getAiToken();\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,\n sourceLocale,\n targetLocales,\n contentTypeSchema,\n }),\n });\n\n if (!response.ok) {\n strapi.log.error(\n `AI Localizations request failed: ${response.status} ${response.statusText}`\n );\n\n throw new Error(`AI Localizations request failed: ${response.statusText}`);\n }\n\n return (await response.json()) as Awaited<\n ReturnType<AiTranslationsProvider['generateTranslations']>\n >;\n },\n };\n};\n\nexport { createStrapiManagedAiTranslationsProvider };\n"],"names":["createStrapiManagedAiTranslationsProvider","strapi","aiServerUrl","process","env","STRAPI_AI_URL","getAiToken","token","ai","admin","error","Error","cause","undefined","name","generateTranslations","sourceLocale","targetLocales","content","contentTypeSchema","log","http","response","fetch","method","headers","Authorization","body","JSON","stringify","ok","status","statusText","json"],"mappings":"AAIA,MAAMA,yCAAAA,GAA4C,CAAC,EACjDC,MAAM,EAGP,GAAA;;AAEC,IAAA,MAAMC,WAAAA,GAAcC,OAAAA,CAAQC,GAAG,CAACC,aAAa,IAAI,kCAAA;AAEjD,IAAA,MAAMC,UAAAA,GAAa,UAAA;QACjB,IAAI;YACF,MAAM,EAAEC,KAAK,EAAE,GAAG,MAAMN,OAAOO,EAAE,CAACC,KAAK,CAACH,UAAU,EAAA;YAClD,OAAOC,KAAAA;AACT,QAAA,CAAA,CAAE,OAAOG,KAAAA,EAAO;YACd,MAAM,IAAIC,MAAM,6BAAA,EAA+B;gBAC7CC,KAAAA,EAAOF,KAAAA,YAAiBC,QAAQD,KAAAA,GAAQG;AAC1C,aAAA,CAAA;AACF,QAAA;AACF,IAAA,CAAA;IAEA,OAAO;QACLC,IAAAA,EAAM,gBAAA;QAEN,MAAMC,oBAAAA,CAAAA,CAAqB,EAAEC,YAAY,EAAEC,aAAa,EAAEC,OAAO,EAAEC,iBAAiB,EAAE,EAAA;AACpF,YAAA,MAAMZ,QAAQ,MAAMD,UAAAA,EAAAA;YAEpBL,MAAAA,CAAOmB,GAAG,CAACC,IAAI,CAAC,mDAAA,CAAA;AAChB,YAAA,MAAMC,WAAW,MAAMC,KAAAA,CAAM,GAAGrB,WAAAA,CAAY,4BAA4B,CAAC,EAAE;gBACzEsB,MAAAA,EAAQ,MAAA;gBACRC,OAAAA,EAAS;oBACP,cAAA,EAAgB,kBAAA;oBAChBC,aAAAA,EAAe,CAAC,OAAO,EAAEnB,KAAAA,CAAAA;AAC3B,iBAAA;gBACAoB,IAAAA,EAAMC,IAAAA,CAAKC,SAAS,CAAC;AACnBX,oBAAAA,OAAAA;AACAF,oBAAAA,YAAAA;AACAC,oBAAAA,aAAAA;AACAE,oBAAAA;AACF,iBAAA;AACF,aAAA,CAAA;YAEA,IAAI,CAACG,QAAAA,CAASQ,EAAE,EAAE;AAChB7B,gBAAAA,MAAAA,CAAOmB,GAAG,CAACV,KAAK,CACd,CAAC,iCAAiC,EAAEY,QAAAA,CAASS,MAAM,CAAC,CAAC,EAAET,QAAAA,CAASU,UAAU,CAAA,CAAE,CAAA;AAG9E,gBAAA,MAAM,IAAIrB,KAAAA,CAAM,CAAC,iCAAiC,EAAEW,QAAAA,CAASU,UAAU,CAAA,CAAE,CAAA;AAC3E,YAAA;YAEA,OAAQ,MAAMV,SAASW,IAAI,EAAA;AAG7B,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var aiTranslationsStrapiManaged = require('./ai-translations-strapi-managed.js');
|
|
4
4
|
|
|
5
|
+
// This service mirrors upload's ai-metadata-provider service on purpose. Keep the two in
|
|
6
|
+
// sync, and only extract the shared logic once a third feature needs it.
|
|
5
7
|
const createAITranslationsService = ({ strapi })=>{
|
|
6
8
|
let registeredProvider = null;
|
|
7
9
|
const resolveProvider = ()=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-translations.js","sources":["../../../server/src/services/ai-translations.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\nimport { createStrapiManagedAiTranslationsProvider } from './ai-translations-strapi-managed';\n\nexport type GenerateTranslationsParams = {\n sourceLocale: string;\n targetLocales: string[];\n content: Record<string, unknown>;\n contentTypeSchema: Record<string, Record<string, unknown>>;\n};\n\nexport type GenerateTranslationsResult = {\n localizations: Array<{ content: Record<string, unknown>; locale: string }>;\n};\n\nexport type AiTranslationsProvider = Modules.AI.AiProvider & {\n generateTranslations: (params: GenerateTranslationsParams) => Promise<GenerateTranslationsResult>;\n};\n\nexport interface AiTranslationsService {\n hasProvider(): boolean;\n registerProvider(params: { provider: AiTranslationsProvider }): void;\n registerStrapiManagedProvider(): void;\n generateTranslations(params: GenerateTranslationsParams): Promise<GenerateTranslationsResult>;\n}\n\nconst createAITranslationsService = ({\n strapi,\n}: {\n strapi: Core.Strapi;\n}): AiTranslationsService => {\n let registeredProvider: AiTranslationsProvider | null = null;\n\n const resolveProvider = (): AiTranslationsProvider | null => {\n if (!strapi.ai.admin.isAvailable()) {\n return null;\n }\n\n return registeredProvider;\n };\n\n return {\n hasProvider(): boolean {\n return resolveProvider() !== null;\n },\n\n registerProvider({ provider }: { provider: AiTranslationsProvider }) {\n if (!strapi.ai.admin.authorizeCustomProvider()) {\n return;\n }\n\n if (registeredProvider !== null) {\n throw new Error(\n `The AI translations provider \"${registeredProvider.name}\" is already registered, \"${provider.name}\" cannot replace it.`\n );\n }\n\n registeredProvider = provider;\n },\n\n registerStrapiManagedProvider() {\n if (!strapi.ai.admin.isStrapiManagedAiEnabled()) {\n strapi.log.warn(\n 'The Strapi-managed AI translations provider was ignored: the Strapi license does not include the \"cms-ai\" feature.'\n );\n return;\n }\n\n const provider = createStrapiManagedAiTranslationsProvider({ strapi });\n\n if (registeredProvider !== null) {\n throw new Error(\n `The AI translations provider \"${registeredProvider.name}\" is already registered, \"${provider.name}\" cannot replace it.`\n );\n }\n\n registeredProvider = provider;\n },\n\n async generateTranslations(\n params: GenerateTranslationsParams\n ): Promise<GenerateTranslationsResult> {\n const provider = resolveProvider();\n\n if (provider === null) {\n throw new Error('No AI translations provider is registered.');\n }\n\n return provider.generateTranslations(params);\n },\n };\n};\n\nexport { createAITranslationsService };\n"],"names":["createAITranslationsService","strapi","registeredProvider","resolveProvider","ai","admin","isAvailable","hasProvider","registerProvider","provider","authorizeCustomProvider","Error","name","registerStrapiManagedProvider","isStrapiManagedAiEnabled","log","warn","createStrapiManagedAiTranslationsProvider","generateTranslations","params"],"mappings":";;;;AAyBA,MAAMA,2BAAAA,GAA8B,CAAC,EACnCC,MAAM,EAGP,GAAA;AACC,IAAA,IAAIC,kBAAAA,GAAoD,IAAA;AAExD,IAAA,MAAMC,eAAAA,GAAkB,IAAA;AACtB,QAAA,IAAI,CAACF,MAAAA,CAAOG,EAAE,CAACC,KAAK,CAACC,WAAW,EAAA,EAAI;YAClC,OAAO,IAAA;AACT,QAAA;QAEA,OAAOJ,kBAAAA;AACT,IAAA,CAAA;IAEA,OAAO;AACLK,QAAAA,WAAAA,CAAAA,GAAAA;AACE,YAAA,OAAOJ,eAAAA,EAAAA,KAAsB,IAAA;AAC/B,QAAA,CAAA;QAEAK,gBAAAA,CAAAA,CAAiB,EAAEC,QAAQ,EAAwC,EAAA;AACjE,YAAA,IAAI,CAACR,MAAAA,CAAOG,EAAE,CAACC,KAAK,CAACK,uBAAuB,EAAA,EAAI;AAC9C,gBAAA;AACF,YAAA;AAEA,YAAA,IAAIR,uBAAuB,IAAA,EAAM;AAC/B,gBAAA,MAAM,IAAIS,KAAAA,CACR,CAAC,8BAA8B,EAAET,kBAAAA,CAAmBU,IAAI,CAAC,0BAA0B,EAAEH,QAAAA,CAASG,IAAI,CAAC,oBAAoB,CAAC,CAAA;AAE5H,YAAA;YAEAV,kBAAAA,GAAqBO,QAAAA;AACvB,QAAA,CAAA;AAEAI,QAAAA,6BAAAA,CAAAA,GAAAA;AACE,YAAA,IAAI,CAACZ,MAAAA,CAAOG,EAAE,CAACC,KAAK,CAACS,wBAAwB,EAAA,EAAI;gBAC/Cb,MAAAA,CAAOc,GAAG,CAACC,IAAI,CACb,oHAAA,CAAA;AAEF,gBAAA;AACF,YAAA;AAEA,YAAA,MAAMP,WAAWQ,qEAAAA,CAA0C;AAAEhB,gBAAAA;AAAO,aAAA,CAAA;AAEpE,YAAA,IAAIC,uBAAuB,IAAA,EAAM;AAC/B,gBAAA,MAAM,IAAIS,KAAAA,CACR,CAAC,8BAA8B,EAAET,kBAAAA,CAAmBU,IAAI,CAAC,0BAA0B,EAAEH,QAAAA,CAASG,IAAI,CAAC,oBAAoB,CAAC,CAAA;AAE5H,YAAA;YAEAV,kBAAAA,GAAqBO,QAAAA;AACvB,QAAA,CAAA;AAEA,QAAA,MAAMS,sBACJC,MAAkC,EAAA;AAElC,YAAA,MAAMV,QAAAA,GAAWN,eAAAA,EAAAA;AAEjB,YAAA,IAAIM,aAAa,IAAA,EAAM;AACrB,gBAAA,MAAM,IAAIE,KAAAA,CAAM,4CAAA,CAAA;AAClB,YAAA;YAEA,OAAOF,QAAAA,CAASS,oBAAoB,CAACC,MAAAA,CAAAA;AACvC,QAAA;AACF,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"ai-translations.js","sources":["../../../server/src/services/ai-translations.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\nimport { createStrapiManagedAiTranslationsProvider } from './ai-translations-strapi-managed';\n\nexport type GenerateTranslationsParams = {\n sourceLocale: string;\n targetLocales: string[];\n content: Record<string, unknown>;\n contentTypeSchema: Record<string, Record<string, unknown>>;\n};\n\nexport type GenerateTranslationsResult = {\n localizations: Array<{ content: Record<string, unknown>; locale: string }>;\n};\n\nexport type AiTranslationsProvider = Modules.AI.AiProvider & {\n generateTranslations: (params: GenerateTranslationsParams) => Promise<GenerateTranslationsResult>;\n};\n\nexport interface AiTranslationsService {\n hasProvider(): boolean;\n registerProvider(params: { provider: AiTranslationsProvider }): void;\n registerStrapiManagedProvider(): void;\n generateTranslations(params: GenerateTranslationsParams): Promise<GenerateTranslationsResult>;\n}\n\n// This service mirrors upload's ai-metadata-provider service on purpose. Keep the two in\n// sync, and only extract the shared logic once a third feature needs it.\nconst createAITranslationsService = ({\n strapi,\n}: {\n strapi: Core.Strapi;\n}): AiTranslationsService => {\n let registeredProvider: AiTranslationsProvider | null = null;\n\n const resolveProvider = (): AiTranslationsProvider | null => {\n if (!strapi.ai.admin.isAvailable()) {\n return null;\n }\n\n return registeredProvider;\n };\n\n return {\n hasProvider(): boolean {\n return resolveProvider() !== null;\n },\n\n registerProvider({ provider }: { provider: AiTranslationsProvider }) {\n if (!strapi.ai.admin.authorizeCustomProvider()) {\n return;\n }\n\n if (registeredProvider !== null) {\n throw new Error(\n `The AI translations provider \"${registeredProvider.name}\" is already registered, \"${provider.name}\" cannot replace it.`\n );\n }\n\n registeredProvider = provider;\n },\n\n registerStrapiManagedProvider() {\n if (!strapi.ai.admin.isStrapiManagedAiEnabled()) {\n strapi.log.warn(\n 'The Strapi-managed AI translations provider was ignored: the Strapi license does not include the \"cms-ai\" feature.'\n );\n return;\n }\n\n const provider = createStrapiManagedAiTranslationsProvider({ strapi });\n\n if (registeredProvider !== null) {\n throw new Error(\n `The AI translations provider \"${registeredProvider.name}\" is already registered, \"${provider.name}\" cannot replace it.`\n );\n }\n\n registeredProvider = provider;\n },\n\n async generateTranslations(\n params: GenerateTranslationsParams\n ): Promise<GenerateTranslationsResult> {\n const provider = resolveProvider();\n\n if (provider === null) {\n throw new Error('No AI translations provider is registered.');\n }\n\n return provider.generateTranslations(params);\n },\n };\n};\n\nexport { createAITranslationsService };\n"],"names":["createAITranslationsService","strapi","registeredProvider","resolveProvider","ai","admin","isAvailable","hasProvider","registerProvider","provider","authorizeCustomProvider","Error","name","registerStrapiManagedProvider","isStrapiManagedAiEnabled","log","warn","createStrapiManagedAiTranslationsProvider","generateTranslations","params"],"mappings":";;;;AAyBA;AACA;AACA,MAAMA,2BAAAA,GAA8B,C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,IAAI,CAAC,oBAAoB,CAAC,CAAA;AAE5H,YAAA;YAEAV,kBAAAA,GAAqBO,QAAAA;AACvB,QAAA,CAAA;AAEA,QAAA,MAAMS,sBACJC,MAAkC,EAAA;AAElC,YAAA,MAAMV,QAAAA,GAAWN,eAAAA,EAAAA;AAEjB,YAAA,IAAIM,aAAa,IAAA,EAAM;AACrB,gBAAA,MAAM,IAAIE,KAAAA,CAAM,4CAAA,CAAA;AAClB,YAAA;YAEA,OAAOF,QAAAA,CAASS,oBAAoB,CAACC,MAAAA,CAAAA;AACvC,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createStrapiManagedAiTranslationsProvider } from './ai-translations-strapi-managed.mjs';
|
|
2
2
|
|
|
3
|
+
// This service mirrors upload's ai-metadata-provider service on purpose. Keep the two in
|
|
4
|
+
// sync, and only extract the shared logic once a third feature needs it.
|
|
3
5
|
const createAITranslationsService = ({ strapi })=>{
|
|
4
6
|
let registeredProvider = null;
|
|
5
7
|
const resolveProvider = ()=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-translations.mjs","sources":["../../../server/src/services/ai-translations.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\nimport { createStrapiManagedAiTranslationsProvider } from './ai-translations-strapi-managed';\n\nexport type GenerateTranslationsParams = {\n sourceLocale: string;\n targetLocales: string[];\n content: Record<string, unknown>;\n contentTypeSchema: Record<string, Record<string, unknown>>;\n};\n\nexport type GenerateTranslationsResult = {\n localizations: Array<{ content: Record<string, unknown>; locale: string }>;\n};\n\nexport type AiTranslationsProvider = Modules.AI.AiProvider & {\n generateTranslations: (params: GenerateTranslationsParams) => Promise<GenerateTranslationsResult>;\n};\n\nexport interface AiTranslationsService {\n hasProvider(): boolean;\n registerProvider(params: { provider: AiTranslationsProvider }): void;\n registerStrapiManagedProvider(): void;\n generateTranslations(params: GenerateTranslationsParams): Promise<GenerateTranslationsResult>;\n}\n\nconst createAITranslationsService = ({\n strapi,\n}: {\n strapi: Core.Strapi;\n}): AiTranslationsService => {\n let registeredProvider: AiTranslationsProvider | null = null;\n\n const resolveProvider = (): AiTranslationsProvider | null => {\n if (!strapi.ai.admin.isAvailable()) {\n return null;\n }\n\n return registeredProvider;\n };\n\n return {\n hasProvider(): boolean {\n return resolveProvider() !== null;\n },\n\n registerProvider({ provider }: { provider: AiTranslationsProvider }) {\n if (!strapi.ai.admin.authorizeCustomProvider()) {\n return;\n }\n\n if (registeredProvider !== null) {\n throw new Error(\n `The AI translations provider \"${registeredProvider.name}\" is already registered, \"${provider.name}\" cannot replace it.`\n );\n }\n\n registeredProvider = provider;\n },\n\n registerStrapiManagedProvider() {\n if (!strapi.ai.admin.isStrapiManagedAiEnabled()) {\n strapi.log.warn(\n 'The Strapi-managed AI translations provider was ignored: the Strapi license does not include the \"cms-ai\" feature.'\n );\n return;\n }\n\n const provider = createStrapiManagedAiTranslationsProvider({ strapi });\n\n if (registeredProvider !== null) {\n throw new Error(\n `The AI translations provider \"${registeredProvider.name}\" is already registered, \"${provider.name}\" cannot replace it.`\n );\n }\n\n registeredProvider = provider;\n },\n\n async generateTranslations(\n params: GenerateTranslationsParams\n ): Promise<GenerateTranslationsResult> {\n const provider = resolveProvider();\n\n if (provider === null) {\n throw new Error('No AI translations provider is registered.');\n }\n\n return provider.generateTranslations(params);\n },\n };\n};\n\nexport { createAITranslationsService };\n"],"names":["createAITranslationsService","strapi","registeredProvider","resolveProvider","ai","admin","isAvailable","hasProvider","registerProvider","provider","authorizeCustomProvider","Error","name","registerStrapiManagedProvider","isStrapiManagedAiEnabled","log","warn","createStrapiManagedAiTranslationsProvider","generateTranslations","params"],"mappings":";;AAyBA,MAAMA,2BAAAA,GAA8B,CAAC,EACnCC,MAAM,EAGP,GAAA;AACC,IAAA,IAAIC,kBAAAA,GAAoD,IAAA;AAExD,IAAA,MAAMC,eAAAA,GAAkB,IAAA;AACtB,QAAA,IAAI,CAACF,MAAAA,CA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AAA,MAAMV,QAAAA,GAAWN,eAAAA,EAAAA;AAEjB,YAAA,IAAIM,aAAa,IAAA,EAAM;AACrB,gBAAA,MAAM,IAAIE,KAAAA,CAAM,4CAAA,CAAA;AAClB,YAAA;YAEA,OAAOF,QAAAA,CAASS,oBAAoB,CAACC,MAAAA,CAAAA;AACvC,QAAA;AACF,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"ai-translations.mjs","sources":["../../../server/src/services/ai-translations.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\nimport { createStrapiManagedAiTranslationsProvider } from './ai-translations-strapi-managed';\n\nexport type GenerateTranslationsParams = {\n sourceLocale: string;\n targetLocales: string[];\n content: Record<string, unknown>;\n contentTypeSchema: Record<string, Record<string, unknown>>;\n};\n\nexport type GenerateTranslationsResult = {\n localizations: Array<{ content: Record<string, unknown>; locale: string }>;\n};\n\nexport type AiTranslationsProvider = Modules.AI.AiProvider & {\n generateTranslations: (params: GenerateTranslationsParams) => Promise<GenerateTranslationsResult>;\n};\n\nexport interface AiTranslationsService {\n hasProvider(): boolean;\n registerProvider(params: { provider: AiTranslationsProvider }): void;\n registerStrapiManagedProvider(): void;\n generateTranslations(params: GenerateTranslationsParams): Promise<GenerateTranslationsResult>;\n}\n\n// This service mirrors upload's ai-metadata-provider service on purpose. Keep the two in\n// sync, and only extract the shared logic once a third feature needs it.\nconst createAITranslationsService = ({\n strapi,\n}: {\n strapi: Core.Strapi;\n}): AiTranslationsService => {\n let registeredProvider: AiTranslationsProvider | null = null;\n\n const resolveProvider = (): AiTranslationsProvider | null => {\n if (!strapi.ai.admin.isAvailable()) {\n return null;\n }\n\n return registeredProvider;\n };\n\n return {\n hasProvider(): boolean {\n return resolveProvider() !== null;\n },\n\n registerProvider({ provider }: { provider: AiTranslationsProvider }) {\n if (!strapi.ai.admin.authorizeCustomProvider()) {\n return;\n }\n\n if (registeredProvider !== null) {\n throw new Error(\n `The AI translations provider \"${registeredProvider.name}\" is already registered, \"${provider.name}\" cannot replace it.`\n );\n }\n\n registeredProvider = provider;\n },\n\n registerStrapiManagedProvider() {\n if (!strapi.ai.admin.isStrapiManagedAiEnabled()) {\n strapi.log.warn(\n 'The Strapi-managed AI translations provider was ignored: the Strapi license does not include the \"cms-ai\" feature.'\n );\n return;\n }\n\n const provider = createStrapiManagedAiTranslationsProvider({ strapi });\n\n if (registeredProvider !== null) {\n throw new Error(\n `The AI translations provider \"${registeredProvider.name}\" is already registered, \"${provider.name}\" cannot replace it.`\n );\n }\n\n registeredProvider = provider;\n },\n\n async generateTranslations(\n params: GenerateTranslationsParams\n ): Promise<GenerateTranslationsResult> {\n const provider = resolveProvider();\n\n if (provider === null) {\n throw new Error('No AI translations provider is registered.');\n }\n\n return provider.generateTranslations(params);\n },\n };\n};\n\nexport { createAITranslationsService };\n"],"names":["createAITranslationsService","strapi","registeredProvider","resolveProvider","ai","admin","isAvailable","hasProvider","registerProvider","provider","authorizeCustomProvider","Error","name","registerStrapiManagedProvider","isStrapiManagedAiEnabled","log","warn","createStrapiManagedAiTranslationsProvider","generateTranslations","params"],"mappings":";;AAyBA;AACA;AACA,MAAMA,2BAAAA,GAA8B,CAAC,EACnCC,MAAM,EAGP,GAAA;AACC,IAAA,IAAIC,kBAAAA,GAAoD,IAAA;AAExD,IAAA,MAAMC,eAAAA,GAAkB,IAAA;AACtB,QAAA,IAAI,CAACF,MAAAA,CAAOG,EAAE,CAACC,KAAK,CAACC,WAAW,EAAA,EAAI;YAClC,OAAO,IAAA;AACT,QAAA;QAEA,OAAOJ,kBAAAA;AACT,IAAA,CAAA;IAEA,OAAO;AACLK,QAAAA,WAAAA,CAAAA,GAAAA;AACE,YAAA,OAAOJ,eAAAA,EAAAA,KAAsB,IAAA;AAC/B,QAAA,CAAA;QAEAK,gBAAAA,CAAAA,CAAiB,EAAEC,QAAQ,EAAwC,EAAA;AACjE,YAAA,IAAI,CAACR,MAAAA,CAAOG,EAAE,CAACC,KAAK,CAACK,uBAAuB,EAAA,EAAI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