@strapi/i18n 5.29.0 → 5.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/dist/admin/components/BulkLocaleActionModal.js.map +1 -1
  2. package/dist/admin/components/BulkLocaleActionModal.mjs.map +1 -1
  3. package/dist/admin/components/CMHeaderActions.js +145 -13
  4. package/dist/admin/components/CMHeaderActions.js.map +1 -1
  5. package/dist/admin/components/CMHeaderActions.mjs +148 -16
  6. package/dist/admin/components/CMHeaderActions.mjs.map +1 -1
  7. package/dist/admin/components/CreateLocale.js +2 -3
  8. package/dist/admin/components/CreateLocale.js.map +1 -1
  9. package/dist/admin/components/CreateLocale.mjs +3 -4
  10. package/dist/admin/components/CreateLocale.mjs.map +1 -1
  11. package/dist/admin/components/LocaleListCell.js.map +1 -1
  12. package/dist/admin/components/LocaleListCell.mjs.map +1 -1
  13. package/dist/admin/contentManagerHooks/editView.js.map +1 -1
  14. package/dist/admin/contentManagerHooks/editView.mjs.map +1 -1
  15. package/dist/admin/hooks/useAILocalizationJobsPolling.js +110 -0
  16. package/dist/admin/hooks/useAILocalizationJobsPolling.js.map +1 -0
  17. package/dist/admin/hooks/useAILocalizationJobsPolling.mjs +89 -0
  18. package/dist/admin/hooks/useAILocalizationJobsPolling.mjs.map +1 -0
  19. package/dist/admin/hooks/useI18n.js +4 -4
  20. package/dist/admin/hooks/useI18n.js.map +1 -1
  21. package/dist/admin/hooks/useI18n.mjs +4 -4
  22. package/dist/admin/hooks/useI18n.mjs.map +1 -1
  23. package/dist/admin/pages/SettingsPage.js +1 -1
  24. package/dist/admin/pages/SettingsPage.js.map +1 -1
  25. package/dist/admin/pages/SettingsPage.mjs +1 -1
  26. package/dist/admin/pages/SettingsPage.mjs.map +1 -1
  27. package/dist/admin/services/aiLocalizationJobs.js +26 -0
  28. package/dist/admin/services/aiLocalizationJobs.js.map +1 -0
  29. package/dist/admin/services/aiLocalizationJobs.mjs +24 -0
  30. package/dist/admin/services/aiLocalizationJobs.mjs.map +1 -0
  31. package/dist/admin/services/api.js +2 -1
  32. package/dist/admin/services/api.js.map +1 -1
  33. package/dist/admin/services/api.mjs +2 -1
  34. package/dist/admin/services/api.mjs.map +1 -1
  35. package/dist/admin/services/locales.js.map +1 -1
  36. package/dist/admin/services/locales.mjs.map +1 -1
  37. package/dist/admin/services/settings.js +2 -1
  38. package/dist/admin/services/settings.js.map +1 -1
  39. package/dist/admin/services/settings.mjs +2 -1
  40. package/dist/admin/services/settings.mjs.map +1 -1
  41. package/dist/admin/src/components/CMHeaderActions.d.ts +12 -5
  42. package/dist/admin/src/hooks/useAILocalizationJobsPolling.d.ts +9 -0
  43. package/dist/admin/src/services/aiLocalizationJobs.d.ts +6 -0
  44. package/dist/admin/src/services/api.d.ts +1 -1
  45. package/dist/admin/src/services/locales.d.ts +1 -1
  46. package/dist/admin/src/services/relations.d.ts +1 -1
  47. package/dist/admin/src/services/settings.d.ts +2 -2
  48. package/dist/admin/translations/en.json.js +4 -1
  49. package/dist/admin/translations/en.json.js.map +1 -1
  50. package/dist/admin/translations/en.json.mjs +4 -1
  51. package/dist/admin/translations/en.json.mjs.map +1 -1
  52. package/dist/admin/utils/getTranslation.js.map +1 -1
  53. package/dist/admin/utils/getTranslation.mjs.map +1 -1
  54. package/dist/admin/utils/prefixPluginTranslations.js.map +1 -1
  55. package/dist/admin/utils/prefixPluginTranslations.mjs.map +1 -1
  56. package/dist/server/bootstrap.js +2 -0
  57. package/dist/server/bootstrap.js.map +1 -1
  58. package/dist/server/bootstrap.mjs +2 -0
  59. package/dist/server/bootstrap.mjs.map +1 -1
  60. package/dist/server/controllers/ai-localization-jobs.js +47 -0
  61. package/dist/server/controllers/ai-localization-jobs.js.map +1 -0
  62. package/dist/server/controllers/ai-localization-jobs.mjs +45 -0
  63. package/dist/server/controllers/ai-localization-jobs.mjs.map +1 -0
  64. package/dist/server/controllers/index.js +3 -1
  65. package/dist/server/controllers/index.js.map +1 -1
  66. package/dist/server/controllers/index.mjs +3 -1
  67. package/dist/server/controllers/index.mjs.map +1 -1
  68. package/dist/server/models/ai-localization-job.js +60 -0
  69. package/dist/server/models/ai-localization-job.js.map +1 -0
  70. package/dist/server/models/ai-localization-job.mjs +57 -0
  71. package/dist/server/models/ai-localization-job.mjs.map +1 -0
  72. package/dist/server/register.js +3 -1
  73. package/dist/server/register.js.map +1 -1
  74. package/dist/server/register.mjs +3 -1
  75. package/dist/server/register.mjs.map +1 -1
  76. package/dist/server/routes/admin.js +20 -0
  77. package/dist/server/routes/admin.js.map +1 -1
  78. package/dist/server/routes/admin.mjs +20 -0
  79. package/dist/server/routes/admin.mjs.map +1 -1
  80. package/dist/server/services/ai-localization-jobs.js +64 -0
  81. package/dist/server/services/ai-localization-jobs.js.map +1 -0
  82. package/dist/server/services/ai-localization-jobs.mjs +62 -0
  83. package/dist/server/services/ai-localization-jobs.mjs.map +1 -0
  84. package/dist/server/services/ai-localizations.js +245 -5
  85. package/dist/server/services/ai-localizations.js.map +1 -1
  86. package/dist/server/services/ai-localizations.mjs +245 -5
  87. package/dist/server/services/ai-localizations.mjs.map +1 -1
  88. package/dist/server/services/content-types.js.map +1 -1
  89. package/dist/server/services/content-types.mjs.map +1 -1
  90. package/dist/server/services/index.js +3 -1
  91. package/dist/server/services/index.js.map +1 -1
  92. package/dist/server/services/index.mjs +3 -1
  93. package/dist/server/services/index.mjs.map +1 -1
  94. package/dist/server/src/bootstrap.d.ts.map +1 -1
  95. package/dist/server/src/controllers/ai-localization-jobs.d.ts +17 -0
  96. package/dist/server/src/controllers/ai-localization-jobs.d.ts.map +1 -0
  97. package/dist/server/src/controllers/index.d.ts +6 -0
  98. package/dist/server/src/controllers/index.d.ts.map +1 -1
  99. package/dist/server/src/index.d.ts +26 -2
  100. package/dist/server/src/index.d.ts.map +1 -1
  101. package/dist/server/src/models/ai-localization-job.d.ts +5 -0
  102. package/dist/server/src/models/ai-localization-job.d.ts.map +1 -0
  103. package/dist/server/src/models/index.d.ts +5 -0
  104. package/dist/server/src/models/index.d.ts.map +1 -0
  105. package/dist/server/src/register.d.ts +1 -1
  106. package/dist/server/src/register.d.ts.map +1 -1
  107. package/dist/server/src/routes/admin.d.ts.map +1 -1
  108. package/dist/server/src/services/ai-localization-jobs.d.ts +26 -0
  109. package/dist/server/src/services/ai-localization-jobs.d.ts.map +1 -0
  110. package/dist/server/src/services/ai-localizations.d.ts +11 -1
  111. package/dist/server/src/services/ai-localizations.d.ts.map +1 -1
  112. package/dist/server/src/services/index.d.ts +19 -1
  113. package/dist/server/src/services/index.d.ts.map +1 -1
  114. package/dist/server/src/utils/index.d.ts +4 -0
  115. package/dist/server/src/utils/index.d.ts.map +1 -1
  116. package/dist/server/utils/index.js.map +1 -1
  117. package/dist/server/utils/index.mjs.map +1 -1
  118. package/dist/shared/contracts/ai-localization-jobs.d.ts +27 -0
  119. package/dist/shared/contracts/ai-localization-jobs.d.ts.map +1 -0
  120. package/dist/shared/contracts/shared.d.ts.map +1 -0
  121. package/package.json +7 -6
