@nocode-factory/sanity-kit 2.65.0-rc.7 → 2.66.0-rc.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.
@@ -1,63 +1,36 @@
1
1
  import {useCallback, useState} from 'react'
2
- import {Box, Button, Card, Checkbox, Dialog, Flex, Spinner, Stack, Text} from '@sanity/ui'
2
+ import {Box, Button, Card, Dialog, Flex, Spinner, Stack, Text} from '@sanity/ui'
3
3
  import {useSchema} from 'sanity'
4
4
  import {TranslateIcon} from '@sanity/icons/Translate'
5
5
  import {useKitConfig} from '../../context/KitContext'
6
6
  import {useKitClient} from '../../hooks/useKitClient'
7
7
  import type {SchemaTypeLike} from '../../lib/propagate'
8
- import {createTranslatedVersion, fillTranslation, retryTranslatedVersion, untranslatedPaths} from '../../lib/translateDocument'
9
- import {readTrace, recordTrace} from '../../lib/translationTrace'
10
- import {valueAtKey} from '../../lib/aiTexts'
8
+ import {createTranslatedVersion, fillTranslation, untranslatedPaths} from '../../lib/translateDocument'
9
+ import {recordTrace} from '../../lib/translationTrace'
11
10
  import {BOARD_LAYOUT_TYPE} from '../../schema/boardLayout'
12
11
  import {TRANSLATION_TODO_TYPE} from '../../schema/translationTodo'
13
12
 
14
13
  type Doc = Record<string, unknown>
15
- type Source = {_id: string; _type: string; title?: string}
16
- type Todo = {documentId: string; sourceId: string; sourceLanguage: string; paths: string[]; language?: string; title?: string}
17
14
 
18
15
  interface Plan {
19
16
  /** Documents de la langue principale sans version dans une langue. */
20
- missing: {language: string; docs: Source[]}[]
21
- /** Versions traduites inachevées (textes « To translate » : échec de l'IA, texte gardé...). */
22
- unfinished: Todo[]
23
- /** Versions traduites qui n'existent qu'en brouillon (à relire puis publier). */
24
- drafts: {language: string; count: number}[]
17
+ missing: {language: string; docs: {_id: string; _type: string}[]}[]
25
18
  /** Valeurs par défaut des composants : document absent, ou textes à traduire, par langue. */
26
19
  defaults: {language: string; exists: boolean; texts: number; from: string}[]
27
20
  }
28
21
 
29
- /** Ligne du compte rendu : réussite, à relire, ou échec AVEC sa raison. */
30
- type Line = {tone: 'positive' | 'caution' | 'critical'; text: string}
31
-
32
22
  const EXCLUDED = ['translation.metadata', BOARD_LAYOUT_TYPE, TRANSLATION_TODO_TYPE]
33
- const TITLE = 'coalesce(title, name, heading, internalName, slug.current, _id)'
34
-
35
- /** Nom lisible d'une version inachevée (les valeurs par défaut n'ont pas de titre). */
36
- const label = (t: Todo) => (/componentDefaults/.test(t.documentId) || /componentDefaults/.test(t.title ?? '') ? 'Component defaults' : (t.title ?? t.documentId).replace(/^drafts\./, ''))
37
-
38
- /** Erreur lisible pour l'équipe (le service renvoie parfois un message technique). */
39
- function explain(error: string): string {
40
- const e = error.toLowerCase()
41
- if (/401|403|unauthori|forbidden|key/.test(e)) return `${error} (kit project key: run \`npx ncf-kit setup\`)`
42
- if (/429|rate|quota|limit/.test(e)) return `${error} (AI service busy or quota reached: retry in a few minutes)`
43
- if (/timeout|timed out|network|fetch|50\d/.test(e)) return `${error} (AI service unreachable: retry in a few minutes)`
44
- if (/too (long|large)|length|token/.test(e)) return `${error} (text too long for one request: translate this field by hand)`
45
- return error
46
- }
47
23
 
