import{logger as e}from"../../logger/index.mjs";import{translateJSON as t}from"./translateJSON/index.mjs";import{chunkJSON as n,mergeChunks as r,reconstructFromSingleChunk as i,reduceObjectFormat as a,verifyIdenticObjectFormat as o}from"@intlayer/chokidar/utils";const s=e=>new Promise(t=>setTimeout(t,e)),c=async(e,t=3)=>{try{return await e()}catch(n){if(t<=0)throw n;return await s(2e3),c(e,t-1)}},l=async({content:s,sourceLocale:l,targetLocales:u,aiConfig:d,mode:f=`complete`,dictionaryDescription:p,applicationContext:m})=>{let h=n(s,3e3),g={};for(let n of u){e.info(`Translating to ${n}... (${h.length} chunks)`);let s=[];for(let e of h){let r=i(e),u=a(r,r),h=await c(async()=>{let e=await t({entryFileContent:r,presetOutputContent:u,entryLocale:l,outputLocale:n,mode:f,aiConfig:d,dictionaryDescription:p,applicationContext:m,tags:[]});if(!e?.fileContent)throw Error(`No content returned from AI`);let i=o(e.fileContent,r);if(!i.isIdentic)throw Error(`Format verification failed: ${i.error}`);return e.fileContent});s.push(h)}g[n]=r(s)}return g};export{l as translateDictionaryDB};
//# sourceMappingURL=translateDictionaryDB.mjs.map