@@ -1,12 +1,29 @@
1
+ import { traverseEntity } from '@strapi/utils';
2
+ import { getService } from '../utils/index.mjs';
3
+
4
+ const isLocalizedAttribute = (attribute)=>{
5
+ return attribute?.pluginOptions?.i18n?.localized === true;
6
+ };
1
7
  const createAILocalizationsService = ({ strapi })=>{
8
+ // TODO: add a helper function to get the AI server URL
9
+ const aiServerUrl = process.env.STRAPI_AI_URL || 'https://strapi-ai.apps.strapi.io';
10
+ const aiLocalizationJobsService = getService('ai-localization-jobs');
11
+ const UNSUPPORTED_ATTRIBUTE_TYPES = [
12
+ 'media',
13
+ 'relation',
14
+ 'boolean'
15
+ ];
16
+ const IGNORED_FIELDS = [
17
+ 'id',
18
+ 'documentId',
19
+ 'createdAt',
20
+ 'updatedAt',
21
+ 'updatedBy',
22
+ 'localizations'
23
+ ];
2
24
  return {
3
25
  // Async to avoid changing the signature later (there will be a db check in the future)
4
26
  async isEnabled () {
5
- // Check if future flag is enabled
6
- const isFutureFlagEnabled = strapi.features.future.isEnabled('unstableAILocalizations');
7
- if (!isFutureFlagEnabled) {
8
- return false;
9
- }
10
27
  // Check if user disabled AI features globally
11
28
  const isAIEnabled = strapi.config.get('admin.ai.enabled', true);
12
29
  if (!isAIEnabled) {
@@ -17,7 +34,230 @@ const createAILocalizationsService = ({ strapi })=>{
17
34
  if (!hasAccess) {
18
35
  return false;
19
36
  }
37
+ const settings = getService('settings');
38
+ const aiSettings = await settings.getSettings();
39
+ if (!aiSettings?.aiLocalizations) {
40
+ return false;
41
+ }
20
42
  return true;
43
+ },
44
+ /**
45
+ * Checks if there are localizations that need to be generated for the given document,
46
+ * and if so, calls the AI service and saves the results to the database.
47
+ * Works for both single and collection types, on create and update.
48
+ */ async generateDocumentLocalizations ({ model, document }) {
49
+ const isFeatureEnabled = await this.isEnabled();
50
+ if (!isFeatureEnabled) {
51
+ return;
52
+ }
53
+ const schema = strapi.getModel(model);
54
+ const localeService = getService('locales');
55
+ // No localizations needed for content types with i18n disabled
56
+ const isLocalizedContentType = getService('content-types').isLocalizedContentType(schema);
57
+ if (!isLocalizedContentType) {
58
+ return;
59
+ }
60
+ // Don't trigger localizations if the update is on a derived locale, only do it on the default
61
+ const defaultLocale = await localeService.getDefaultLocale();
62
+ if (document?.locale !== defaultLocale) {
63
+ return;
64
+ }
65
+ const documentId = document.documentId;
66
+ if (!documentId) {
67
+ strapi.log.warn(`AI Localizations: missing documentId for ${schema.uid}`);
68
+ return;
69
+ }
70
+ const localizedRoots = new Set();
71
+ const translateableContent = await traverseEntity(({ key, attribute, parent, path }, { remove })=>{
72
+ if (IGNORED_FIELDS.includes(key)) {
73
+ remove(key);
74
+ return;
75
+ }
76
+ const hasLocalizedOption = attribute && isLocalizedAttribute(attribute);
77
+ if (attribute && UNSUPPORTED_ATTRIBUTE_TYPES.includes(attribute.type)) {
78
+ remove(key);
79
+ return;
80
+ }
81
+ // If this field is localized, keep it (and mark as localized root if component/dz)
82
+ if (hasLocalizedOption) {
83
+ // If it's a component/dynamiczone, add to the set
84
+ if ([
85
+ 'component',
86
+ 'dynamiczone'
87
+ ].includes(attribute.type)) {
88
+ localizedRoots.add(path.raw);
89
+ }
90
+ return; // keep
91
+ }
92
+ if (parent && localizedRoots.has(parent.path.raw)) {
93
+ // If parent exists in the localized roots set, keep it
94
+ // If this is also a component/dz, propagate the localized root flag
95
+ if ([
96
+ 'component',
97
+ 'dynamiczone'
98
+ ].includes(attribute?.type ?? '')) {
99
+ localizedRoots.add(path.raw);
100
+ }
101
+ return; // keep
102
+ }
103
+ // Otherwise, remove the field
104
+ remove(key);
105
+ }, {
106
+ schema,
107
+ getModel: strapi.getModel.bind(strapi)
108
+ }, document);
109
+ if (Object.keys(translateableContent).length === 0) {
110
+ strapi.log.info(`AI Localizations: no translatable content for ${schema.uid} document ${documentId}`);
111
+ return;
112
+ }
113
+ const localesList = await localeService.find();
114
+ const targetLocales = localesList.filter((l)=>l.code !== document.locale).map((l)=>l.code);
115
+ if (targetLocales.length === 0) {
116
+ strapi.log.info(`AI Localizations: no target locales for ${schema.uid} document ${documentId}`);
117
+ return;
118
+ }
119
+ await aiLocalizationJobsService.upsertJobForDocument({
120
+ contentType: model,
121
+ documentId,
122
+ sourceLocale: document.locale,
123
+ targetLocales,
124
+ status: 'processing'
125
+ });
126
+ let token;
127
+ try {
128
+ const tokenData = await strapi.service('admin::user').getAiToken();
129
+ token = tokenData.token;
130
+ } catch (error) {
131
+ await aiLocalizationJobsService.upsertJobForDocument({
132
+ documentId,
133
+ contentType: model,
134
+ sourceLocale: document.locale,
135
+ targetLocales,
136
+ status: 'failed'
137
+ });
138
+ throw new Error('Failed to retrieve AI token', {
139
+ cause: error instanceof Error ? error : undefined
140
+ });
141
+ }
142
+ /**
143
+ * Provide a schema to the LLM so that we can give it instructions about how to handle each
144
+ * type of attribute. Only keep essential schema data to avoid cluttering the context.
145
+ * Ignore fields that don't need to be localized.
146
+ * TODO: also provide a schema of all the referenced components
147
+ */ const minimalContentTypeSchema = Object.fromEntries(Object.entries(schema.attributes)// eslint-disable-next-line @typescript-eslint/no-unused-vars
148
+ .filter(([_, attr])=>{
149
+ const isLocalized = isLocalizedAttribute(attr);
150
+ const isSupportedType = !UNSUPPORTED_ATTRIBUTE_TYPES.includes(attr.type);
151
+ return isLocalized && isSupportedType;
152
+ }).map(([key, attr])=>{
153
+ const minimalAttribute = {
154
+ type: attr.type
155
+ };
156
+ if (attr.type === 'component') {
157
+ minimalAttribute.repeatable = attr.repeatable ?? false;
158
+ }
159
+ return [
160
+ key,
161
+ minimalAttribute
162
+ ];
163
+ }));
164
+ strapi.log.http('Contacting AI Server for localizations generation');
165
+ const response = await fetch(`${aiServerUrl}/i18n/generate-localizations`, {
166
+ method: 'POST',
167
+ headers: {
168
+ 'Content-Type': 'application/json',
169
+ Authorization: `Bearer ${token}`
170
+ },
171
+ body: JSON.stringify({
172
+ content: translateableContent,
173
+ sourceLocale: document.locale,
174
+ targetLocales,
175
+ contentTypeSchema: minimalContentTypeSchema
176
+ })
177
+ });
178
+ if (!response.ok) {
179
+ strapi.log.error(`AI Localizations request failed: ${response.status} ${response.statusText}`);
180
+ await aiLocalizationJobsService.upsertJobForDocument({
181
+ documentId,
182
+ contentType: model,
183
+ sourceLocale: document.locale,
184
+ targetLocales,
185
+ status: 'failed'
186
+ });
187
+ throw new Error(`AI Localizations request failed: ${response.statusText}`);
188
+ }
189
+ const aiResult = await response.json();
190
+ // Get all media field names dynamically from the schema
191
+ const mediaFields = Object.entries(schema.attributes)// eslint-disable-next-line @typescript-eslint/no-unused-vars
192
+ .filter(([_, attr])=>attr.type === 'media').map(([key])=>key);
193
+ try {
194
+ await Promise.all(aiResult.localizations.map(async (localization)=>{
195
+ const { content, locale } = localization;
196
+ // Fetch the derived locale document
197
+ const derivedDoc = await strapi.documents(model).findOne({
198
+ documentId,
199
+ locale,
200
+ populate: mediaFields
201
+ });
202
+ // Merge AI content and media fields, works only on first level media fields (root level)
203
+ const mergedData = structuredClone(content);
204
+ for (const field of mediaFields){
205
+ // Only copy media if not already set in derived locale
206
+ if (!derivedDoc || !derivedDoc[field]) {
207
+ mergedData[field] = document[field];
208
+ } else {
209
+ mergedData[field] = derivedDoc[field];
210
+ }
211
+ }
212
+ await strapi.documents(model).update({
213
+ documentId,
214
+ locale,
215
+ fields: [],
216
+ data: mergedData
217
+ });
218
+ await aiLocalizationJobsService.upsertJobForDocument({
219
+ documentId,
220
+ contentType: model,
221
+ sourceLocale: document.locale,
222
+ targetLocales,
223
+ status: 'completed'
224
+ });
225
+ }));
226
+ } catch (error) {
227
+ await aiLocalizationJobsService.upsertJobForDocument({
228
+ documentId,
229
+ contentType: model,
230
+ sourceLocale: document.locale,
231
+ targetLocales,
232
+ status: 'failed'
233
+ });
234
+ strapi.log.error('AI Localizations generation failed', error);
235
+ }
236
+ },
237
+ setupMiddleware () {
238
+ strapi.documents.use(async (context, next)=>{
239
+ const result = await next();
240
+ // Only trigger for the allowed actions
241
+ if (![
242
+ 'create',
243
+ 'update'
244
+ ].includes(context.action)) {
245
+ return result;
246
+ }
247
+ // Check if AI localizations are enabled before triggering
248
+ const isEnabled = await this.isEnabled();
249
+ if (!isEnabled) {
250
+ return result;
251
+ }
252
+ // Don't await since localizations should be done in the background without blocking the request
253
+ strapi.plugin('i18n').service('ai-localizations').generateDocumentLocalizations({
254
+ model: context.contentType.uid,
255
+ document: result
256
+ }).catch((error)=>{
257
+ strapi.log.error('AI Localizations generation failed', error);
258
+ });
259
+ return result;
260
+ });
21
261
  }
22
262
  };
23
263
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ai-localizations.mjs","sources":["../../../server/src/services/ai-localizations.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nconst createAILocalizationsService = ({ strapi }: { strapi: Core.Strapi }) => {\n return {\n // Async to avoid changing the signature later (there will be a db check in the future)\n async isEnabled() {\n // Check if future flag is enabled\n const isFutureFlagEnabled = strapi.features.future.isEnabled('unstableAILocalizations');\n if (!isFutureFlagEnabled) {\n return false;\n }\n\n // Check if user disabled AI features globally\n const isAIEnabled = strapi.config.get('admin.ai.enabled', true);\n if (!isAIEnabled) {\n return false;\n }\n\n // Check if the user's license grants access to AI features\n const hasAccess = strapi.ee.features.isEnabled('cms-ai');\n if (!hasAccess) {\n return false;\n }\n\n return true;\n },\n };\n};\n\nexport { createAILocalizationsService };\n"],"names":["createAILocalizationsService","strapi","isEnabled","isFutureFlagEnabled","features","future","isAIEnabled","config","get","hasAccess","ee"],"mappings":"AAEA,MAAMA,4BAA+B,GAAA,CAAC,EAAEC,MAAM,EAA2B,GAAA;IACvE,OAAO;;QAEL,MAAMC,SAAAA,CAAAA,GAAAA;;AAEJ,YAAA,MAAMC,sBAAsBF,MAAOG,CAAAA,QAAQ,CAACC,MAAM,CAACH,SAAS,CAAC,yBAAA,CAAA;AAC7D,YAAA,IAAI,CAACC,mBAAqB,EAAA;gBACxB,OAAO,KAAA;AACT;;AAGA,YAAA,MAAMG,cAAcL,MAAOM,CAAAA,MAAM,CAACC,GAAG,CAAC,kBAAoB,EAAA,IAAA,CAAA;AAC1D,YAAA,IAAI,CAACF,WAAa,EAAA;gBAChB,OAAO,KAAA;AACT;;AAGA,YAAA,MAAMG,YAAYR,MAAOS,CAAAA,EAAE,CAACN,QAAQ,CAACF,SAAS,CAAC,QAAA,CAAA;AAC/C,YAAA,IAAI,CAACO,SAAW,EAAA;gBACd,OAAO,KAAA;AACT;YAEA,OAAO,IAAA;AACT;AACF,KAAA;AACF;;;;"}
1
+ {"version":3,"file":"ai-localizations.mjs","sources":["../../../server/src/services/ai-localizations.ts"],"sourcesContent":["import type { Core, Modules, Schema, UID } from '@strapi/types';\nimport { traverseEntity } from '@strapi/utils';\nimport { getService } from '../utils';\n\nconst isLocalizedAttribute = (attribute: Schema.Attribute.Attribute | undefined): boolean => {\n return (attribute?.pluginOptions as any)?.i18n?.localized === true;\n};\n\nconst createAILocalizationsService = ({ strapi }: { strapi: Core.Strapi }) => {\n // TODO: add a helper function to get the AI server URL\n const aiServerUrl = process.env.STRAPI_AI_URL || 'https://strapi-ai.apps.strapi.io';\n const aiLocalizationJobsService = getService('ai-localization-jobs');\n\n const UNSUPPORTED_ATTRIBUTE_TYPES: Schema.Attribute.Kind[] = ['media', 'relation', 'boolean'];\n const IGNORED_FIELDS = [\n 'id',\n 'documentId',\n 'createdAt',\n 'updatedAt',\n 'updatedBy',\n 'localizations',\n ];\n\n return {\n // Async to avoid changing the signature later (there will be a db check in the future)\n async isEnabled() {\n // Check if user disabled AI features globally\n const isAIEnabled = strapi.config.get('admin.ai.enabled', true);\n if (!isAIEnabled) {\n return false;\n }\n\n // Check if the user's license grants access to AI features\n const hasAccess = strapi.ee.features.isEnabled('cms-ai');\n if (!hasAccess) {\n return false;\n }\n\n const settings = getService('settings');\n const aiSettings = await settings.getSettings();\n if (!aiSettings?.aiLocalizations) {\n return false;\n }\n\n return true;\n },\n\n /**\n * Checks if there are localizations that need to be generated for the given document,\n * and if so, calls the AI service and saves the results to the database.\n * Works for both single and collection types, on create and update.\n */\n async generateDocumentLocalizations({\n model,\n document,\n }: {\n model: UID.ContentType;\n document: Modules.Documents.AnyDocument;\n }) {\n const isFeatureEnabled = await this.isEnabled();\n if (!isFeatureEnabled) {\n return;\n }\n\n const schema = strapi.getModel(model);\n const localeService = getService('locales');\n\n // No localizations needed for content types with i18n disabled\n const isLocalizedContentType = getService('content-types').isLocalizedContentType(schema);\n if (!isLocalizedContentType) {\n return;\n }\n\n // Don't trigger localizations if the update is on a derived locale, only do it on the default\n const defaultLocale = await localeService.getDefaultLocale();\n if (document?.locale !== defaultLocale) {\n return;\n }\n\n const documentId = document.documentId;\n\n if (!documentId) {\n strapi.log.warn(`AI Localizations: missing documentId for ${schema.uid}`);\n return;\n }\n\n const localizedRoots = new Set();\n\n const translateableContent = await traverseEntity(\n ({ key, attribute, parent, path }, { remove }) => {\n if (IGNORED_FIELDS.includes(key)) {\n remove(key);\n return;\n }\n const hasLocalizedOption = attribute && isLocalizedAttribute(attribute);\n if (attribute && UNSUPPORTED_ATTRIBUTE_TYPES.includes(attribute.type)) {\n remove(key);\n return;\n }\n\n // If this field is localized, keep it (and mark as localized root if component/dz)\n if (hasLocalizedOption) {\n // If it's a component/dynamiczone, add to the set\n if (['component', 'dynamiczone'].includes(attribute.type)) {\n localizedRoots.add(path.raw);\n }\n return; // keep\n }\n\n if (parent && localizedRoots.has(parent.path.raw)) {\n // If parent exists in the localized roots set, keep it\n // If this is also a component/dz, propagate the localized root flag\n if (['component', 'dynamiczone'].includes(attribute?.type ?? '')) {\n localizedRoots.add(path.raw);\n }\n return; // keep\n }\n\n // Otherwise, remove the field\n remove(key);\n },\n { schema, getModel: strapi.getModel.bind(strapi) },\n document\n );\n\n if (Object.keys(translateableContent).length === 0) {\n strapi.log.info(\n `AI Localizations: no translatable content for ${schema.uid} document ${documentId}`\n );\n return;\n }\n\n const localesList = await localeService.find();\n const targetLocales = localesList\n .filter((l) => l.code !== document.locale)\n .map((l) => l.code);\n\n if (targetLocales.length === 0) {\n strapi.log.info(\n `AI Localizations: no target locales for ${schema.uid} document ${documentId}`\n );\n return;\n }\n\n await aiLocalizationJobsService.upsertJobForDocument({\n contentType: model,\n documentId,\n sourceLocale: document.locale,\n targetLocales,\n status: 'processing',\n });\n\n let token: string;\n try {\n const tokenData = await strapi.service('admin::user').getAiToken();\n token = tokenData.token;\n } catch (error) {\n await aiLocalizationJobsService.upsertJobForDocument({\n documentId,\n contentType: model,\n sourceLocale: document.locale,\n targetLocales,\n status: 'failed',\n });\n\n throw new Error('Failed to retrieve AI token', {\n cause: error instanceof Error ? error : undefined,\n });\n }\n\n /**\n * Provide a schema to the LLM so that we can give it instructions about how to handle each\n * type of attribute. Only keep essential schema data to avoid cluttering the context.\n * Ignore fields that don't need to be localized.\n * TODO: also provide a schema of all the referenced components\n */\n const minimalContentTypeSchema = Object.fromEntries(\n Object.entries(schema.attributes)\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n .filter(([_, attr]) => {\n const isLocalized = isLocalizedAttribute(attr);\n const isSupportedType = !UNSUPPORTED_ATTRIBUTE_TYPES.includes(attr.type);\n return isLocalized && isSupportedType;\n })\n .map(([key, attr]) => {\n const minimalAttribute = { type: attr.type };\n if (attr.type === 'component') {\n (\n minimalAttribute as Schema.Attribute.Component<`${string}.${string}`, boolean>\n ).repeatable = attr.repeatable ?? false;\n }\n return [key, minimalAttribute];\n })\n );\n\n strapi.log.http('Contacting AI Server for localizations generation');\n const response = await fetch(`${aiServerUrl}/i18n/generate-localizations`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${token}`,\n },\n body: JSON.stringify({\n content: translateableContent,\n sourceLocale: document.locale,\n targetLocales,\n contentTypeSchema: minimalContentTypeSchema,\n }),\n });\n\n if (!response.ok) {\n strapi.log.error(\n `AI Localizations request failed: ${response.status} ${response.statusText}`\n );\n\n await aiLocalizationJobsService.upsertJobForDocument({\n documentId,\n contentType: model,\n sourceLocale: document.locale,\n targetLocales,\n status: 'failed',\n });\n\n throw new Error(`AI Localizations request failed: ${response.statusText}`);\n }\n\n const aiResult = await response.json();\n // Get all media field names dynamically from the schema\n const mediaFields = Object.entries(schema.attributes)\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n .filter(([_, attr]) => attr.type === 'media')\n .map(([key]) => key);\n\n try {\n await Promise.all(\n aiResult.localizations.map(async (localization: any) => {\n const { content, locale } = localization;\n\n // Fetch the derived locale document\n const derivedDoc = await strapi.documents(model).findOne({\n documentId,\n locale,\n populate: mediaFields,\n });\n\n // Merge AI content and media fields, works only on first level media fields (root level)\n const mergedData = structuredClone(content);\n for (const field of mediaFields) {\n // Only copy media if not already set in derived locale\n if (!derivedDoc || !derivedDoc[field]) {\n mergedData[field] = document[field];\n } else {\n mergedData[field] = derivedDoc[field];\n }\n }\n\n await strapi.documents(model).update({\n documentId,\n locale,\n fields: [],\n data: mergedData,\n });\n\n await aiLocalizationJobsService.upsertJobForDocument({\n documentId,\n contentType: model,\n sourceLocale: document.locale,\n targetLocales,\n status: 'completed',\n });\n })\n );\n } catch (error) {\n await aiLocalizationJobsService.upsertJobForDocument({\n documentId,\n contentType: model,\n sourceLocale: document.locale,\n targetLocales,\n status: 'failed',\n });\n strapi.log.error('AI Localizations generation failed', error);\n }\n },\n setupMiddleware() {\n strapi.documents.use(async (context, next) => {\n const result = await next();\n\n // Only trigger for the allowed actions\n if (!['create', 'update'].includes(context.action)) {\n return result;\n }\n\n // Check if AI localizations are enabled before triggering\n const isEnabled = await this.isEnabled();\n if (!isEnabled) {\n return result;\n }\n\n // Don't await since localizations should be done in the background without blocking the request\n strapi\n .plugin('i18n')\n .service('ai-localizations')\n .generateDocumentLocalizations({\n model: context.contentType.uid,\n document: result,\n })\n .catch((error: any) => {\n strapi.log.error('AI Localizations generation failed', error);\n });\n\n return result;\n });\n },\n };\n};\n\nexport { createAILocalizationsService };\n"],"names":["isLocalizedAttribute","attribute","pluginOptions","i18n","localized","createAILocalizationsService","strapi","aiServerUrl","process","env","STRAPI_AI_URL","aiLocalizationJobsService","getService","UNSUPPORTED_ATTRIBUTE_TYPES","IGNORED_FIELDS","isEnabled","isAIEnabled","config","get","hasAccess","ee","features","settings","aiSettings","getSettings","aiLocalizations","generateDocumentLocalizations","model","document","isFeatureEnabled","schema","getModel","localeService","isLocalizedContentType","defaultLocale","getDefaultLocale","locale","documentId","log","warn","uid","localizedRoots","Set","translateableContent","traverseEntity","key","parent","path","remove","includes","hasLocalizedOption","type","add","raw","has","bind","Object","keys","length","info","localesList","find","targetLocales","filter","l","code","map","upsertJobForDocument","contentType","sourceLocale","status","token","tokenData","service","getAiToken","error","Error","cause","undefined","minimalContentTypeSchema","fromEntries","entries","attributes","_","attr","isLocalized","isSupportedType","minimalAttribute","repeatable","http","response","fetch","method","headers","Authorization","body","JSON","stringify","content","contentTypeSchema","ok","statusText","aiResult","json","mediaFields","Promise","all","localizations","localization","derivedDoc","documents","findOne","populate","mergedData","structuredClone","field","update","fields","data","setupMiddleware","use","context","next","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D,OAAOD,MAAAA;AACT;;AAGA,gBAAA,MAAM5G,SAAY,GAAA,MAAM,IAAI,CAACA,SAAS,EAAA;AACtC,gBAAA,IAAI,CAACA,SAAW,EAAA;oBACd,OAAO4G,MAAAA;AACT;;AAGArH,gBAAAA,MAAAA,CACGuH,MAAM,CAAC,MAAA,CAAA,CACPpD,OAAO,CAAC,kBAAA,CAAA,CACR/C,6BAA6B,CAAC;oBAC7BC,KAAO8F,EAAAA,OAAAA,CAAQrD,WAAW,CAAC5B,GAAG;oBAC9BZ,QAAU+F,EAAAA;iBAEXG,CAAAA,CAAAA,KAAK,CAAC,CAACnD,KAAAA,GAAAA;AACNrE,oBAAAA,MAAAA,CAAOgC,GAAG,CAACqC,KAAK,CAAC,oCAAsCA,EAAAA,KAAAA,CAAAA;AACzD,iBAAA,CAAA;gBAEF,OAAOgD,MAAAA;AACT,aAAA,CAAA;AACF;AACF,KAAA;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"content-types.js","sources":["../../../server/src/services/content-types.ts"],"sourcesContent":["import _ from 'lodash';\nimport { pick, pipe, has, prop, isNil, cloneDeep, isArray } from 'lodash/fp';\nimport { errors, contentTypes as contentTypeUtils } from '@strapi/utils';\nimport { getService } from '../utils';\n\nconst {\n isRelationalAttribute,\n getVisibleAttributes,\n isTypedAttribute,\n getScalarAttributes,\n getRelationalAttributes,\n} = contentTypeUtils;\nconst { ApplicationError } = errors;\n\nconst hasLocalizedOption = (modelOrAttribute: any) => {\n return prop('pluginOptions.i18n.localized', modelOrAttribute) === true;\n};\n\nconst getValidLocale = async (locale: any) => {\n const localesService = getService('locales');\n\n if (isNil(locale)) {\n return localesService.getDefaultLocale();\n }\n\n const foundLocale = await localesService.findByCode(locale);\n if (!foundLocale) {\n throw new ApplicationError('Locale not found');\n }\n\n return locale;\n};\n\n/**\n * Returns whether an attribute is localized or not\n * @param {*} attribute\n * @returns\n */\nconst isLocalizedAttribute = (attribute: any) => {\n return (\n hasLocalizedOption(attribute) ||\n isRelationalAttribute(attribute) ||\n isTypedAttribute(attribute, 'uid')\n );\n};\n\n/**\n * Returns whether a model is localized or not\n * @param {*} model\n * @returns\n */\nconst isLocalizedContentType = (model: any) => {\n return hasLocalizedOption(model);\n};\n\n/**\n * Returns the list of attribute names that are not localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getNonLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter(\n (attrName) => !isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\nconst removeId = (value: any) => {\n if (typeof value === 'object' && has('id', value)) {\n delete value.id;\n }\n};\n\nconst removeIds = (model: any) => (entry: any) => removeIdsMut(model, cloneDeep(entry));\n\nconst removeIdsMut = (model: any, entry: any) => {\n if (isNil(entry)) {\n return entry;\n }\n\n removeId(entry);\n\n _.forEach(model.attributes, (attr, attrName) => {\n const value = entry[attrName];\n if (attr.type === 'dynamiczone' && isArray(value)) {\n value.forEach((compo) => {\n if (has('__component', compo)) {\n const model = strapi.components[compo.__component];\n removeIdsMut(model, compo);\n }\n });\n } else if (attr.type === 'component') {\n const model = strapi.components[attr.component];\n if (isArray(value)) {\n value.forEach((compo) => removeIdsMut(model, compo));\n } else {\n removeIdsMut(model, value);\n }\n }\n });\n\n return entry;\n};\n\n/**\n * Returns a copy of an entry picking only its non localized attributes\n * @param {object} model\n * @param {object} entry\n * @returns {object}\n */\nconst copyNonLocalizedAttributes = (model: any, entry: any) => {\n const nonLocalizedAttributes = getNonLocalizedAttributes(model);\n\n return pipe(pick(nonLocalizedAttributes), removeIds(model))(entry);\n};\n\n/**\n * Returns the list of attribute names that are localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter((attrName) =>\n isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\n/**\n * Fill non localized fields of an entry if there are nil\n * @param {Object} entry entry to fill\n * @param {Object} relatedEntry values used to fill\n * @param {Object} options\n * @param {Object} options.model corresponding model\n */\nconst fillNonLocalizedAttributes = (entry: any, relatedEntry: any, { model }: any) => {\n if (isNil(relatedEntry)) {\n return;\n }\n\n const modelDef = strapi.getModel(model);\n const relatedEntryCopy = copyNonLocalizedAttributes(modelDef, relatedEntry);\n\n _.forEach(relatedEntryCopy, (value, field) => {\n if (isNil(entry[field])) {\n entry[field] = value;\n }\n });\n};\n\n/**\n * build the populate param to\n * @param {String} modelUID uid of the model, could be of a content-type or a component\n */\nconst getNestedPopulateOfNonLocalizedAttributes = (modelUID: any) => {\n const schema = strapi.getModel(modelUID);\n const scalarAttributes = getScalarAttributes(schema);\n const nonLocalizedAttributes = getNonLocalizedAttributes(schema);\n\n const allAttributes = [...scalarAttributes, ...nonLocalizedAttributes];\n if (schema.modelType === 'component') {\n // When called recursively on a non localized component we\n // need to explicitly populate that components relations\n allAttributes.push(...getRelationalAttributes(schema));\n }\n\n const currentAttributesToPopulate = allAttributes.filter((value, index, self) => {\n return self.indexOf(value) === index && self.lastIndexOf(value) === index;\n });\n\n const attributesToPopulate = [...currentAttributesToPopulate];\n for (const attrName of currentAttributesToPopulate) {\n const attr = schema.attributes[attrName];\n if (attr.type === 'component') {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(attr.component).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n } else if (attr.type === 'dynamiczone') {\n attr.components.forEach((componentName) => {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(componentName).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n });\n }\n }\n\n return attributesToPopulate;\n};\n\nconst contentTypes = () => ({\n isLocalizedContentType,\n getValidLocale,\n getLocalizedAttributes,\n getNonLocalizedAttributes,\n copyNonLocalizedAttributes,\n fillNonLocalizedAttributes,\n getNestedPopulateOfNonLocalizedAttributes,\n});\n\ntype ContentTypesService = typeof contentTypes;\n\nexport default contentTypes;\nexport { ContentTypesService };\n"],"names":["isRelationalAttribute","getVisibleAttributes","isTypedAttribute","getScalarAttributes","getRelationalAttributes","contentTypeUtils","ApplicationError","errors","hasLocalizedOption","modelOrAttribute","prop","getValidLocale","locale","localesService","getService","isNil","getDefaultLocale","foundLocale","findByCode","isLocalizedAttribute","attribute","isLocalizedContentType","model","getNonLocalizedAttributes","filter","attrName","attributes","removeId","value","has","id","removeIds","entry","removeIdsMut","cloneDeep","_","forEach","attr","type","isArray","compo","strapi","components","__component","component","copyNonLocalizedAttributes","nonLocalizedAttributes","pipe","pick","getLocalizedAttributes","fillNonLocalizedAttributes","relatedEntry","modelDef","getModel","relatedEntryCopy","field","getNestedPopulateOfNonLocalizedAttributes","modelUID","schema","scalarAttributes","allAttributes","modelType","push","currentAttributesToPopulate","index","self","indexOf","lastIndexOf","attributesToPopulate","nestedPopulate","map","nestedAttr","componentName","contentTypes"],"mappings":";;;;;;;AAKA,MAAM,EACJA,qBAAqB,EACrBC,oBAAoB,EACpBC,gBAAgB,EAChBC,mBAAmB,EACnBC,uBAAuB,EACxB,GAAGC,kBAAAA;AACJ,MAAM,EAAEC,gBAAgB,EAAE,GAAGC,YAAAA;AAE7B,MAAMC,qBAAqB,CAACC,gBAAAA,GAAAA;IAC1B,OAAOC,OAAAA,CAAK,gCAAgCD,gBAAsB,CAAA,KAAA,IAAA;AACpE,CAAA;AAEA,MAAME,iBAAiB,OAAOC,MAAAA,GAAAA;AAC5B,IAAA,MAAMC,iBAAiBC,gBAAW,CAAA,SAAA,CAAA;AAElC,IAAA,IAAIC,SAAMH,MAAS,CAAA,EAAA;AACjB,QAAA,OAAOC,eAAeG,gBAAgB,EAAA;AACxC;AAEA,IAAA,MAAMC,WAAc,GAAA,MAAMJ,cAAeK,CAAAA,UAAU,CAACN,MAAAA,CAAAA;AACpD,IAAA,IAAI,CAACK,WAAa,EAAA;AAChB,QAAA,MAAM,IAAIX,gBAAiB,CAAA,kBAAA,CAAA;AAC7B;IAEA,OAAOM,MAAAA;AACT,CAAA;AAEA;;;;IAKA,MA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AA;AACtE,KAAA,CAAA;AAEA,IAAA,MAAMI,oBAAuB,GAAA;AAAIL,QAAAA,GAAAA;AAA4B,KAAA;IAC7D,KAAK,MAAMtC,YAAYsC,2BAA6B,CAAA;AAClD,QAAA,MAAM1B,IAAOqB,GAAAA,MAAAA,CAAOhC,UAAU,CAACD,QAAS,CAAA;QACxC,IAAIY,IAAAA,CAAKC,IAAI,KAAK,WAAa,EAAA;AAC7B,YAAA,MAAM+B,cAAiBb,GAAAA,yCAAAA,CAA0CnB,IAAKO,CAAAA,SAAS,EAAE0B,GAAG,CAClF,CAACC,UAAAA,GAAe,CAAC,EAAE9C,QAAAA,CAAS,CAAC,EAAE8C,WAAW,CAAC,CAAA;AAE7CH,YAAAA,oBAAAA,CAAqBN,IAAI,CAAIO,GAAAA,cAAAA,CAAAA;AAC/B,SAAA,MAAO,IAAIhC,IAAAA,CAAKC,IAAI,KAAK,aAAe,EAAA;AACtCD,YAAAA,IAAAA,CAAKK,UAAU,CAACN,OAAO,CAAC,CAACoC,aAAAA,GAAAA;AACvB,gBAAA,MAAMH,cAAiBb,GAAAA,yCAAAA,CAA0CgB,aAAeF,CAAAA,CAAAA,GAAG,CACjF,CAACC,UAAe,GAAA,CAAC,EAAE9C,QAAAA,CAAS,CAAC,EAAE8C,WAAW,CAAC,CAAA;AAE7CH,gBAAAA,oBAAAA,CAAqBN,IAAI,CAAIO,GAAAA,cAAAA,CAAAA;AAC/B,aAAA,CAAA;AACF;AACF;IAEA,OAAOD,oBAAAA;AACT,CAAA;AAEMK,MAAAA,YAAAA,GAAe,KAAO;AAC1BpD,QAAAA,sBAAAA;AACAV,QAAAA,cAAAA;AACAsC,QAAAA,sBAAAA;AACA1B,QAAAA,yBAAAA;AACAsB,QAAAA,0BAAAA;AACAK,QAAAA,0BAAAA;AACAM,QAAAA;KACF;;;;"}
1
+ {"version":3,"file":"content-types.js","sources":["../../../server/src/services/content-types.ts"],"sourcesContent":["import _ from 'lodash';\nimport { pick, pipe, has, prop, isNil, cloneDeep, isArray } from 'lodash/fp';\nimport { errors, contentTypes as contentTypeUtils } from '@strapi/utils';\nimport { getService } from '../utils';\n\nconst {\n isRelationalAttribute,\n getVisibleAttributes,\n isTypedAttribute,\n getScalarAttributes,\n getRelationalAttributes,\n} = contentTypeUtils;\nconst { ApplicationError } = errors;\n\nconst hasLocalizedOption = (modelOrAttribute: any) => {\n return prop('pluginOptions.i18n.localized', modelOrAttribute) === true;\n};\n\nconst getValidLocale = async (locale: any) => {\n const localesService = getService('locales');\n\n if (isNil(locale)) {\n return localesService.getDefaultLocale();\n }\n\n const foundLocale = await localesService.findByCode(locale);\n if (!foundLocale) {\n throw new ApplicationError('Locale not found');\n }\n\n return locale;\n};\n\n/**\n * Returns whether an attribute is localized or not\n * @param {*} attribute\n * @returns\n */\nconst isLocalizedAttribute = (attribute: any) => {\n return (\n hasLocalizedOption(attribute) ||\n isRelationalAttribute(attribute) ||\n isTypedAttribute(attribute, 'uid')\n );\n};\n\n/**\n * Returns whether a model is localized or not\n * @param {*} model\n * @returns\n */\nconst isLocalizedContentType = (model: any) => {\n return hasLocalizedOption(model);\n};\n\n/**\n * Returns the list of attribute names that are not localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getNonLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter(\n (attrName) => !isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\nconst removeId = (value: any) => {\n if (typeof value === 'object' && has('id', value)) {\n delete value.id;\n }\n};\n\nconst removeIds = (model: any) => (entry: any) => removeIdsMut(model, cloneDeep(entry));\n\nconst removeIdsMut = (model: any, entry: any) => {\n if (isNil(entry)) {\n return entry;\n }\n\n removeId(entry);\n\n _.forEach(model.attributes, (attr, attrName) => {\n const value = entry[attrName];\n if (attr.type === 'dynamiczone' && isArray(value)) {\n value.forEach((compo) => {\n if (has('__component', compo)) {\n const model = strapi.components[compo.__component];\n removeIdsMut(model, compo);\n }\n });\n } else if (attr.type === 'component') {\n const model = strapi.components[attr.component];\n if (isArray(value)) {\n value.forEach((compo) => removeIdsMut(model, compo));\n } else {\n removeIdsMut(model, value);\n }\n }\n });\n\n return entry;\n};\n\n/**\n * Returns a copy of an entry picking only its non localized attributes\n * @param {object} model\n * @param {object} entry\n * @returns {object}\n */\nconst copyNonLocalizedAttributes = (model: any, entry: any) => {\n const nonLocalizedAttributes = getNonLocalizedAttributes(model);\n\n return pipe(pick(nonLocalizedAttributes), removeIds(model))(entry);\n};\n\n/**\n * Returns the list of attribute names that are localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter((attrName) =>\n isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\n/**\n * Fill non localized fields of an entry if there are nil\n * @param {Object} entry entry to fill\n * @param {Object} relatedEntry values used to fill\n * @param {Object} options\n * @param {Object} options.model corresponding model\n */\nconst fillNonLocalizedAttributes = (entry: any, relatedEntry: any, { model }: any) => {\n if (isNil(relatedEntry)) {\n return;\n }\n\n const modelDef = strapi.getModel(model);\n const relatedEntryCopy = copyNonLocalizedAttributes(modelDef, relatedEntry);\n\n _.forEach(relatedEntryCopy, (value, field) => {\n if (isNil(entry[field])) {\n entry[field] = value;\n }\n });\n};\n\n/**\n * build the populate param to\n * @param {String} modelUID uid of the model, could be of a content-type or a component\n */\nconst getNestedPopulateOfNonLocalizedAttributes = (modelUID: any) => {\n const schema = strapi.getModel(modelUID);\n const scalarAttributes = getScalarAttributes(schema);\n const nonLocalizedAttributes = getNonLocalizedAttributes(schema);\n\n const allAttributes = [...scalarAttributes, ...nonLocalizedAttributes];\n if (schema.modelType === 'component') {\n // When called recursively on a non localized component we\n // need to explicitly populate that components relations\n allAttributes.push(...getRelationalAttributes(schema));\n }\n\n const currentAttributesToPopulate = allAttributes.filter((value, index, self) => {\n return self.indexOf(value) === index && self.lastIndexOf(value) === index;\n });\n\n const attributesToPopulate = [...currentAttributesToPopulate];\n for (const attrName of currentAttributesToPopulate) {\n const attr = schema.attributes[attrName];\n if (attr.type === 'component') {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(attr.component).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n } else if (attr.type === 'dynamiczone') {\n attr.components.forEach((componentName) => {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(componentName).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n });\n }\n }\n\n return attributesToPopulate;\n};\n\nconst contentTypes = () => ({\n isLocalizedContentType,\n getValidLocale,\n getLocalizedAttributes,\n getNonLocalizedAttributes,\n copyNonLocalizedAttributes,\n fillNonLocalizedAttributes,\n getNestedPopulateOfNonLocalizedAttributes,\n});\n\ntype ContentTypesService = typeof contentTypes;\n\nexport default contentTypes;\nexport { ContentTypesService };\n"],"names":["isRelationalAttribute","getVisibleAttributes","isTypedAttribute","getScalarAttributes","getRelationalAttributes","contentTypeUtils","ApplicationError","errors","hasLocalizedOption","modelOrAttribute","prop","getValidLocale","locale","localesService","getService","isNil","getDefaultLocale","foundLocale","findByCode","isLocalizedAttribute","attribute","isLocalizedContentType","model","getNonLocalizedAttributes","filter","attrName","attributes","removeId","value","has","id","removeIds","entry","removeIdsMut","cloneDeep","_","forEach","attr","type","isArray","compo","strapi","components","__component","component","copyNonLocalizedAttributes","nonLocalizedAttributes","pipe","pick","getLocalizedAttributes","fillNonLocalizedAttributes","relatedEntry","modelDef","getModel","relatedEntryCopy","field","getNestedPopulateOfNonLocalizedAttributes","modelUID","schema","scalarAttributes","allAttributes","modelType","push","currentAttributesToPopulate","index","self","indexOf","lastIndexOf","attributesToPopulate","nestedPopulate","map","nestedAttr","componentName","contentTypes"],"mappings":";;;;;;;AAKA,MAAM,EACJA,qBAAqB,EACrBC,oBAAoB,EACpBC,gBAAgB,EAChBC,mBAAmB,EACnBC,uBAAuB,EACxB,GAAGC,kBAAAA;AACJ,MAAM,EAAEC,gBAAgB,EAAE,GAAG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yCAA0CgB,CAAAA,aAAAA,CAAAA,CAAeF,GAAG,CACjF,CAACC,UAAAA,GAAe,CAAG9C,EAAAA,QAAAA,CAAS,CAAC,EAAE8C,UAAY,CAAA,CAAA,CAAA;AAE7CH,gBAAAA,oBAAAA,CAAqBN,IAAI,CAAIO,GAAAA,cAAAA,CAAAA;AAC/B,aAAA,CAAA;AACF;AACF;IAEA,OAAOD,oBAAAA;AACT,CAAA;AAEMK,MAAAA,YAAAA,GAAe,KAAO;AAC1BpD,QAAAA,sBAAAA;AACAV,QAAAA,cAAAA;AACAsC,QAAAA,sBAAAA;AACA1B,QAAAA,yBAAAA;AACAsB,QAAAA,0BAAAA;AACAK,QAAAA,0BAAAA;AACAM,QAAAA;KACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"content-types.mjs","sources":["../../../server/src/services/content-types.ts"],"sourcesContent":["import _ from 'lodash';\nimport { pick, pipe, has, prop, isNil, cloneDeep, isArray } from 'lodash/fp';\nimport { errors, contentTypes as contentTypeUtils } from '@strapi/utils';\nimport { getService } from '../utils';\n\nconst {\n isRelationalAttribute,\n getVisibleAttributes,\n isTypedAttribute,\n getScalarAttributes,\n getRelationalAttributes,\n} = contentTypeUtils;\nconst { ApplicationError } = errors;\n\nconst hasLocalizedOption = (modelOrAttribute: any) => {\n return prop('pluginOptions.i18n.localized', modelOrAttribute) === true;\n};\n\nconst getValidLocale = async (locale: any) => {\n const localesService = getService('locales');\n\n if (isNil(locale)) {\n return localesService.getDefaultLocale();\n }\n\n const foundLocale = await localesService.findByCode(locale);\n if (!foundLocale) {\n throw new ApplicationError('Locale not found');\n }\n\n return locale;\n};\n\n/**\n * Returns whether an attribute is localized or not\n * @param {*} attribute\n * @returns\n */\nconst isLocalizedAttribute = (attribute: any) => {\n return (\n hasLocalizedOption(attribute) ||\n isRelationalAttribute(attribute) ||\n isTypedAttribute(attribute, 'uid')\n );\n};\n\n/**\n * Returns whether a model is localized or not\n * @param {*} model\n * @returns\n */\nconst isLocalizedContentType = (model: any) => {\n return hasLocalizedOption(model);\n};\n\n/**\n * Returns the list of attribute names that are not localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getNonLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter(\n (attrName) => !isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\nconst removeId = (value: any) => {\n if (typeof value === 'object' && has('id', value)) {\n delete value.id;\n }\n};\n\nconst removeIds = (model: any) => (entry: any) => removeIdsMut(model, cloneDeep(entry));\n\nconst removeIdsMut = (model: any, entry: any) => {\n if (isNil(entry)) {\n return entry;\n }\n\n removeId(entry);\n\n _.forEach(model.attributes, (attr, attrName) => {\n const value = entry[attrName];\n if (attr.type === 'dynamiczone' && isArray(value)) {\n value.forEach((compo) => {\n if (has('__component', compo)) {\n const model = strapi.components[compo.__component];\n removeIdsMut(model, compo);\n }\n });\n } else if (attr.type === 'component') {\n const model = strapi.components[attr.component];\n if (isArray(value)) {\n value.forEach((compo) => removeIdsMut(model, compo));\n } else {\n removeIdsMut(model, value);\n }\n }\n });\n\n return entry;\n};\n\n/**\n * Returns a copy of an entry picking only its non localized attributes\n * @param {object} model\n * @param {object} entry\n * @returns {object}\n */\nconst copyNonLocalizedAttributes = (model: any, entry: any) => {\n const nonLocalizedAttributes = getNonLocalizedAttributes(model);\n\n return pipe(pick(nonLocalizedAttributes), removeIds(model))(entry);\n};\n\n/**\n * Returns the list of attribute names that are localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter((attrName) =>\n isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\n/**\n * Fill non localized fields of an entry if there are nil\n * @param {Object} entry entry to fill\n * @param {Object} relatedEntry values used to fill\n * @param {Object} options\n * @param {Object} options.model corresponding model\n */\nconst fillNonLocalizedAttributes = (entry: any, relatedEntry: any, { model }: any) => {\n if (isNil(relatedEntry)) {\n return;\n }\n\n const modelDef = strapi.getModel(model);\n const relatedEntryCopy = copyNonLocalizedAttributes(modelDef, relatedEntry);\n\n _.forEach(relatedEntryCopy, (value, field) => {\n if (isNil(entry[field])) {\n entry[field] = value;\n }\n });\n};\n\n/**\n * build the populate param to\n * @param {String} modelUID uid of the model, could be of a content-type or a component\n */\nconst getNestedPopulateOfNonLocalizedAttributes = (modelUID: any) => {\n const schema = strapi.getModel(modelUID);\n const scalarAttributes = getScalarAttributes(schema);\n const nonLocalizedAttributes = getNonLocalizedAttributes(schema);\n\n const allAttributes = [...scalarAttributes, ...nonLocalizedAttributes];\n if (schema.modelType === 'component') {\n // When called recursively on a non localized component we\n // need to explicitly populate that components relations\n allAttributes.push(...getRelationalAttributes(schema));\n }\n\n const currentAttributesToPopulate = allAttributes.filter((value, index, self) => {\n return self.indexOf(value) === index && self.lastIndexOf(value) === index;\n });\n\n const attributesToPopulate = [...currentAttributesToPopulate];\n for (const attrName of currentAttributesToPopulate) {\n const attr = schema.attributes[attrName];\n if (attr.type === 'component') {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(attr.component).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n } else if (attr.type === 'dynamiczone') {\n attr.components.forEach((componentName) => {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(componentName).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n });\n }\n }\n\n return attributesToPopulate;\n};\n\nconst contentTypes = () => ({\n isLocalizedContentType,\n getValidLocale,\n getLocalizedAttributes,\n getNonLocalizedAttributes,\n copyNonLocalizedAttributes,\n fillNonLocalizedAttributes,\n getNestedPopulateOfNonLocalizedAttributes,\n});\n\ntype ContentTypesService = typeof contentTypes;\n\nexport default contentTypes;\nexport { ContentTypesService };\n"],"names":["isRelationalAttribute","getVisibleAttributes","isTypedAttribute","getScalarAttributes","getRelationalAttributes","contentTypeUtils","ApplicationError","errors","hasLocalizedOption","modelOrAttribute","prop","getValidLocale","locale","localesService","getService","isNil","getDefaultLocale","foundLocale","findByCode","isLocalizedAttribute","attribute","isLocalizedContentType","model","getNonLocalizedAttributes","filter","attrName","attributes","removeId","value","has","id","removeIds","entry","removeIdsMut","cloneDeep","_","forEach","attr","type","isArray","compo","strapi","components","__component","component","copyNonLocalizedAttributes","nonLocalizedAttributes","pipe","pick","getLocalizedAttributes","fillNonLocalizedAttributes","relatedEntry","modelDef","getModel","relatedEntryCopy","field","getNestedPopulateOfNonLocalizedAttributes","modelUID","schema","scalarAttributes","allAttributes","modelType","push","currentAttributesToPopulate","index","self","indexOf","lastIndexOf","attributesToPopulate","nestedPopulate","map","nestedAttr","componentName","contentTypes"],"mappings":";;;;;AAKA,MAAM,EACJA,qBAAqB,EACrBC,oBAAoB,EACpBC,gBAAgB,EAChBC,mBAAmB,EACnBC,uBAAuB,EACxB,GAAGC,cAAAA;AACJ,MAAM,EAAEC,gBAAgB,EAAE,GAAGC,MAAAA;AAE7B,MAAMC,qBAAqB,CAACC,gBAAAA,GAAAA;IAC1B,OAAOC,IAAAA,CAAK,gCAAgCD,gBAAsB,CAAA,KAAA,IAAA;AACpE,CAAA;AAEA,MAAME,iBAAiB,OAAOC,MAAAA,GAAAA;AAC5B,IAAA,MAAMC,iBAAiBC,UAAW,CAAA,SAAA,CAAA;AAElC,IAAA,IAAIC,MAAMH,MAAS,CAAA,EAAA;AACjB,QAAA,OAAOC,eAAeG,gBAAgB,EAAA;AACxC;AAEA,IAAA,MAAMC,WAAc,GAAA,MAAMJ,cAAeK,CAAAA,UAAU,CAACN,MAAAA,CAAAA;AACpD,IAAA,IAAI,CAACK,WAAa,EAAA;AAChB,QAAA,MAAM,IAAIX,gBAAiB,CAAA,kBAAA,CAAA;AAC7B;IAEA,OAAOM,MAAAA;AACT,CAAA;AAEA;;;;IAKA,MAAMO,uBAAuB,CAACC,SAAAA,GAAAA;AAC5B,IAAA,OACEZ,kBAAmBY,CAAAA,SAAAA,CAAAA,IACnBpB,qBAAsBoB,CAAAA,SAAAA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C,2BAA6B,CAAA;AAClD,QAAA,MAAM1B,IAAOqB,GAAAA,MAAAA,CAAOhC,UAAU,CAACD,QAAS,CAAA;QACxC,IAAIY,IAAAA,CAAKC,IAAI,KAAK,WAAa,EAAA;AAC7B,YAAA,MAAM+B,cAAiBb,GAAAA,yCAAAA,CAA0CnB,IAAKO,CAAAA,SAAS,EAAE0B,GAAG,CAClF,CAACC,UAAAA,GAAe,CAAC,EAAE9C,QAAAA,CAAS,CAAC,EAAE8C,WAAW,CAAC,CAAA;AAE7CH,YAAAA,oBAAAA,CAAqBN,IAAI,CAAIO,GAAAA,cAAAA,CAAAA;AAC/B,SAAA,MAAO,IAAIhC,IAAAA,CAAKC,IAAI,KAAK,aAAe,EAAA;AACtCD,YAAAA,IAAAA,CAAKK,UAAU,CAACN,OAAO,CAAC,CAACoC,aAAAA,GAAAA;AACvB,gBAAA,MAAMH,cAAiBb,GAAAA,yCAAAA,CAA0CgB,aAAeF,CAAAA,CAAAA,GAAG,CACjF,CAACC,UAAe,GAAA,CAAC,EAAE9C,QAAAA,CAAS,CAAC,EAAE8C,WAAW,CAAC,CAAA;AAE7CH,gBAAAA,oBAAAA,CAAqBN,IAAI,CAAIO,GAAAA,cAAAA,CAAAA;AAC/B,aAAA,CAAA;AACF;AACF;IAEA,OAAOD,oBAAAA;AACT,CAAA;AAEMK,MAAAA,YAAAA,GAAe,KAAO;AAC1BpD,QAAAA,sBAAAA;AACAV,QAAAA,cAAAA;AACAsC,QAAAA,sBAAAA;AACA1B,QAAAA,yBAAAA;AACAsB,QAAAA,0BAAAA;AACAK,QAAAA,0BAAAA;AACAM,QAAAA;KACF;;;;"}
1
+ {"version":3,"file":"content-types.mjs","sources":["../../../server/src/services/content-types.ts"],"sourcesContent":["import _ from 'lodash';\nimport { pick, pipe, has, prop, isNil, cloneDeep, isArray } from 'lodash/fp';\nimport { errors, contentTypes as contentTypeUtils } from '@strapi/utils';\nimport { getService } from '../utils';\n\nconst {\n isRelationalAttribute,\n getVisibleAttributes,\n isTypedAttribute,\n getScalarAttributes,\n getRelationalAttributes,\n} = contentTypeUtils;\nconst { ApplicationError } = errors;\n\nconst hasLocalizedOption = (modelOrAttribute: any) => {\n return prop('pluginOptions.i18n.localized', modelOrAttribute) === true;\n};\n\nconst getValidLocale = async (locale: any) => {\n const localesService = getService('locales');\n\n if (isNil(locale)) {\n return localesService.getDefaultLocale();\n }\n\n const foundLocale = await localesService.findByCode(locale);\n if (!foundLocale) {\n throw new ApplicationError('Locale not found');\n }\n\n return locale;\n};\n\n/**\n * Returns whether an attribute is localized or not\n * @param {*} attribute\n * @returns\n */\nconst isLocalizedAttribute = (attribute: any) => {\n return (\n hasLocalizedOption(attribute) ||\n isRelationalAttribute(attribute) ||\n isTypedAttribute(attribute, 'uid')\n );\n};\n\n/**\n * Returns whether a model is localized or not\n * @param {*} model\n * @returns\n */\nconst isLocalizedContentType = (model: any) => {\n return hasLocalizedOption(model);\n};\n\n/**\n * Returns the list of attribute names that are not localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getNonLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter(\n (attrName) => !isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\nconst removeId = (value: any) => {\n if (typeof value === 'object' && has('id', value)) {\n delete value.id;\n }\n};\n\nconst removeIds = (model: any) => (entry: any) => removeIdsMut(model, cloneDeep(entry));\n\nconst removeIdsMut = (model: any, entry: any) => {\n if (isNil(entry)) {\n return entry;\n }\n\n removeId(entry);\n\n _.forEach(model.attributes, (attr, attrName) => {\n const value = entry[attrName];\n if (attr.type === 'dynamiczone' && isArray(value)) {\n value.forEach((compo) => {\n if (has('__component', compo)) {\n const model = strapi.components[compo.__component];\n removeIdsMut(model, compo);\n }\n });\n } else if (attr.type === 'component') {\n const model = strapi.components[attr.component];\n if (isArray(value)) {\n value.forEach((compo) => removeIdsMut(model, compo));\n } else {\n removeIdsMut(model, value);\n }\n }\n });\n\n return entry;\n};\n\n/**\n * Returns a copy of an entry picking only its non localized attributes\n * @param {object} model\n * @param {object} entry\n * @returns {object}\n */\nconst copyNonLocalizedAttributes = (model: any, entry: any) => {\n const nonLocalizedAttributes = getNonLocalizedAttributes(model);\n\n return pipe(pick(nonLocalizedAttributes), removeIds(model))(entry);\n};\n\n/**\n * Returns the list of attribute names that are localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter((attrName) =>\n isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\n/**\n * Fill non localized fields of an entry if there are nil\n * @param {Object} entry entry to fill\n * @param {Object} relatedEntry values used to fill\n * @param {Object} options\n * @param {Object} options.model corresponding model\n */\nconst fillNonLocalizedAttributes = (entry: any, relatedEntry: any, { model }: any) => {\n if (isNil(relatedEntry)) {\n return;\n }\n\n const modelDef = strapi.getModel(model);\n const relatedEntryCopy = copyNonLocalizedAttributes(modelDef, relatedEntry);\n\n _.forEach(relatedEntryCopy, (value, field) => {\n if (isNil(entry[field])) {\n entry[field] = value;\n }\n });\n};\n\n/**\n * build the populate param to\n * @param {String} modelUID uid of the model, could be of a content-type or a component\n */\nconst getNestedPopulateOfNonLocalizedAttributes = (modelUID: any) => {\n const schema = strapi.getModel(modelUID);\n const scalarAttributes = getScalarAttributes(schema);\n const nonLocalizedAttributes = getNonLocalizedAttributes(schema);\n\n const allAttributes = [...scalarAttributes, ...nonLocalizedAttributes];\n if (schema.modelType === 'component') {\n // When called recursively on a non localized component we\n // need to explicitly populate that components relations\n allAttributes.push(...getRelationalAttributes(schema));\n }\n\n const currentAttributesToPopulate = allAttributes.filter((value, index, self) => {\n return self.indexOf(value) === index && self.lastIndexOf(value) === index;\n });\n\n const attributesToPopulate = [...currentAttributesToPopulate];\n for (const attrName of currentAttributesToPopulate) {\n const attr = schema.attributes[attrName];\n if (attr.type === 'component') {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(attr.component).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n } else if (attr.type === 'dynamiczone') {\n attr.components.forEach((componentName) => {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(componentName).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n });\n }\n }\n\n return attributesToPopulate;\n};\n\nconst contentTypes = () => ({\n isLocalizedContentType,\n getValidLocale,\n getLocalizedAttributes,\n getNonLocalizedAttributes,\n copyNonLocalizedAttributes,\n fillNonLocalizedAttributes,\n getNestedPopulateOfNonLocalizedAttributes,\n});\n\ntype ContentTypesService = typeof contentTypes;\n\nexport default contentTypes;\nexport { ContentTypesService };\n"],"names":["isRelationalAttribute","getVisibleAttributes","isTypedAttribute","getScalarAttributes","getRelationalAttributes","contentTypeUtils","ApplicationError","errors","hasLocalizedOption","modelOrAttribute","prop","getValidLocale","locale","localesService","getService","isNil","getDefaultLocale","foundLocale","findByCode","isLocalizedAttribute","attribute","isLocalizedContentType","model","getNonLocalizedAttributes","filter","attrName","attributes","removeId","value","has","id","removeIds","entry","removeIdsMut","cloneDeep","_","forEach","attr","type","isArray","compo","strapi","components","__component","component","copyNonLocalizedAttributes","nonLocalizedAttributes","pipe","pick","getLocalizedAttributes","fillNonLocalizedAttributes","relatedEntry","modelDef","getModel","relatedEntryCopy","field","getNestedPopulateOfNonLocalizedAttributes","modelUID","schema","scalarAttributes","allAttributes","modelType","push","currentAttributesToPopulate","index","self","indexOf","lastIndexOf","attributesToPopulate","nestedPopulate","map","nestedAttr","componentName","contentTypes"],"mappings":";;;;;AAKA,MAAM,EACJA,qBAAqB,EACrBC,oBAAoB,EACpBC,gBAAgB,EAChBC,mBAAmB,EACnBC,uBAAuB,EACxB,GAAGC,cAAAA;AACJ,MAAM,EAAEC,gBAAgB,EAAE,GAAGC,MAAAA;AAE7B,MAAMC,qBAAqB,CAACC,gBAAAA,GAAAA;IAC1B,OAAOC,IAAAA,CAAK,gCAAgCD,gBAAsB,CAAA,KAAA,IAAA;A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CAAA,CAAA,CAAA;AAE7CH,gBAAAA,oBAAAA,CAAqBN,IAAI,CAAIO,GAAAA,cAAAA,CAAAA;AAC/B,aAAA,CAAA;AACF;AACF;IAEA,OAAOD,oBAAAA;AACT,CAAA;AAEMK,MAAAA,YAAAA,GAAe,KAAO;AAC1BpD,QAAAA,sBAAAA;AACAV,QAAAA,cAAAA;AACAsC,QAAAA,sBAAAA;AACA1B,QAAAA,yBAAAA;AACAsB,QAAAA,0BAAAA;AACAK,QAAAA,0BAAAA;AACAM,QAAAA;KACF;;;;"}
@@ -9,6 +9,7 @@ var contentTypes = require('./content-types.js');
9
9
  var index = require('./sanitize/index.js');
10
10
  var settings = require('./settings.js');
11
11
  var aiLocalizations = require('./ai-localizations.js');
12
+ var aiLocalizationJobs = require('./ai-localization-jobs.js');
12
13
 
13
14
  var services = {
14
15
  permissions,
@@ -18,7 +19,8 @@ var services = {
18
19
  sanitize: index,
19
20
  'iso-locales': isoLocales,
20
21
  'content-types': contentTypes,
21
- aiLocalizations: aiLocalizations.createAILocalizationsService,
22
+ 'ai-localizations': aiLocalizations.createAILocalizationsService,
23
+ 'ai-localization-jobs': aiLocalizationJobs.createAILocalizationJobsService,
22
24
  settings: settings.createSettingsService
23
25
  };
24
26
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../server/src/services/index.ts"],"sourcesContent":["import permissions from './permissions';\nimport metrics from './metrics';\nimport localizations from './localizations';\nimport locales from './locales';\nimport isoLocales from './iso-locales';\nimport contentTypes from './content-types';\nimport sanitize from './sanitize';\nimport { createSettingsService } from './settings';\nimport { createAILocalizationsService } from './ai-localizations';\n\nexport default {\n permissions,\n metrics,\n localizations,\n locales,\n sanitize,\n 'iso-locales': isoLocales,\n 'content-types': contentTypes,\n aiLocalizations: createAILocalizationsService,\n settings: createSettingsService,\n};\n"],"names":["permissions","metrics","localizations","locales","sanitize","isoLocales","contentTypes","aiLocalizations","createAILocalizationsService","settings","createSettingsService"],"mappings":";;;;;;;;;;;;AAUA,eAAe;AACbA,IAAAA,WAAAA;AACAC,IAAAA,OAAAA;AACAC,IAAAA,aAAAA;AACAC,IAAAA,OAAAA;AACAC,cAAAA,KAAAA;IACA,aAAeC,EAAAA,UAAAA;IACf,eAAiBC,EAAAA,YAAAA;IACjBC,eAAiBC,EAAAA,4CAAAA;IACjBC,QAAUC,EAAAA;AACZ,CAAE;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../server/src/services/index.ts"],"sourcesContent":["import permissions from './permissions';\nimport metrics from './metrics';\nimport localizations from './localizations';\nimport locales from './locales';\nimport isoLocales from './iso-locales';\nimport contentTypes from './content-types';\nimport sanitize from './sanitize';\nimport { createSettingsService } from './settings';\nimport { createAILocalizationsService } from './ai-localizations';\nimport { createAILocalizationJobsService } from './ai-localization-jobs';\n\nexport default {\n permissions,\n metrics,\n localizations,\n locales,\n sanitize,\n 'iso-locales': isoLocales,\n 'content-types': contentTypes,\n 'ai-localizations': createAILocalizationsService,\n 'ai-localization-jobs': createAILocalizationJobsService,\n settings: createSettingsService,\n};\n"],"names":["permissions","metrics","localizations","locales","sanitize","isoLocales","contentTypes","createAILocalizationsService","createAILocalizationJobsService","settings","createSettingsService"],"mappings":";;;;;;;;;;;;;AAWA,eAAe;AACbA,IAAAA,WAAAA;AACAC,IAAAA,OAAAA;AACAC,IAAAA,aAAAA;AACAC,IAAAA,OAAAA;AACAC,cAAAA,KAAAA;IACA,aAAeC,EAAAA,UAAAA;IACf,eAAiBC,EAAAA,YAAAA;IACjB,kBAAoBC,EAAAA,4CAAAA;IACpB,sBAAwBC,EAAAA,kDAAAA;IACxBC,QAAUC,EAAAA;AACZ,CAAE;;;;"}
@@ -7,6 +7,7 @@ import contentTypes from './content-types.mjs';
7
7
  import sanitize from './sanitize/index.mjs';
8
8
  import { createSettingsService } from './settings.mjs';
9
9
  import { createAILocalizationsService } from './ai-localizations.mjs';
10
+ import { createAILocalizationJobsService } from './ai-localization-jobs.mjs';
10
11
 
11
12
  var services = {
12
13
  permissions,
@@ -16,7 +17,8 @@ var services = {
16
17
  sanitize,
17
18
  'iso-locales': isoLocalesService,
18
19
  'content-types': contentTypes,
19
- aiLocalizations: createAILocalizationsService,
20
+ 'ai-localizations': createAILocalizationsService,
21
+ 'ai-localization-jobs': createAILocalizationJobsService,
20
22
  settings: createSettingsService
21
23
  };
22
24
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../server/src/services/index.ts"],"sourcesContent":["import permissions from './permissions';\nimport metrics from './metrics';\nimport localizations from './localizations';\nimport locales from './locales';\nimport isoLocales from './iso-locales';\nimport contentTypes from './content-types';\nimport sanitize from './sanitize';\nimport { createSettingsService } from './settings';\nimport { createAILocalizationsService } from './ai-localizations';\n\nexport default {\n permissions,\n metrics,\n localizations,\n locales,\n sanitize,\n 'iso-locales': isoLocales,\n 'content-types': contentTypes,\n aiLocalizations: createAILocalizationsService,\n settings: createSettingsService,\n};\n"],"names":["permissions","metrics","localizations","locales","sanitize","isoLocales","contentTypes","aiLocalizations","createAILocalizationsService","settings","createSettingsService"],"mappings":";;;;;;;;;;AAUA,eAAe;AACbA,IAAAA,WAAAA;AACAC,IAAAA,OAAAA;AACAC,IAAAA,aAAAA;AACAC,IAAAA,OAAAA;AACAC,IAAAA,QAAAA;IACA,aAAeC,EAAAA,iBAAAA;IACf,eAAiBC,EAAAA,YAAAA;IACjBC,eAAiBC,EAAAA,4BAAAA;IACjBC,QAAUC,EAAAA;AACZ,CAAE;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../server/src/services/index.ts"],"sourcesContent":["import permissions from './permissions';\nimport metrics from './metrics';\nimport localizations from './localizations';\nimport locales from './locales';\nimport isoLocales from './iso-locales';\nimport contentTypes from './content-types';\nimport sanitize from './sanitize';\nimport { createSettingsService } from './settings';\nimport { createAILocalizationsService } from './ai-localizations';\nimport { createAILocalizationJobsService } from './ai-localization-jobs';\n\nexport default {\n permissions,\n metrics,\n localizations,\n locales,\n sanitize,\n 'iso-locales': isoLocales,\n 'content-types': contentTypes,\n 'ai-localizations': createAILocalizationsService,\n 'ai-localization-jobs': createAILocalizationJobsService,\n settings: createSettingsService,\n};\n"],"names":["permissions","metrics","localizations","locales","sanitize","isoLocales","contentTypes","createAILocalizationsService","createAILocalizationJobsService","settings","createSettingsService"],"mappings":";;;;;;;;;;;AAWA,eAAe;AACbA,IAAAA,WAAAA;AACAC,IAAAA,OAAAA;AACAC,IAAAA,aAAAA;AACAC,IAAAA,OAAAA;AACAC,IAAAA,QAAAA;IACA,aAAeC,EAAAA,iBAAAA;IACf,eAAiBC,EAAAA,YAAAA;IACjB,kBAAoBC,EAAAA,4BAAAA;IACpB,sBAAwBC,EAAAA,+BAAAA;IACxBC,QAAUC,EAAAA;AACZ,CAAE;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../../server/src/bootstrap.ts"],"names":[],"mappings":";AA4DA,wBAuBE"}
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../../server/src/bootstrap.ts"],"names":[],"mappings":";AA4DA,wBA0BE"}
@@ -0,0 +1,17 @@
1
+ import type { Core } from '@strapi/types';
2
+ declare const createAILocalizationJobsController: ({ strapi }: {
3
+ strapi: Core.Strapi;
4
+ }) => {
5
+ /**
6
+ * Get a job for a singleType using the contentType
7
+ * There is only 1 job per contentType
8
+ */
9
+ getJobForSingleType(ctx: any): Promise<any>;
10
+ /**
11
+ * Get a job for a collectionType using the documentId
12
+ * There is only 1 job per documentId
13
+ */
14
+ getJobForCollectionType(ctx: any): Promise<any>;
15
+ };
16
+ export default createAILocalizationJobsController;
17
+ //# sourceMappingURL=ai-localization-jobs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-localization-jobs.d.ts","sourceRoot":"","sources":["../../../../server/src/controllers/ai-localization-jobs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,QAAA,MAAM,kCAAkC,eAAgB;IAAE,MAAM,EAAE,KAAK,MAAM,CAAA;CAAE;IAK3E;;;OAGG;6BAC4B,GAAG;IAkBlC;;;OAGG;iCACgC,GAAG;CAmBzC,CAAC;AAEF,eAAe,kCAAkC,CAAC"}
@@ -9,6 +9,12 @@ declare const _default: {
9
9
  updateSettings(ctx: import("koa").Context): Promise<void>;
10
10
  getSettings(ctx: import("koa").Context): Promise<void>;
11
11
  };
12
+ 'ai-localization-jobs': ({ strapi }: {
13
+ strapi: import("@strapi/types/dist/core").Strapi;
14
+ }) => {
15
+ getJobForSingleType(ctx: any): Promise<any>;
16
+ getJobForCollectionType(ctx: any): Promise<any>;
17
+ };
12
18
  };
13
19
  export default _default;
14
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/src/controllers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,wBAKE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/src/controllers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,wBAME"}
@@ -3,7 +3,7 @@
3
3
  declare const _default: () => {
4
4
  register: ({ strapi }: {
5
5
  strapi: import("@strapi/types/dist/core").Strapi;
6
- }) => void;
6
+ }) => Promise<void>;
7
7
  bootstrap: () => Promise<void>;
8
8
  routes: {
9
9
  admin: {
@@ -37,6 +37,12 @@ declare const _default: () => {
37
37
  updateSettings(ctx: import("koa").Context): Promise<void>;
38
38
  getSettings(ctx: import("koa").Context): Promise<void>;
39
39
  };
40
+ 'ai-localization-jobs': ({ strapi }: {
41
+ strapi: import("@strapi/types/dist/core").Strapi;
42
+ }) => {
43
+ getJobForSingleType(ctx: any): Promise<any>;
44
+ getJobForCollectionType(ctx: any): Promise<any>;
45
+ };
40
46
  };
41
47
  contentTypes: {
42
48
  locale: {
@@ -150,10 +156,28 @@ declare const _default: () => {
150
156
  fillNonLocalizedAttributes: (entry: any, relatedEntry: any, { model }: any) => void;
151
157
  getNestedPopulateOfNonLocalizedAttributes: (modelUID: any) => string[];
152
158
  };
153
- aiLocalizations: ({ strapi }: {
159
+ 'ai-localizations': ({ strapi }: {
154
160
  strapi: import("@strapi/types/dist/core").Strapi;
155
161
  }) => {
156
162
  isEnabled(): Promise<boolean>;
163
+ generateDocumentLocalizations({ model, document, }: {
164
+ model: import("@strapi/types/dist/uid").ContentType;
165
+ document: import("@strapi/types/dist/modules/documents").AnyDocument;
166
+ }): Promise<void>;
167
+ setupMiddleware(): void;
168
+ };
169
+ 'ai-localization-jobs': ({ strapi }: {
170
+ strapi: import("@strapi/types/dist/core").Strapi;
171
+ }) => {
172
+ upsertJobForDocument({ documentId, contentType, sourceLocale, targetLocales, status, }: {
173
+ documentId: string;
174
+ contentType: string;
175
+ sourceLocale: string;
176
+ targetLocales: string[];
177
+ status?: "processing" | "completed" | "failed" | undefined;
178
+ }): Promise<any>;
179
+ getJobByDocument(contentType: string, documentId: string): Promise<any>;
180
+ getJobByContentType(contentType: string): Promise<any>;
157
181
  };
158
182
  settings: ({ strapi }: {
159
183
  strapi: import("@strapi/types/dist/core").Strapi;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../server/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,wBAOG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../server/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,wBAOG"}
@@ -0,0 +1,5 @@
1
+ import type { Model } from '@strapi/database';
2
+ declare const AI_LOCALIZATION_JOB_UID = "plugin::i18n.ai-localization-job";
3
+ declare const aiLocalizationJob: Model;
4
+ export { aiLocalizationJob, AI_LOCALIZATION_JOB_UID };
5
+ //# sourceMappingURL=ai-localization-job.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-localization-job.d.ts","sourceRoot":"","sources":["../../../../server/src/models/ai-localization-job.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,QAAA,MAAM,uBAAuB,qCAAqC,CAAC;AAEnE,QAAA,MAAM,iBAAiB,EAAE,KAsCxB,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ aiLocalizationJob: import("@strapi/database").Model;
3
+ };
4
+ export default _default;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/src/models/index.ts"],"names":[],"mappings":";;;AAEA,wBAEE"}