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