import p from"path";import{DEFAULT_LOCALE_PLACEHOLDER as s,TRANSLATIONS_FILE_NAME as m}from"../../constants/common.js";import{splitArrayAsync as T}from"../../utils/array/split-array-async.js";import{shutdowner as E}from"../../server/tools/shutdowner.js";import{blue as u}from"../../server/tools/notifiers/helpers/colors.js";import{logger as d}from"../../server/tools/notifiers/logger.js";import{reporter as P}from"../../server/tools/notifiers/reporter.js";import{confirmPrompt as _}from"../generate/prompt.js";import{updateTranslations as D}from"./update-translations.js";import{initPlugins as F}from"../../server/plugins/lifecycle.js";const x="default",M=async n=>{const i=n._||[];if(i.length===0)return P.panicOnContentError("Locale is required but was not provided.");const h=p.resolve(n["project-dir"]),{lifecycleContext:e}=await F({outdir:"",contentDir:h,setGlobalConfig:()=>null}),L=(await e.getConfig()).l10n?.defaultLocale?.toLowerCase()||s,r=[s,...e.fs.localeFolders],a=(i[0]==="all"?r:i).map(t=>{const f=t.toLocaleLowerCase()===L||t===x?s:t.toLowerCase(),w=r.find(A=>A.toLocaleLowerCase()===t)||t,C=f===s?m:p.join(e.fs.localizationFolder,w,m);return{systemName:f,providedName:t,filePath:C}}),[l,c]=await T(a,t=>e.fs.exists(t.filePath)),o=["Confirm the following actions:",""];c.length>0&&(o.push("Create new files with translations stubs:"),o.push(...c.map(t=>` - ${u(t.filePath)}`)),o.push("")),l.length>0&&(o.push("Update translations files with missing phrases (this doesn't rewrite existing data values):"),o.push(...l.map(t=>` - ${u(t.filePath)}`)),o.push("")),o.push("Continue? ");const{confirm:g}=await _(o.join(`
`));if(g){const t=d.startTiming();await D(e,a),d.successTime(t,"Success!")}await E.exitWithCode(0)};export{M as generateTranslations};
