@strapi/i18n 0.0.0-next.ce84fada19d58a7dfbdd553035e6558f8befcba4 → 0.0.0-next.d190a700af70e9360d767221b76cd8e815bd01aa

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 (460) hide show
  1. package/dist/admin/components/BulkLocaleActionModal.js +262 -0
  2. package/dist/admin/components/BulkLocaleActionModal.js.map +1 -0
  3. package/dist/admin/components/BulkLocaleActionModal.mjs +260 -0
  4. package/dist/admin/components/BulkLocaleActionModal.mjs.map +1 -0
  5. package/dist/admin/components/CMHeaderActions.js +968 -0
  6. package/dist/admin/components/CMHeaderActions.js.map +1 -0
  7. package/dist/admin/components/CMHeaderActions.mjs +942 -0
  8. package/dist/admin/components/CMHeaderActions.mjs.map +1 -0
  9. package/dist/admin/components/CMListViewModalsAdditionalInformation.js +69 -0
  10. package/dist/admin/components/CMListViewModalsAdditionalInformation.js.map +1 -0
  11. package/dist/admin/components/CMListViewModalsAdditionalInformation.mjs +65 -0
  12. package/dist/admin/components/CMListViewModalsAdditionalInformation.mjs.map +1 -0
  13. package/dist/admin/components/CheckboxConfirmation.js +155 -0
  14. package/dist/admin/components/CheckboxConfirmation.js.map +1 -0
  15. package/dist/admin/components/CheckboxConfirmation.mjs +134 -0
  16. package/dist/admin/components/CheckboxConfirmation.mjs.map +1 -0
  17. package/dist/admin/components/CreateLocale.js +394 -0
  18. package/dist/admin/components/CreateLocale.js.map +1 -0
  19. package/dist/admin/components/CreateLocale.mjs +368 -0
  20. package/dist/admin/components/CreateLocale.mjs.map +1 -0
  21. package/dist/admin/components/DeleteLocale.js +90 -0
  22. package/dist/admin/components/DeleteLocale.js.map +1 -0
  23. package/dist/admin/components/DeleteLocale.mjs +69 -0
  24. package/dist/admin/components/DeleteLocale.mjs.map +1 -0
  25. package/dist/admin/components/EditLocale.js +212 -0
  26. package/dist/admin/components/EditLocale.js.map +1 -0
  27. package/dist/admin/components/EditLocale.mjs +190 -0
  28. package/dist/admin/components/EditLocale.mjs.map +1 -0
  29. package/dist/admin/components/LocaleListCell.js +102 -0
  30. package/dist/admin/components/LocaleListCell.js.map +1 -0
  31. package/dist/admin/components/LocaleListCell.mjs +100 -0
  32. package/dist/admin/components/LocaleListCell.mjs.map +1 -0
  33. package/dist/admin/components/LocalePicker.js +105 -0
  34. package/dist/admin/components/LocalePicker.js.map +1 -0
  35. package/dist/admin/components/LocalePicker.mjs +84 -0
  36. package/dist/admin/components/LocalePicker.mjs.map +1 -0
  37. package/dist/admin/components/LocaleTable.js +143 -0
  38. package/dist/admin/components/LocaleTable.js.map +1 -0
  39. package/dist/admin/components/LocaleTable.mjs +122 -0
  40. package/dist/admin/components/LocaleTable.mjs.map +1 -0
  41. package/dist/admin/constants.js +37 -0
  42. package/dist/admin/constants.js.map +1 -0
  43. package/dist/admin/constants.mjs +35 -0
  44. package/dist/admin/constants.mjs.map +1 -0
  45. package/dist/admin/contentManagerHooks/editView.js +109 -0
  46. package/dist/admin/contentManagerHooks/editView.js.map +1 -0
  47. package/dist/admin/contentManagerHooks/editView.mjs +88 -0
  48. package/dist/admin/contentManagerHooks/editView.mjs.map +1 -0
  49. package/dist/admin/contentManagerHooks/listView.js +44 -0
  50. package/dist/admin/contentManagerHooks/listView.js.map +1 -0
  51. package/dist/admin/contentManagerHooks/listView.mjs +42 -0
  52. package/dist/admin/contentManagerHooks/listView.mjs.map +1 -0
  53. package/dist/admin/contentReleasesHooks/releaseDetailsView.js +20 -0
  54. package/dist/admin/contentReleasesHooks/releaseDetailsView.js.map +1 -0
  55. package/dist/admin/contentReleasesHooks/releaseDetailsView.mjs +18 -0
  56. package/dist/admin/contentReleasesHooks/releaseDetailsView.mjs.map +1 -0
  57. package/dist/admin/hooks/useAILocalizationJobsPolling.js +110 -0
  58. package/dist/admin/hooks/useAILocalizationJobsPolling.js.map +1 -0
  59. package/dist/admin/hooks/useAILocalizationJobsPolling.mjs +89 -0
  60. package/dist/admin/hooks/useAILocalizationJobsPolling.mjs.map +1 -0
  61. package/dist/admin/hooks/useI18n.js +78 -0
  62. package/dist/admin/hooks/useI18n.js.map +1 -0
  63. package/dist/admin/hooks/useI18n.mjs +57 -0
  64. package/dist/admin/hooks/useI18n.mjs.map +1 -0
  65. package/dist/admin/index.js +226 -5
  66. package/dist/admin/index.js.map +1 -1
  67. package/dist/admin/index.mjs +202 -5
  68. package/dist/admin/index.mjs.map +1 -1
  69. package/dist/admin/middlewares/extendCTBAttributeInitialData.js +71 -0
  70. package/dist/admin/middlewares/extendCTBAttributeInitialData.js.map +1 -0
  71. package/dist/admin/middlewares/extendCTBAttributeInitialData.mjs +69 -0
  72. package/dist/admin/middlewares/extendCTBAttributeInitialData.mjs.map +1 -0
  73. package/dist/admin/middlewares/extendCTBInitialData.js +40 -0
  74. package/dist/admin/middlewares/extendCTBInitialData.js.map +1 -0
  75. package/dist/admin/middlewares/extendCTBInitialData.mjs +38 -0
  76. package/dist/admin/middlewares/extendCTBInitialData.mjs.map +1 -0
  77. package/dist/admin/middlewares/rbac-middleware.js +49 -0
  78. package/dist/admin/middlewares/rbac-middleware.js.map +1 -0
  79. package/dist/admin/middlewares/rbac-middleware.mjs +28 -0
  80. package/dist/admin/middlewares/rbac-middleware.mjs.map +1 -0
  81. package/dist/admin/pages/SettingsPage.js +182 -0
  82. package/dist/admin/pages/SettingsPage.js.map +1 -0
  83. package/dist/admin/pages/SettingsPage.mjs +179 -0
  84. package/dist/admin/pages/SettingsPage.mjs.map +1 -0
  85. package/dist/admin/pluginId.js +6 -0
  86. package/dist/admin/pluginId.js.map +1 -0
  87. package/dist/admin/pluginId.mjs +4 -0
  88. package/dist/admin/pluginId.mjs.map +1 -0
  89. package/dist/admin/services/aiLocalizationJobs.js +26 -0
  90. package/dist/admin/services/aiLocalizationJobs.js.map +1 -0
  91. package/dist/admin/services/aiLocalizationJobs.mjs +24 -0
  92. package/dist/admin/services/aiLocalizationJobs.mjs.map +1 -0
  93. package/dist/admin/services/api.js +15 -0
  94. package/dist/admin/services/api.js.map +1 -0
  95. package/dist/admin/services/api.mjs +13 -0
  96. package/dist/admin/services/api.mjs.map +1 -0
  97. package/dist/admin/services/locales.js +72 -0
  98. package/dist/admin/services/locales.js.map +1 -0
  99. package/dist/admin/services/locales.mjs +66 -0
  100. package/dist/admin/services/locales.mjs.map +1 -0
  101. package/dist/admin/services/relations.js +23 -0
  102. package/dist/admin/services/relations.js.map +1 -0
  103. package/dist/admin/services/relations.mjs +21 -0
  104. package/dist/admin/services/relations.mjs.map +1 -0
  105. package/dist/admin/services/settings.js +30 -0
  106. package/dist/admin/services/settings.js.map +1 -0
  107. package/dist/admin/services/settings.mjs +27 -0
  108. package/dist/admin/services/settings.mjs.map +1 -0
  109. package/dist/admin/src/components/CMHeaderActions.d.ts +19 -6
  110. package/dist/admin/src/components/LocaleListCell.d.ts +5 -4
  111. package/dist/admin/src/components/tests/CreateLocale.test.d.ts +1 -0
  112. package/dist/admin/src/components/tests/DeleteLocale.test.d.ts +1 -0
  113. package/dist/admin/src/components/tests/EditLocale.test.d.ts +1 -0
  114. package/dist/admin/src/components/tests/LocaleListCell.test.d.ts +1 -0
  115. package/dist/admin/src/contentReleasesHooks/releaseDetailsView.d.ts +1 -1
  116. package/dist/admin/src/hooks/useAILocalizationJobsPolling.d.ts +9 -0
  117. package/dist/admin/src/pages/tests/SettingsPage.test.d.ts +1 -0
  118. package/dist/admin/src/services/aiLocalizationJobs.d.ts +6 -0
  119. package/dist/admin/src/services/api.d.ts +1 -1
  120. package/dist/admin/src/services/locales.d.ts +1 -1
  121. package/dist/admin/src/services/relations.d.ts +1 -1
  122. package/dist/admin/src/services/settings.d.ts +5 -0
  123. package/dist/admin/src/utils/schemas.d.ts +642 -16
  124. package/dist/admin/tests/server.d.ts +1 -0
  125. package/dist/admin/tests/utils.d.ts +6 -0
  126. package/dist/admin/translations/de.json.js +66 -0
  127. package/dist/admin/translations/de.json.js.map +1 -0
  128. package/dist/admin/translations/de.json.mjs +64 -0
  129. package/dist/admin/translations/de.json.mjs.map +1 -0
  130. package/dist/admin/translations/dk.json.js +66 -0
  131. package/dist/admin/translations/dk.json.js.map +1 -0
  132. package/dist/admin/translations/dk.json.mjs +64 -0
  133. package/dist/admin/translations/dk.json.mjs.map +1 -0
  134. package/dist/admin/translations/en.json.js +91 -0
  135. package/dist/admin/translations/en.json.js.map +1 -0
  136. package/dist/admin/translations/en.json.mjs +89 -0
  137. package/dist/admin/translations/en.json.mjs.map +1 -0
  138. package/dist/admin/translations/es.json.js +66 -0
  139. package/dist/admin/translations/es.json.js.map +1 -0
  140. package/dist/admin/translations/es.json.mjs +64 -0
  141. package/dist/admin/translations/es.json.mjs.map +1 -0
  142. package/dist/admin/translations/fr.json.js +66 -0
  143. package/dist/admin/translations/fr.json.js.map +1 -0
  144. package/dist/admin/translations/fr.json.mjs +64 -0
  145. package/dist/admin/translations/fr.json.mjs.map +1 -0
  146. package/dist/admin/translations/ko.json.js +65 -0
  147. package/dist/admin/translations/ko.json.js.map +1 -0
  148. package/dist/admin/translations/ko.json.mjs +63 -0
  149. package/dist/admin/translations/ko.json.mjs.map +1 -0
  150. package/dist/admin/translations/pl.json.js +66 -0
  151. package/dist/admin/translations/pl.json.js.map +1 -0
  152. package/dist/admin/translations/pl.json.mjs +64 -0
  153. package/dist/admin/translations/pl.json.mjs.map +1 -0
  154. package/dist/admin/translations/ru.json.js +68 -0
  155. package/dist/admin/translations/ru.json.js.map +1 -0
  156. package/dist/admin/translations/ru.json.mjs +66 -0
  157. package/dist/admin/translations/ru.json.mjs.map +1 -0
  158. package/dist/admin/translations/tr.json.js +66 -0
  159. package/dist/admin/translations/tr.json.js.map +1 -0
  160. package/dist/admin/translations/tr.json.mjs +64 -0
  161. package/dist/admin/translations/tr.json.mjs.map +1 -0
  162. package/dist/admin/translations/uk.json.js +82 -0
  163. package/dist/admin/translations/uk.json.js.map +1 -0
  164. package/dist/admin/translations/uk.json.mjs +80 -0
  165. package/dist/admin/translations/uk.json.mjs.map +1 -0
  166. package/dist/admin/translations/zh-Hans.json.js +57 -0
  167. package/dist/admin/translations/zh-Hans.json.js.map +1 -0
  168. package/dist/admin/translations/zh-Hans.json.mjs +55 -0
  169. package/dist/admin/translations/zh-Hans.json.mjs.map +1 -0
  170. package/dist/admin/translations/zh.json.js +66 -0
  171. package/dist/admin/translations/zh.json.js.map +1 -0
  172. package/dist/admin/translations/zh.json.mjs +64 -0
  173. package/dist/admin/translations/zh.json.mjs.map +1 -0
  174. package/dist/admin/utils/baseQuery.js +8 -0
  175. package/dist/admin/utils/baseQuery.js.map +1 -0
  176. package/dist/admin/utils/baseQuery.mjs +6 -0
  177. package/dist/admin/utils/baseQuery.mjs.map +1 -0
  178. package/dist/admin/utils/clean.js +70 -0
  179. package/dist/admin/utils/clean.js.map +1 -0
  180. package/dist/admin/utils/clean.mjs +68 -0
  181. package/dist/admin/utils/clean.mjs.map +1 -0
  182. package/dist/admin/utils/fields.js +34 -0
  183. package/dist/admin/utils/fields.js.map +1 -0
  184. package/dist/admin/utils/fields.mjs +31 -0
  185. package/dist/admin/utils/fields.mjs.map +1 -0
  186. package/dist/admin/utils/getTranslation.js +8 -0
  187. package/dist/admin/utils/getTranslation.js.map +1 -0
  188. package/dist/admin/utils/getTranslation.mjs +6 -0
  189. package/dist/admin/utils/getTranslation.mjs.map +1 -0
  190. package/dist/admin/utils/prefixPluginTranslations.js +11 -0
  191. package/dist/admin/utils/prefixPluginTranslations.js.map +1 -0
  192. package/dist/admin/utils/prefixPluginTranslations.mjs +9 -0
  193. package/dist/admin/utils/prefixPluginTranslations.mjs.map +1 -0
  194. package/dist/admin/utils/schemas.js +74 -0
  195. package/dist/admin/utils/schemas.js.map +1 -0
  196. package/dist/admin/utils/schemas.mjs +72 -0
  197. package/dist/admin/utils/schemas.mjs.map +1 -0
  198. package/dist/admin/utils/strings.js +6 -0
  199. package/dist/admin/utils/strings.js.map +1 -0
  200. package/dist/admin/utils/strings.mjs +4 -0
  201. package/dist/admin/utils/strings.mjs.map +1 -0
  202. package/dist/server/bootstrap.js +81 -0
  203. package/dist/server/bootstrap.js.map +1 -0
  204. package/dist/server/bootstrap.mjs +79 -0
  205. package/dist/server/bootstrap.mjs.map +1 -0
  206. package/dist/server/constants/index.js +29 -0
  207. package/dist/server/constants/index.js.map +1 -0
  208. package/dist/server/constants/index.mjs +25 -0
  209. package/dist/server/constants/index.mjs.map +1 -0
  210. package/dist/server/constants/iso-locales.json.js +2427 -0
  211. package/dist/server/constants/iso-locales.json.js.map +1 -0
  212. package/dist/server/constants/iso-locales.json.mjs +2425 -0
  213. package/dist/server/constants/iso-locales.json.mjs.map +1 -0
  214. package/dist/server/content-types/index.js +10 -0
  215. package/dist/server/content-types/index.js.map +1 -0
  216. package/dist/server/content-types/index.mjs +8 -0
  217. package/dist/server/content-types/index.mjs.map +1 -0
  218. package/dist/server/content-types/locale/index.js +10 -0
  219. package/dist/server/content-types/locale/index.js.map +1 -0
  220. package/dist/server/content-types/locale/index.mjs +8 -0
  221. package/dist/server/content-types/locale/index.mjs.map +1 -0
  222. package/dist/server/content-types/locale/schema.json.js +46 -0
  223. package/dist/server/content-types/locale/schema.json.js.map +1 -0
  224. package/dist/server/content-types/locale/schema.json.mjs +38 -0
  225. package/dist/server/content-types/locale/schema.json.mjs.map +1 -0
  226. package/dist/server/controllers/ai-localization-jobs.js +47 -0
  227. package/dist/server/controllers/ai-localization-jobs.js.map +1 -0
  228. package/dist/server/controllers/ai-localization-jobs.mjs +45 -0
  229. package/dist/server/controllers/ai-localization-jobs.mjs.map +1 -0
  230. package/dist/server/controllers/content-types.js +76 -0
  231. package/dist/server/controllers/content-types.js.map +1 -0
  232. package/dist/server/controllers/content-types.mjs +74 -0
  233. package/dist/server/controllers/content-types.mjs.map +1 -0
  234. package/dist/server/controllers/index.js +18 -0
  235. package/dist/server/controllers/index.js.map +1 -0
  236. package/dist/server/controllers/index.mjs +16 -0
  237. package/dist/server/controllers/index.mjs.map +1 -0
  238. package/dist/server/controllers/iso-locales.js +13 -0
  239. package/dist/server/controllers/iso-locales.js.map +1 -0
  240. package/dist/server/controllers/iso-locales.mjs +11 -0
  241. package/dist/server/controllers/iso-locales.mjs.map +1 -0
  242. package/dist/server/controllers/locales.js +108 -0
  243. package/dist/server/controllers/locales.js.map +1 -0
  244. package/dist/server/controllers/locales.mjs +87 -0
  245. package/dist/server/controllers/locales.mjs.map +1 -0
  246. package/dist/server/controllers/settings.js +24 -0
  247. package/dist/server/controllers/settings.js.map +1 -0
  248. package/dist/server/controllers/settings.mjs +22 -0
  249. package/dist/server/controllers/settings.mjs.map +1 -0
  250. package/dist/server/controllers/validate-locale-creation.js +47 -0
  251. package/dist/server/controllers/validate-locale-creation.js.map +1 -0
  252. package/dist/server/controllers/validate-locale-creation.mjs +45 -0
  253. package/dist/server/controllers/validate-locale-creation.mjs.map +1 -0
  254. package/dist/server/domain/locale.js +11 -0
  255. package/dist/server/domain/locale.js.map +1 -0
  256. package/dist/server/domain/locale.mjs +9 -0
  257. package/dist/server/domain/locale.mjs.map +1 -0
  258. package/dist/server/graphql.js +115 -0
  259. package/dist/server/graphql.js.map +1 -0
  260. package/dist/server/graphql.mjs +113 -0
  261. package/dist/server/graphql.mjs.map +1 -0
  262. package/dist/server/index.js +18 -3430
  263. package/dist/server/index.js.map +1 -1
  264. package/dist/server/index.mjs +17 -3412
  265. package/dist/server/index.mjs.map +1 -1
  266. package/dist/server/models/ai-localization-job.js +60 -0
  267. package/dist/server/models/ai-localization-job.js.map +1 -0
  268. package/dist/server/models/ai-localization-job.mjs +57 -0
  269. package/dist/server/models/ai-localization-job.mjs.map +1 -0
  270. package/dist/server/register.js +81 -0
  271. package/dist/server/register.js.map +1 -0
  272. package/dist/server/register.mjs +79 -0
  273. package/dist/server/register.mjs.map +1 -0
  274. package/dist/server/routes/admin.js +142 -0
  275. package/dist/server/routes/admin.js.map +1 -0
  276. package/dist/server/routes/admin.mjs +140 -0
  277. package/dist/server/routes/admin.mjs.map +1 -0
  278. package/dist/server/routes/content-api.js +19 -0
  279. package/dist/server/routes/content-api.js.map +1 -0
  280. package/dist/server/routes/content-api.mjs +17 -0
  281. package/dist/server/routes/content-api.mjs.map +1 -0
  282. package/dist/server/routes/index.js +12 -0
  283. package/dist/server/routes/index.js.map +1 -0
  284. package/dist/server/routes/index.mjs +10 -0
  285. package/dist/server/routes/index.mjs.map +1 -0
  286. package/dist/server/routes/validation/locale.js +57 -0
  287. package/dist/server/routes/validation/locale.js.map +1 -0
  288. package/dist/server/routes/validation/locale.mjs +36 -0
  289. package/dist/server/routes/validation/locale.mjs.map +1 -0
  290. package/dist/server/services/ai-localization-jobs.js +64 -0
  291. package/dist/server/services/ai-localization-jobs.js.map +1 -0
  292. package/dist/server/services/ai-localization-jobs.mjs +62 -0
  293. package/dist/server/services/ai-localization-jobs.mjs.map +1 -0
  294. package/dist/server/services/ai-localizations.js +268 -0
  295. package/dist/server/services/ai-localizations.js.map +1 -0
  296. package/dist/server/services/ai-localizations.mjs +266 -0
  297. package/dist/server/services/ai-localizations.mjs.map +1 -0
  298. package/dist/server/services/content-types.js +157 -0
  299. package/dist/server/services/content-types.js.map +1 -0
  300. package/dist/server/services/content-types.mjs +155 -0
  301. package/dist/server/services/content-types.mjs.map +1 -0
  302. package/dist/server/services/index.js +28 -0
  303. package/dist/server/services/index.js.map +1 -0
  304. package/dist/server/services/index.mjs +26 -0
  305. package/dist/server/services/index.mjs.map +1 -0
  306. package/dist/server/services/iso-locales.js +12 -0
  307. package/dist/server/services/iso-locales.js.map +1 -0
  308. package/dist/server/services/iso-locales.mjs +10 -0
  309. package/dist/server/services/iso-locales.mjs.map +1 -0
  310. package/dist/server/services/locales.js +114 -0
  311. package/dist/server/services/locales.js.map +1 -0
  312. package/dist/server/services/locales.mjs +112 -0
  313. package/dist/server/services/locales.mjs.map +1 -0
  314. package/dist/server/services/localizations.js +68 -0
  315. package/dist/server/services/localizations.js.map +1 -0
  316. package/dist/server/services/localizations.mjs +66 -0
  317. package/dist/server/services/localizations.mjs.map +1 -0
  318. package/dist/server/services/metrics.js +30 -0
  319. package/dist/server/services/metrics.js.map +1 -0
  320. package/dist/server/services/metrics.mjs +28 -0
  321. package/dist/server/services/metrics.mjs.map +1 -0
  322. package/dist/server/services/permissions/actions.js +136 -0
  323. package/dist/server/services/permissions/actions.js.map +1 -0
  324. package/dist/server/services/permissions/actions.mjs +134 -0
  325. package/dist/server/services/permissions/actions.mjs.map +1 -0
  326. package/dist/server/services/permissions/engine.js +52 -0
  327. package/dist/server/services/permissions/engine.js.map +1 -0
  328. package/dist/server/services/permissions/engine.mjs +50 -0
  329. package/dist/server/services/permissions/engine.mjs.map +1 -0
  330. package/dist/server/services/permissions/sections-builder.js +45 -0
  331. package/dist/server/services/permissions/sections-builder.js.map +1 -0
  332. package/dist/server/services/permissions/sections-builder.mjs +43 -0
  333. package/dist/server/services/permissions/sections-builder.mjs.map +1 -0
  334. package/dist/server/services/permissions.js +14 -0
  335. package/dist/server/services/permissions.js.map +1 -0
  336. package/dist/server/services/permissions.mjs +12 -0
  337. package/dist/server/services/permissions.mjs.map +1 -0
  338. package/dist/server/services/sanitize/index.js +34 -0
  339. package/dist/server/services/sanitize/index.js.map +1 -0
  340. package/dist/server/services/sanitize/index.mjs +32 -0
  341. package/dist/server/services/sanitize/index.mjs.map +1 -0
  342. package/dist/server/services/settings.js +25 -0
  343. package/dist/server/services/settings.js.map +1 -0
  344. package/dist/server/services/settings.mjs +23 -0
  345. package/dist/server/services/settings.mjs.map +1 -0
  346. package/dist/server/src/bootstrap.d.ts.map +1 -1
  347. package/dist/server/src/controllers/ai-localization-jobs.d.ts +17 -0
  348. package/dist/server/src/controllers/ai-localization-jobs.d.ts.map +1 -0
  349. package/dist/server/src/controllers/index.d.ts +10 -0
  350. package/dist/server/src/controllers/index.d.ts.map +1 -1
  351. package/dist/server/src/controllers/settings.d.ts +7 -0
  352. package/dist/server/src/controllers/settings.d.ts.map +1 -0
  353. package/dist/server/src/index.d.ts +53 -8
  354. package/dist/server/src/index.d.ts.map +1 -1
  355. package/dist/server/src/models/ai-localization-job.d.ts +5 -0
  356. package/dist/server/src/models/ai-localization-job.d.ts.map +1 -0
  357. package/dist/server/src/models/index.d.ts +5 -0
  358. package/dist/server/src/models/index.d.ts.map +1 -0
  359. package/dist/server/src/register.d.ts +1 -1
  360. package/dist/server/src/register.d.ts.map +1 -1
  361. package/dist/server/src/routes/admin.d.ts.map +1 -1
  362. package/dist/server/src/routes/content-api.d.ts +5 -8
  363. package/dist/server/src/routes/content-api.d.ts.map +1 -1
  364. package/dist/server/src/routes/index.d.ts +3 -7
  365. package/dist/server/src/routes/index.d.ts.map +1 -1
  366. package/dist/server/src/routes/validation/index.d.ts +2 -0
  367. package/dist/server/src/routes/validation/index.d.ts.map +1 -0
  368. package/dist/server/src/routes/validation/locale.d.ts +41 -0
  369. package/dist/server/src/routes/validation/locale.d.ts.map +1 -0
  370. package/dist/server/src/services/ai-localization-jobs.d.ts +26 -0
  371. package/dist/server/src/services/ai-localization-jobs.d.ts.map +1 -0
  372. package/dist/server/src/services/ai-localizations.d.ts +18 -0
  373. package/dist/server/src/services/ai-localizations.d.ts.map +1 -0
  374. package/dist/server/src/services/index.d.ts +39 -0
  375. package/dist/server/src/services/index.d.ts.map +1 -1
  376. package/dist/server/src/services/localizations.d.ts +1 -1
  377. package/dist/server/src/services/localizations.d.ts.map +1 -1
  378. package/dist/server/src/services/sanitize/index.d.ts +11 -0
  379. package/dist/server/src/services/sanitize/index.d.ts.map +1 -0
  380. package/dist/server/src/services/settings.d.ts +13 -0
  381. package/dist/server/src/services/settings.d.ts.map +1 -0
  382. package/dist/server/src/utils/index.d.ts +9 -1
  383. package/dist/server/src/utils/index.d.ts.map +1 -1
  384. package/dist/server/src/validation/settings.d.ts +12 -0
  385. package/dist/server/src/validation/settings.d.ts.map +1 -0
  386. package/dist/server/utils/index.js +16 -0
  387. package/dist/server/utils/index.js.map +1 -0
  388. package/dist/server/utils/index.mjs +13 -0
  389. package/dist/server/utils/index.mjs.map +1 -0
  390. package/dist/server/validation/content-types.js +18 -0
  391. package/dist/server/validation/content-types.js.map +1 -0
  392. package/dist/server/validation/content-types.mjs +16 -0
  393. package/dist/server/validation/content-types.mjs.map +1 -0
  394. package/dist/server/validation/locales.js +23 -0
  395. package/dist/server/validation/locales.js.map +1 -0
  396. package/dist/server/validation/locales.mjs +20 -0
  397. package/dist/server/validation/locales.mjs.map +1 -0
  398. package/dist/server/validation/settings.js +11 -0
  399. package/dist/server/validation/settings.js.map +1 -0
  400. package/dist/server/validation/settings.mjs +9 -0
  401. package/dist/server/validation/settings.mjs.map +1 -0
  402. package/dist/shared/contracts/ai-localization-jobs.d.ts +27 -0
  403. package/dist/shared/contracts/ai-localization-jobs.d.ts.map +1 -0
  404. package/dist/shared/contracts/content-manager.d.ts +1 -1
  405. package/dist/shared/contracts/settings.d.ts +40 -0
  406. package/dist/shared/contracts/shared.d.ts +1 -1
  407. package/dist/shared/contracts/shared.d.ts.map +1 -0
  408. package/package.json +22 -17
  409. package/dist/_chunks/SettingsPage-DbRFoF_H.mjs +0 -554
  410. package/dist/_chunks/SettingsPage-DbRFoF_H.mjs.map +0 -1
  411. package/dist/_chunks/SettingsPage-uGJv15wR.js +0 -574
  412. package/dist/_chunks/SettingsPage-uGJv15wR.js.map +0 -1
  413. package/dist/_chunks/de-9eCAqqrB.mjs +0 -66
  414. package/dist/_chunks/de-9eCAqqrB.mjs.map +0 -1
  415. package/dist/_chunks/de-DtWiGdHl.js +0 -66
  416. package/dist/_chunks/de-DtWiGdHl.js.map +0 -1
  417. package/dist/_chunks/dk-2qBjxt-P.mjs +0 -66
  418. package/dist/_chunks/dk-2qBjxt-P.mjs.map +0 -1
  419. package/dist/_chunks/dk-D8C-casx.js +0 -66
  420. package/dist/_chunks/dk-D8C-casx.js.map +0 -1
  421. package/dist/_chunks/en-BYRZFDBV.mjs +0 -81
  422. package/dist/_chunks/en-BYRZFDBV.mjs.map +0 -1
  423. package/dist/_chunks/en-Dk9At9_Z.js +0 -81
  424. package/dist/_chunks/en-Dk9At9_Z.js.map +0 -1
  425. package/dist/_chunks/es-DS-XFGSw.js +0 -66
  426. package/dist/_chunks/es-DS-XFGSw.js.map +0 -1
  427. package/dist/_chunks/es-DlmMVaBG.mjs +0 -66
  428. package/dist/_chunks/es-DlmMVaBG.mjs.map +0 -1
  429. package/dist/_chunks/fr-3S6ke71d.mjs +0 -66
  430. package/dist/_chunks/fr-3S6ke71d.mjs.map +0 -1
  431. package/dist/_chunks/fr-BTjekDpq.js +0 -66
  432. package/dist/_chunks/fr-BTjekDpq.js.map +0 -1
  433. package/dist/_chunks/index-7_EUScSl.mjs +0 -1614
  434. package/dist/_chunks/index-7_EUScSl.mjs.map +0 -1
  435. package/dist/_chunks/index-BGtXLYX-.js +0 -1636
  436. package/dist/_chunks/index-BGtXLYX-.js.map +0 -1
  437. package/dist/_chunks/ko-DmcGUBQ3.js +0 -65
  438. package/dist/_chunks/ko-DmcGUBQ3.js.map +0 -1
  439. package/dist/_chunks/ko-qTjQ8IMw.mjs +0 -65
  440. package/dist/_chunks/ko-qTjQ8IMw.mjs.map +0 -1
  441. package/dist/_chunks/pl-B67TSHqT.mjs +0 -66
  442. package/dist/_chunks/pl-B67TSHqT.mjs.map +0 -1
  443. package/dist/_chunks/pl-Cn5RYonZ.js +0 -66
  444. package/dist/_chunks/pl-Cn5RYonZ.js.map +0 -1
  445. package/dist/_chunks/ru-BMBgVL3s.js +0 -68
  446. package/dist/_chunks/ru-BMBgVL3s.js.map +0 -1
  447. package/dist/_chunks/ru-hagMa57T.mjs +0 -68
  448. package/dist/_chunks/ru-hagMa57T.mjs.map +0 -1
  449. package/dist/_chunks/tr-CarUU76c.js +0 -66
  450. package/dist/_chunks/tr-CarUU76c.js.map +0 -1
  451. package/dist/_chunks/tr-Dw_jmkG-.mjs +0 -66
  452. package/dist/_chunks/tr-Dw_jmkG-.mjs.map +0 -1
  453. package/dist/_chunks/zh-57YM4amO.mjs +0 -66
  454. package/dist/_chunks/zh-57YM4amO.mjs.map +0 -1
  455. package/dist/_chunks/zh-CukOviB0.js +0 -66
  456. package/dist/_chunks/zh-CukOviB0.js.map +0 -1
  457. package/dist/_chunks/zh-Hans-DSHIXAa3.js +0 -57
  458. package/dist/_chunks/zh-Hans-DSHIXAa3.js.map +0 -1
  459. package/dist/_chunks/zh-Hans-Dyc-aR-h.mjs +0 -57
  460. package/dist/_chunks/zh-Hans-Dyc-aR-h.mjs.map +0 -1