48
24
  /**
49
25
  * Langues du site : met chaque langue au niveau de la langue principale, en UN clic
50
- * explicite (jamais tout seul). Utile à l'ajout d'une langue et après l'ajout d'un
51
- * composant (valeurs par défaut traduites dans chaque langue).
52
- * - On choisit ce qu'on traduit (documents manquants, traductions inachevées, valeurs
53
- * par défaut des composants) et, par défaut, tout est enregistré en BROUILLON à relire
54
- * (kit >= 2.65.0) : une traduction de l'IA n'est publiée sans relecture que si on coche
55
- * « Publish right away ».
56
- * - Chaque échec est listé avec sa raison ; une version inachevée (échec de l'IA) est
57
- * détectée et reprise par « Retry » (seulement ses textes à traduire).
58
- * - Valeurs par défaut : seuls les textes vides ou restés identiques au texte source sont
59
- * traduits (jamais un texte traduit à la main) ; un texte que l'IA a rendu à l'identique
60
- * (nom propre, marque) n'est plus reproposé.
26
+ * explicite (jamais tout seul). Utile à l'ajout d'une langue (« de » : toutes les
27
+ * pages en allemand) et après l'ajout d'un composant (valeurs par défaut traduites
28
+ * dans chaque langue).
29
+ * - Documents : chaque document publié de la langue principale sans version dans
30
+ * une langue reçoit sa version, traduite par l'IA, publiée et reliée.
31
+ * - Valeurs par défaut des composants : langue source (anglais en général), puis
32
+ * chaque langue ; un document absent est créé ; seuls les textes vides ou restés
33
+ * identiques au texte source sont traduits (jamais un texte traduit à la main).
61
34
  */