@@ -0,0 +1,268 @@
1
+ 'use strict';
2
+
3
+ var utils = require('@strapi/utils');
4
+ var index = require('../utils/index.js');
5
+
6
+ const isLocalizedAttribute = (attribute)=>{
7
+ return attribute?.pluginOptions?.i18n?.localized === true;
8
+ };
9
+ const createAILocalizationsService = ({ strapi })=>{
10
+ // TODO: add a helper function to get the AI server URL
11
+ const aiServerUrl = process.env.STRAPI_AI_URL || 'https://strapi-ai.apps.strapi.io';
12
+ const aiLocalizationJobsService = index.getService('ai-localization-jobs');
13
+ const UNSUPPORTED_ATTRIBUTE_TYPES = [
14
+ 'media',
15
+ 'relation',
16
+ 'boolean'
17
+ ];
18
+ const IGNORED_FIELDS = [
19
+ 'id',
20
+ 'documentId',
21
+ 'createdAt',
22
+ 'updatedAt',
23
+ 'updatedBy',
24
+ 'localizations'
25
+ ];
26
+ return {
27
+ // Async to avoid changing the signature later (there will be a db check in the future)
28
+ async isEnabled () {
29
+ // Check if user disabled AI features globally
30
+ const isAIEnabled = strapi.config.get('admin.ai.enabled', true);
31
+ if (!isAIEnabled) {
32
+ return false;
33
+ }
34
+ // Check if the user's license grants access to AI features
35
+ const hasAccess = strapi.ee.features.isEnabled('cms-ai');
36
+ if (!hasAccess) {
37
+ return false;
38
+ }
39
+ const settings = index.getService('settings');
40
+ const aiSettings = await settings.getSettings();
41
+ if (!aiSettings?.aiLocalizations) {
42
+ return false;
43
+ }
44
+ return true;
45
+ },
46
+ /**
47
+ * Checks if there are localizations that need to be generated for the given document,
48
+ * and if so, calls the AI service and saves the results to the database.
49
+ * Works for both single and collection types, on create and update.
50
+ */ async generateDocumentLocalizations ({ model, document }) {
51
+ const isFeatureEnabled = await this.isEnabled();
52
+ if (!isFeatureEnabled) {
53
+ return;
54
+ }
55
+ const schema = strapi.getModel(model);
56
+ const localeService = index.getService('locales');
57
+ // No localizations needed for content types with i18n disabled
58
+ const isLocalizedContentType = index.getService('content-types').isLocalizedContentType(schema);
59
+ if (!isLocalizedContentType) {
60
+ return;
61
+ }
62
+ // Don't trigger localizations if the update is on a derived locale, only do it on the default
63
+ const defaultLocale = await localeService.getDefaultLocale();
64
+ if (document?.locale !== defaultLocale) {
65
+ return;
66
+ }
67
+ const documentId = document.documentId;
68
+ if (!documentId) {
69
+ strapi.log.warn(`AI Localizations: missing documentId for ${schema.uid}`);
70
+ return;
71
+ }
72
+ const localizedRoots = new Set();
73
+ const translateableContent = await utils.traverseEntity(({ key, attribute, parent, path }, { remove })=>{
74
+ if (IGNORED_FIELDS.includes(key)) {
75
+ remove(key);
76
+ return;
77
+ }
78
+ const hasLocalizedOption = attribute && isLocalizedAttribute(attribute);
79
+ if (attribute && UNSUPPORTED_ATTRIBUTE_TYPES.includes(attribute.type)) {
80
+ remove(key);
81
+ return;
82
+ }
83
+ // If this field is localized, keep it (and mark as localized root if component/dz)
84
+ if (hasLocalizedOption) {
85
+ // If it's a component/dynamiczone, add to the set
86
+ if ([
87
+ 'component',
88
+ 'dynamiczone'
89
+ ].includes(attribute.type)) {
90
+ localizedRoots.add(path.raw);
91
+ }
92
+ return; // keep
93
+ }
94
+ if (parent && localizedRoots.has(parent.path.raw)) {
95
+ // If parent exists in the localized roots set, keep it
96
+ // If this is also a component/dz, propagate the localized root flag
97
+ if ([
98
+ 'component',
99
+ 'dynamiczone'
100
+ ].includes(attribute?.type ?? '')) {
101
+ localizedRoots.add(path.raw);
102
+ }
103
+ return; // keep
104
+ }
105
+ // Otherwise, remove the field
106
+ remove(key);
107
+ }, {
108
+ schema,
109
+ getModel: strapi.getModel.bind(strapi)
110
+ }, document);
111
+ if (Object.keys(translateableContent).length === 0) {
112
+ strapi.log.info(`AI Localizations: no translatable content for ${schema.uid} document ${documentId}`);
113
+ return;
114
+ }
115
+ const localesList = await localeService.find();
116
+ const targetLocales = localesList.filter((l)=>l.code !== document.locale).map((l)=>l.code);
117
+ if (targetLocales.length === 0) {
118
+ strapi.log.info(`AI Localizations: no target locales for ${schema.uid} document ${documentId}`);
119
+ return;
120
+ }
121
+ await aiLocalizationJobsService.upsertJobForDocument({
122
+ contentType: model,
123
+ documentId,
124
+ sourceLocale: document.locale,
125
+ targetLocales,
126
+ status: 'processing'
127
+ });
128
+ let token;
129
+ try {
130
+ const tokenData = await strapi.service('admin::user').getAiToken();
131
+ token = tokenData.token;
132
+ } catch (error) {
133
+ await aiLocalizationJobsService.upsertJobForDocument({
134
+ documentId,
135
+ contentType: model,
136
+ sourceLocale: document.locale,
137
+ targetLocales,
138
+ status: 'failed'
139
+ });
140
+ throw new Error('Failed to retrieve AI token', {
141
+ cause: error instanceof Error ? error : undefined
142
+ });
143
+ }
144
+ /**
145
+ * Provide a schema to the LLM so that we can give it instructions about how to handle each
146
+ * type of attribute. Only keep essential schema data to avoid cluttering the context.
147
+ * Ignore fields that don't need to be localized.
148
+ * TODO: also provide a schema of all the referenced components
149
+ */ const minimalContentTypeSchema = Object.fromEntries(Object.entries(schema.attributes)// eslint-disable-next-line @typescript-eslint/no-unused-vars
150
+ .filter(([_, attr])=>{
151
+ const isLocalized = isLocalizedAttribute(attr);
152
+ const isSupportedType = !UNSUPPORTED_ATTRIBUTE_TYPES.includes(attr.type);
153
+ return isLocalized && isSupportedType;
154
+ }).map(([key, attr])=>{
155
+ const minimalAttribute = {
156
+ type: attr.type
157
+ };
158
+ if (attr.type === 'component') {
159
+ minimalAttribute.repeatable = attr.repeatable ?? false;
160
+ }
161
+ return [
162
+ key,
163
+ minimalAttribute
164
+ ];
165
+ }));
166
+ strapi.log.http('Contacting AI Server for localizations generation');
167
+ const response = await fetch(`${aiServerUrl}/i18n/generate-localizations`, {
168
+ method: 'POST',
169
+ headers: {
170
+ 'Content-Type': 'application/json',
171
+ Authorization: `Bearer ${token}`
172
+ },
173
+ body: JSON.stringify({
174
+ content: translateableContent,
175
+ sourceLocale: document.locale,
176
+ targetLocales,
177
+ contentTypeSchema: minimalContentTypeSchema
178
+ })
179
+ });
180
+ if (!response.ok) {
181
+ strapi.log.error(`AI Localizations request failed: ${response.status} ${response.statusText}`);
182
+ await aiLocalizationJobsService.upsertJobForDocument({
183
+ documentId,
184
+ contentType: model,
185
+ sourceLocale: document.locale,
186
+ targetLocales,
187
+ status: 'failed'
188
+ });
189
+ throw new Error(`AI Localizations request failed: ${response.statusText}`);
190
+ }
191
+ const aiResult = await response.json();
192
+ // Get all media field names dynamically from the schema
193
+ const mediaFields = Object.entries(schema.attributes)// eslint-disable-next-line @typescript-eslint/no-unused-vars
194
+ .filter(([_, attr])=>attr.type === 'media').map(([key])=>key);
195
+ try {
196
+ await Promise.all(aiResult.localizations.map(async (localization)=>{
197
+ const { content, locale } = localization;
198
+ // Fetch the derived locale document
199
+ const derivedDoc = await strapi.documents(model).findOne({
200
+ documentId,
201
+ locale,
202
+ populate: mediaFields
203
+ });
204
+ // Merge AI content and media fields, works only on first level media fields (root level)
205
+ const mergedData = structuredClone(content);
206
+ for (const field of mediaFields){
207
+ // Only copy media if not already set in derived locale
208
+ if (!derivedDoc || !derivedDoc[field]) {
209
+ mergedData[field] = document[field];
210
+ } else {
211
+ mergedData[field] = derivedDoc[field];
212
+ }
213
+ }
214
+ await strapi.documents(model).update({
215
+ documentId,
216
+ locale,
217
+ fields: [],
218
+ data: mergedData
219
+ });
220
+ await aiLocalizationJobsService.upsertJobForDocument({
221
+ documentId,
222
+ contentType: model,
223
+ sourceLocale: document.locale,
224
+ targetLocales,
225
+ status: 'completed'
226
+ });
227
+ }));
228
+ } catch (error) {
229
+ await aiLocalizationJobsService.upsertJobForDocument({
230
+ documentId,
231
+ contentType: model,
232
+ sourceLocale: document.locale,
233
+ targetLocales,
234
+ status: 'failed'
235
+ });
236
+ strapi.log.error('AI Localizations generation failed', error);
237
+ }
238
+ },
239
+ setupMiddleware () {
240
+ strapi.documents.use(async (context, next)=>{
241
+ const result = await next();
242
+ // Only trigger for the allowed actions
243
+ if (![
244
+ 'create',
245
+ 'update'
246
+ ].includes(context.action)) {
247
+ return result;
248
+ }
249
+ // Check if AI localizations are enabled before triggering
250
+ const isEnabled = await this.isEnabled();
251
+ if (!isEnabled) {
252
+ return result;
253
+ }
254
+ // Don't await since localizations should be done in the background without blocking the request
255
+ strapi.plugin('i18n').service('ai-localizations').generateDocumentLocalizations({
256
+ model: context.contentType.uid,
257
+ document: result
258
+ }).catch((error)=>{
259
+ strapi.log.error('AI Localizations generation failed', error);
260
+ });
261
+ return result;
262
+ });
263
+ }
264
+ };
265
+ };
266
+
267
+ exports.createAILocalizationsService = createAILocalizationsService;
268
+ //# sourceMappingURL=ai-localizations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-localizations.js","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","result","action","plugin","catch"],"mappings":";;;;;AAIA,MAAMA,uBAAuB,CAACC,SAAAA,GAAAA;AAC5B,IAAA,OAAO,SAACA,EAAWC,aAAuBC,EAAAA,IAAAA,EAAMC,SAAc,KAAA,IAAA;AAChE,CAAA;AAEA,MAAMC,4BAA+B,GAAA,CAAC,EAAEC,MAAM,EAA2B,GAAA;;AAEvE,IAAA,MAAMC,WAAcC,GAAAA,OAAAA,CAAQC,GAAG,CAACC,aAAa,IAAI,kCAAA;AACjD,IAAA,MAAMC,4BAA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G;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;;;;"}
@@ -0,0 +1,266 @@
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
+ };
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
+ ];
24
+ return {
25
+ // Async to avoid changing the signature later (there will be a db check in the future)
26
+ async isEnabled () {
27
+ // Check if user disabled AI features globally
28
+ const isAIEnabled = strapi.config.get('admin.ai.enabled', true);
29
+ if (!isAIEnabled) {
30
+ return false;
31
+ }
32
+ // Check if the user's license grants access to AI features
33
+ const hasAccess = strapi.ee.features.isEnabled('cms-ai');
34
+ if (!hasAccess) {
35
+ return false;
36
+ }
37
+ const settings = getService('settings');
38
+ const aiSettings = await settings.getSettings();
39
+ if (!aiSettings?.aiLocalizations) {
40
+ return false;
41
+ }
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
+ });
261
+ }
262
+ };
263
+ };
264
+
265
+ export { createAILocalizationsService };
266
+ //# sourceMappingURL=ai-localizations.mjs.map
@@ -0,0 +1 @@
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","result","action","plugin","catch"],"mappings":";;;AAIA,MAAMA,uBAAuB,CAACC,SAAAA,GAAAA;AAC5B,IAAA,OAAO,SAACA,EAAWC,aAAuBC,EAAAA,IAAAA,EAAMC,SAAc,KAAA,IAAA;AAChE,CAAA;AAEA,MAAMC,4BAA+B,GAAA,CAAC,EAAEC,MAAM,EAA2B,GAAA;;AAEvE,IAAA,MAAMC,WAAcC,GAAAA,OAAAA,CAAQC,GAAG,CAACC,aAAa,IAAI,kCAAA;AACjD,IAAA,MAAMC,4BAA4BC,UAAW,CAAA,sBAAA,CAAA;AAE7C,I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