62
35
  export function LanguagesSync() {
63
36
  const config = useKitConfig()
@@ -67,9 +40,7 @@ export function LanguagesSync() {
67
40
  const [plan, setPlan] = useState<Plan | null>(null)
68
41
  const [busy, setBusy] = useState(false)
69
42
  const [progress, setProgress] = useState<string | null>(null)
70
- const [report, setReport] = useState<Line[] | null>(null)
71
- const [pick, setPick] = useState({missing: true, unfinished: true, defaults: true})
72
- const [publishNow, setPublishNow] = useState(false)
43
+ const [report, setReport] = useState<string[] | null>(null)
73
44
  const i18n = config.i18n
74
45
  const field = i18n?.field ?? 'language'
75
46
  const defaultsType = config.componentPreview.defaultsType
@@ -78,10 +49,10 @@ export function LanguagesSync() {
78
49
  const analyse = useCallback(async () => {
79
50
  if (!i18n) return
80
51
  setPlan(null)
52
+ setReport(null)
81
53
  const main = i18n.defaultLocale
82
- const others = i18n.locales.filter((l) => l !== main)
83
- const sources = await client.fetch<Source[]>(
84
- `*[defined(${field}) && ${field} == $main && !(_id in path("drafts.**")) && !(_type in $excluded)]{_id, _type, "title": ${TITLE}}`,
54
+ const sources = await client.fetch<{_id: string; _type: string}[]>(
55
+ `*[defined(${field}) && ${field} == $main && !(_id in path("drafts.**")) && !(_type in $excluded)]{_id, _type}`,
85
56
  {main, excluded: [...EXCLUDED, defaultsType]},
86
57
  )
87
58
  const metas = await client.fetch<{refs: {lang?: string; id?: string}[] | null}[]>(
@@ -92,181 +63,114 @@ export function LanguagesSync() {
92
63
  const langs = new Set((m.refs ?? []).map((r) => r.lang ?? ''))
93
64
  for (const r of m.refs ?? []) if (r.id) langsOf.set(r.id, langs)
94
65
  }
66
+ const others = i18n.locales.filter((l) => l !== main)
95
67
  const missing = others.map((language) => ({language, docs: sources.filter((d) => !langsOf.get(d._id)?.has(language))}))
96
68
 
97
- // Versions traduites inachevées : liste « To translate » non vide.
98
- const unfinished = await client.fetch<Todo[]>(
99
- `*[_type == $todo && count(paths) > 0]{documentId, sourceId, sourceLanguage, paths,
100
- "version": coalesce(*[_id == "drafts." + ^.documentId][0], *[_id == ^.documentId][0]){"language": ${field}, "title": ${TITLE}}}
101
- {documentId, sourceId, sourceLanguage, paths, "language": version.language, "title": version.title}`,
102
- {todo: TRANSLATION_TODO_TYPE},
103
- )
104
- // Versions qui n'existent qu'en brouillon (traduites, pas encore publiées).
105
- const draftOnly = await client.fetch<{language: string}[]>(
106
- `*[_id in path("drafts.**") && ${field} in $others && !(_type in $excluded) && !defined(*[_id == string::split(^._id, "drafts.")[1]][0]._id)]{"language": ${field}}`,
107
- {others, excluded: EXCLUDED},
108
- )
109
- const drafts = others.map((language) => ({language, count: draftOnly.filter((d) => d.language === language).length})).filter((d) => d.count)
110
-
111
69
  const defaultsDocs = await client.fetch<Doc[]>(`*[_type == $type && !(_id in path("drafts.**"))]`, {type: defaultsType})
112
- const defaultsDrafts = await client.fetch<Doc[]>(`*[_type == $type && _id in path("drafts.**")]`, {type: defaultsType})
113
70
  const byLang = (lang: string) => defaultsDocs.find((d) => d[field] === lang) ?? null
114
- // Version à compléter : le brouillon s'il existe (une traduction en cours de relecture
115
- // n'est plus « à traduire »), sans les textes déjà repris par « Unfinished translations ».
116
- const currentOf = (doc: Doc) => defaultsDrafts.find((d) => d._id === `drafts.${String(doc._id)}`) ?? doc
117
- const inTodo = (doc: Doc) => new Set(unfinished.filter((t) => t.documentId === String(doc._id)).flatMap((t) => t.paths))
118
71
  const sourceLang = byLang(i18n.defaultsSourceLocale) ? i18n.defaultsSourceLocale : main
119
72
  const sourceDoc = byLang(sourceLang)
120
73
  const mainDoc = byLang(main)
121
74
  const defaults: Plan['defaults'] = []
122
- // 1. Un nouveau composant est rempli dans la langue principale : la langue source
123
- // (anglais) est d'abord complétée depuis elle.
75
+ // 1. Un nouveau composant est rempli dans la langue principale (démo, pages) :
76
+ // la langue source (anglais) est d'abord complétée depuis elle.
124
77
  if (sourceDoc && mainDoc && sourceLang !== main) {
125
- const trace = await readTrace(client, String(sourceDoc._id))
126
- const pending = inTodo(sourceDoc)
127
- const texts = untranslatedPaths(mainDoc, currentOf(sourceDoc), typeOf(defaultsType), trace).filter((p) => !pending.has(p)).length
78
+ const texts = untranslatedPaths(mainDoc, sourceDoc, typeOf(defaultsType)).length
128
79
  if (texts) defaults.push({language: sourceLang, exists: true, texts, from: main})
129
80
  }
130
81
  // 2. Puis chaque autre langue depuis la langue source.
131
82
  if (sourceDoc)
132
83
  for (const language of i18n.locales.filter((l) => l !== sourceLang)) {
133
84
  const doc = byLang(language)
134
- const trace = doc ? await readTrace(client, String(doc._id)) : undefined
135
- const pending = doc ? inTodo(doc) : new Set<string>()
136
- const texts = untranslatedPaths(sourceDoc, doc ? currentOf(doc) : null, typeOf(defaultsType), trace).filter((p) => !pending.has(p)).length
137
- defaults.push({language, exists: Boolean(doc), texts, from: sourceLang})
85
+ defaults.push({language, exists: Boolean(doc), texts: untranslatedPaths(sourceDoc, doc, typeOf(defaultsType)).length, from: sourceLang})
138
86
  }
139
- setPlan({missing, unfinished, drafts, defaults})
87
+ setPlan({missing, defaults})
140
88
  }, [client, defaultsType, field, i18n]) // eslint-disable-line react-hooks/exhaustive-deps
141
89
 
142
90
  const run = async () => {
143
91
  if (!plan || !i18n) return
144
92
  setBusy(true)
145
- setReport(null)
146
- const lines: Line[] = []
147
- const fail = (what: string, error: string) => lines.push({tone: 'critical', text: `${what}: ${explain(error)}`})
93
+ const lines: string[] = []
148
94
  try {
149
95
  // 1. Documents manquants (pages, collections, réglages par langue).
150
- if (pick.missing) {
151
- const total = plan.missing.reduce((n, m) => n + m.docs.length, 0)
152
- let n = 0
153
- for (const m of plan.missing) {
154
- let published = 0
155
- let review = 0
156
- for (const d of m.docs) {
157
- n++
158
- setProgress(`Documents ${n}/${total} (${m.language.toUpperCase()})`)
159
- const what = `${m.language.toUpperCase()} « ${d.title ?? d._id} »`
160
- try {
161
- const source = await client.getDocument<Doc>(d._id)
162
- if (!source) {
163
- fail(what, 'source version not found')
164
- continue
165
- }
166
- const created = await createTranslatedVersion({
167
- client,
168
- config,
169
- type: d._type,
170
- schemaType: typeOf(d._type),
171
- source,
172
- sourceId: d._id,
173
- sourceLanguage: i18n.defaultLocale,
174
- language: m.language,
175
- ai: true,
176
- publish: publishNow,
177
- })
178
- if (created.published) published++
179
- else if (created.complete) review++
180
- else if (created.aiError) fail(what, `AI translation failed, saved as a draft with ${created.remaining.length} text(s) to translate. ${created.aiError}`)
181
- else fail(what, `${created.remaining.length} text(s) not translated, saved as a draft (marked "To translate")`)
182
- } catch (cause) {
183
- fail(what, cause instanceof Error ? cause.message : String(cause))
184
- }
185
- }
186
- if (published) lines.push({tone: 'positive', text: `${m.language.toUpperCase()}: ${published} document(s) translated and published`})
187
- if (review) lines.push({tone: 'caution', text: `${m.language.toUpperCase()}: ${review} document(s) translated as drafts, to review then publish`})
188
- }
189
- }
190
- // 2. Traductions inachevées : on reprend seulement leurs textes à traduire.
191
- if (pick.unfinished)
192
- for (const [n, t] of plan.unfinished.entries()) {
193
- setProgress(`Unfinished translations ${n + 1}/${plan.unfinished.length}`)
194
- const what = `${(t.language ?? '').toUpperCase()} « ${label(t)} »`
195
- if (!t.language) {
196
- fail(what, 'language of the translated version unknown')
197
- continue
198
- }
199
- const r = await retryTranslatedVersion({client, config, todo: t, language: t.language, publish: publishNow})
200
- if (r.aiError) fail(what, `still ${r.remaining.length} text(s) to translate. ${r.aiError}`)
201
- else if (r.remaining.length) fail(what, `${r.remaining.length} text(s) could not be placed (field changed since): translate them by hand`)
202
- else lines.push({tone: r.published ? 'positive' : 'caution', text: `${what}: completed${r.published ? ' and published' : ', draft to review then publish'}`})
203
- }
204
- // 3. Valeurs par défaut des composants.
205
- if (pick.defaults)
206
- for (const d of plan.defaults) {
207
- if (d.exists && !d.texts) continue
208
- const what = `Component defaults ${d.language.toUpperCase()}`
96
+ const total = plan.missing.reduce((n, m) => n + m.docs.length, 0)
97
+ let n = 0
98
+ for (const m of plan.missing) {
99
+ let ok = 0
100
+ let drafts = 0
101
+ for (const d of m.docs) {
102
+ n++
103
+ setProgress(`Documents ${n}/${total} (${m.language.toUpperCase()})`)
104
+ const source = await client.getDocument<Doc>(d._id)
105
+ if (!source) continue
209
106
  try {
210
- // Relu à chaque étape : l'étape précédente vient peut-être de compléter la source.
211
- const src = await client.fetch<Doc | null>(`*[_type == $type && ${field} == $lang && !(_id in path("drafts.**"))][0]`, {type: defaultsType, lang: d.from})
212
- if (!src) continue
213
- setProgress(`${what}`)
214
- if (!d.exists) {
215
- const created = await createTranslatedVersion({
216
- client,
217
- config,
218
- type: defaultsType,
219
- schemaType: typeOf(defaultsType),
220
- source: src,
221
- sourceId: String(src._id),
222
- sourceLanguage: d.from,
223
- language: d.language,
224
- ai: true,
225
- publish: publishNow,
226
- })
227
- if (created.aiError) fail(what, `AI translation failed, created as a draft. ${created.aiError}`)
228
- else lines.push({tone: created.published ? 'positive' : 'caution', text: `${what}: created${created.published ? ' and published' : ' as a draft, to review then publish'}`})
229
- continue
230
- }
231
- const published = await client.fetch<Doc | null>(`*[_type == $type && ${field} == $lang && !(_id in path("drafts.**"))][0]`, {type: defaultsType, lang: d.language})
232
- if (!published) continue
233
- const id = String(published._id)
234
- // Brouillon : complété depuis le brouillon en cours s'il existe (rien n'est défait).
235
- const base = (await client.getDocument<Doc>(`drafts.${id}`)) ?? published
236
- const filled = await fillTranslation({
107
+ const created = await createTranslatedVersion({
108
+ client,
237
109
  config,
238
- schemaType: typeOf(defaultsType),
239
- source: src,
240
- target: base,
241
- sourceLanguage: d.from,
242
- language: d.language,
243
- trace: await readTrace(client, id),
244
- })
245
- const {_rev, _updatedAt, _createdAt, ...doc} = filled.document
246
- const tx = client.transaction()
247
- if (publishNow) {
248
- tx.createOrReplace({...doc, _id: id} as {_id: string; _type: string})
249
- tx.delete(`drafts.${id}`)
250
- } else tx.createOrReplace({...doc, _id: `drafts.${id}`} as {_id: string; _type: string})
251
- await tx.commit()
252
- await recordTrace(client, id, filled.written, {sourceId: String(src._id), sourceLanguage: d.from})
253
- // Textes rendus à l'identique par l'IA (noms propres, marques) : signalés à vérifier.
254
- const unchanged = filled.written.filter((w) => JSON.stringify(w.value) === JSON.stringify(valueAtKey(src, w.path))).length
255
- if (filled.error) fail(what, `${filled.error} The other texts were kept; retry to translate the rest.`)
256
- lines.push({
257
- tone: publishNow ? 'positive' : 'caution',
258
- text: `${what}: ${filled.translated} text(s) translated${publishNow ? ' and published' : ' in the draft, to review then publish'}${unchanged ? ` (${unchanged} kept identical by the AI: names, brands... check them)` : ''}`,
110
+ type: d._type,
111
+ schemaType: typeOf(d._type),
112
+ source,
113
+ sourceId: d._id,
114
+ sourceLanguage: i18n.defaultLocale,
115
+ language: m.language,
116
+ ai: true,
259
117
  })
118
+ if (created.published) ok++
119
+ else drafts++
260
120
  } catch (cause) {
261
- fail(what, cause instanceof Error ? cause.message : String(cause))
121
+ lines.push(`${m.language.toUpperCase()} ${d._id}: ${cause instanceof Error ? cause.message : String(cause)}`)
262
122
  }
263
123
  }
124
+ if (m.docs.length) lines.unshift(`${m.language.toUpperCase()}: ${ok} published${drafts ? `, ${drafts} saved as drafts (texts to translate)` : ''}`)
125
+ }
126
+ // 2. Valeurs par défaut des composants.
127
+ for (const d of plan.defaults) {
128
+ if (d.exists && !d.texts) continue
129
+ // Relu à chaque étape : l'étape 1 vient peut-être de compléter la source.
130
+ const src = await client.fetch<Doc | null>(`*[_type == $type && ${field} == $lang && !(_id in path("drafts.**"))][0]`, {type: defaultsType, lang: d.from})
131
+ if (!src) continue
132
+ const sourceLang = d.from
133
+ setProgress(`Component defaults (${d.language.toUpperCase()})`)
134
+ if (!d.exists) {
135
+ await createTranslatedVersion({
136
+ client,
137
+ config,
138
+ type: defaultsType,
139
+ schemaType: typeOf(defaultsType),
140
+ source: src,
141
+ sourceId: String(src._id),
142
+ sourceLanguage: sourceLang,
143
+ language: d.language,
144
+ ai: true,
145
+ })
146
+ lines.push(`Component defaults ${d.language.toUpperCase()}: created`)
147
+ continue
148
+ }
149
+ const target = await client.fetch<Doc | null>(`*[_type == $type && ${field} == $lang && !(_id in path("drafts.**"))][0]`, {
150
+ type: defaultsType,
151
+ lang: d.language,
152
+ })
153
+ if (!target) continue
154
+ const filled = await fillTranslation({config, schemaType: typeOf(defaultsType), source: src, target, sourceLanguage: sourceLang, language: d.language})
155
+ const {_rev, _updatedAt, _createdAt, ...doc} = filled.document
156
+ const tx = client.transaction().createOrReplace(doc as {_id: string; _type: string})
157
+ // Brouillon en cours : complété aussi, pour que sa publication ne défasse rien.
158
+ const draft = await client.getDocument<Doc>(`drafts.${String(target._id)}`)
159
+ if (draft) {
160
+ const fd = await fillTranslation({config, schemaType: typeOf(defaultsType), source: src, target: draft, sourceLanguage: sourceLang, language: d.language})
161
+ const {_rev: r2, _updatedAt: u2, _createdAt: c2, ...dd} = fd.document
162
+ tx.createOrReplace(dd as {_id: string; _type: string})
163
+ }
164
+ await tx.commit()
165
+ await recordTrace(client, String(target._id), filled.written, {sourceId: String(src._id), sourceLanguage: sourceLang})
166
+ lines.push(`Component defaults ${d.language.toUpperCase()}: ${filled.translated} text${filled.translated > 1 ? 's' : ''} translated`)
167
+ }
264
168
  } catch (cause) {
265
- fail('Stopped', cause instanceof Error ? cause.message : String(cause))
169
+ lines.push(`Stopped: ${cause instanceof Error ? cause.message : String(cause)}`)
266
170
  } finally {
267
171
  setBusy(false)
268
172
  setProgress(null)
269
- setReport(lines.length ? lines : [{tone: 'positive', text: 'Everything was already up to date.'}])
173
+ setReport(lines.length ? lines : ['Everything was already up to date.'])
270
174
  void analyse()
271
175
  }
272
176
  }
@@ -274,17 +178,6 @@ export function LanguagesSync() {
274
178
  if (!i18n || !config.history) return null
275
179
  const pendingDocs = plan?.missing.reduce((n, m) => n + m.docs.length, 0) ?? 0
276
180
  const pendingDefaults = plan?.defaults.filter((d) => !d.exists || d.texts).length ?? 0
277
- const pendingUnfinished = plan?.unfinished.length ?? 0
278
- const selected = (pick.missing && pendingDocs) || (pick.unfinished && pendingUnfinished) || (pick.defaults && pendingDefaults)
279
- const failures = report?.filter((l) => l.tone === 'critical').length ?? 0
280
- const option = (key: keyof typeof pick, label: string, count: number) => (
281
- <Flex as="label" align="center" gap={2}>
282
- <Checkbox checked={pick[key] && count > 0} disabled={!count || busy} onChange={() => setPick({...pick, [key]: !pick[key]})} />
283
- <Text size={1} muted={!count}>
284
- {label}
285
- </Text>
286
- </Flex>
287
- )
288
181
 
289
182
  return (
290
183
  <>
@@ -296,7 +189,6 @@ export function LanguagesSync() {
296
189
  padding={2}
297
190
  onClick={() => {
298
191
  setOpen(true)
299
- setReport(null)
300
192
  void analyse()
301
193
  }}
302
194
  />
@@ -304,9 +196,9 @@ export function LanguagesSync() {
304
196
  <Dialog id="ncf-languages" header="Languages" width={1} onClose={() => !busy && setOpen(false)}>
305
197
  <Stack gap={4} padding={4}>
306
198
  <Text size={1} muted>
307
- Brings every language to the level of the main language ({i18n.defaultLocale.toUpperCase()}) with AI translation.
308
- Translations are saved as drafts to review, unless you choose to publish them right away. Texts already translated
309
- (even by hand) are never changed.
199
+ Brings every language to the level of the main language ({i18n.defaultLocale.toUpperCase()}): missing pages and
200
+ documents are created, translated with AI and published; component defaults are translated from{' '}
201
+ {i18n.defaultsSourceLocale.toUpperCase()}. Texts already translated (even by hand) are never changed.
310
202
  </Text>
311
203
  {!plan ? (
312
204
  <Flex align="center" gap={2}>
@@ -324,27 +216,6 @@ export function LanguagesSync() {
324
216
  </Text>
325
217
  </Card>
326
218
  ))}
327
- {plan.unfinished.length > 0 && (
328
- <Card padding={3} radius={2} border tone="critical">
329
- <Stack gap={2}>
330
- <Text size={1} weight="semibold">
331
- {plan.unfinished.length} unfinished translation{plan.unfinished.length > 1 ? 's' : ''} (texts still to translate)
332
- </Text>
333
- {plan.unfinished.slice(0, 8).map((t) => (
334
- <Text key={t.documentId} size={1} muted>
335
- {(t.language ?? '').toUpperCase()} « {label(t)} »: {t.paths.length} text{t.paths.length > 1 ? 's' : ''}
336
- </Text>
337
- ))}
338
- </Stack>
339
- </Card>
340
- )}
341
- {plan.drafts.map((d) => (
342
- <Card key={`dr-${d.language}`} padding={3} radius={2} border tone="caution">
343
- <Text size={1}>
344
- {d.language.toUpperCase()}: {d.count} translated version{d.count > 1 ? 's' : ''} only in draft, not online yet (review then publish)
345
- </Text>
346
- </Card>
347
- ))}
348
219
  {plan.defaults.map((d) => (
349
220
  <Card key={`d-${d.language}`} padding={3} radius={2} border tone={!d.exists || d.texts ? 'caution' : 'positive'}>
350
221
  <Text size={1}>
@@ -353,20 +224,6 @@ export function LanguagesSync() {
353
224
  </Text>
354
225
  </Card>
355
226
  ))}
356
- <Stack gap={2}>
357
- <Text size={1} weight="semibold">
358
- Translate
359
- </Text>
360
- {option('missing', `Missing documents (${pendingDocs})`, pendingDocs)}
361
- {option('unfinished', `Unfinished translations, retry (${pendingUnfinished})`, pendingUnfinished)}
362
- {option('defaults', `Component defaults (${pendingDefaults} language${pendingDefaults > 1 ? 's' : ''})`, pendingDefaults)}
363
- <Box paddingTop={2}>
364
- <Flex as="label" align="center" gap={2}>
365
- <Checkbox checked={publishNow} disabled={busy} onChange={() => setPublishNow(!publishNow)} />
366
- <Text size={1}>Publish right away, without review (otherwise: drafts to review then publish)</Text>
367
- </Flex>
368
- </Box>
369
- </Stack>
370
227
  </Stack>
371
228
  )}
372
229
  {progress && (
@@ -376,27 +233,26 @@ export function LanguagesSync() {
376
233
  </Flex>
377
234
  )}
378
235
  {report && (
379
- <Stack gap={2}>
380
- {failures > 0 && (
381
- <Text size={1} weight="semibold">
382
- {failures} item{failures > 1 ? 's' : ''} failed: the reason is given for each. Fix it if needed, then retry (unfinished translations are kept and listed above).
383
- </Text>
384
- )}
385
- {report.map((line, i) => (
386
- <Card key={i} padding={3} radius={2} tone={line.tone}>
387
- <Text size={1}>{line.text}</Text>
388
- </Card>
389
- ))}
390
- </Stack>
236
+ <Card padding={3} radius={2} tone="primary">
237
+ <Stack gap={2}>
238
+ {report.map((line, i) => (
239
+ <Text key={i} size={1}>
240
+ {line}
241
+ </Text>
242
+ ))}
243
+ </Stack>
244
+ </Card>
391
245
  )}
392
246
  <Flex justify="flex-end" gap={2}>
393
247
  <Button text="Close" mode="ghost" disabled={busy} onClick={() => setOpen(false)} />
394
- <Button
395
- tone={publishNow ? 'caution' : 'primary'}
396
- text={busy ? 'Working…' : failures && pendingUnfinished ? 'Retry' : publishNow ? 'Translate with AI and publish' : 'Translate with AI (drafts)'}
397
- disabled={busy || !plan || !selected}
398
- onClick={() => void run()}
399
- />
248
+ <Box>
249
+ <Button
250
+ tone="primary"
251
+ text={busy ? 'Working…' : 'Translate with AI and publish'}
252
+ disabled={busy || !plan || (!pendingDocs && !pendingDefaults)}
253
+ onClick={() => void run()}
254
+ />
255
+ </Box>
400
256
  </Flex>
401
257
  </Stack>
402
258
  </Dialog>
package/src/version.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
4
4
  * le vérifie.
5
5
  */
6
- export const KIT_VERSION = '2.65.0-rc.7'
6
+ export const KIT_VERSION = '2.66.0-rc.1'