@nocode-factory/sanity-kit 2.65.0-rc.3 → 2.65.0-rc.5
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 +25 -0
- package/bin/ncf-kit.mjs +38 -3
- package/bin/translation-audit.mjs +39 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +138 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/actions/PropagatePublish.tsx +25 -1
- package/src/form/TranslationTodoInput.tsx +5 -1
- package/src/lib/linkedTranslations.ts +51 -0
- package/src/lib/propagate.ts +29 -1
- package/src/lib/translateDocument.ts +51 -19
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -27,6 +27,28 @@
|
|
|
27
27
|
textes, un lot refusé est redécoupé jusqu'au texte seul, et les textes traduits sont
|
|
28
28
|
GARDÉS : seuls les ratés restent « To translate » (création, reprise, propagation,
|
|
29
29
|
valeurs par défaut). Une erreur sans remède (quota, clé du kit) s'arrête tout de suite.
|
|
30
|
+
- **Slug jamais « traduit » comme un texte** : une reprise le vidait (vu sur JAF, page
|
|
31
|
+
sans adresse). Il est recalculé depuis le titre traduit, unique dans la langue.
|
|
32
|
+
- **Ancres et valeurs techniques jamais envoyées à l'IA** : ancre d'une section (même sans
|
|
33
|
+
`options.instanceOnly`), ancre de la page visée par un lien, adresse, email, téléphone,
|
|
34
|
+
jeton de couleur, code, chemin ou couleur hexadécimale sont recopiés tels quels. Avant,
|
|
35
|
+
l'IA écrivait « start of school year » dans une ancre (liens du sommaire cassés) et
|
|
36
|
+
envoyait couleur, téléphone et email à traduire (vu sur JAF).
|
|
37
|
+
- **Textes alternatifs des images traduits** (`alt`, légende d'une image qui déclare ses
|
|
38
|
+
champs) : avant, l'image était recopiée entière, alt dans la langue principale.
|
|
39
|
+
- **Source affichée sous un slug « To translate »** : le slug de la version principale (il
|
|
40
|
+
s'affichait « vide »).
|
|
41
|
+
- **`doctor` nomme les pages** sans version ou seulement en brouillon (5 au plus).
|
|
42
|
+
- **Page liée sans version dans la langue** : la fenêtre de propagation le dit AVANT de
|
|
43
|
+
créer la version (« Links to 1 page with no published EN version (« Page cible ») : this
|
|
44
|
+
version can be saved as a draft, but not published until that page is translated »).
|
|
45
|
+
Page volontairement non traduite : dans la version de cette langue, lien de type URL vers
|
|
46
|
+
son adresse (règle « viser exprès une autre langue ») ou lien retiré. Avant, la version se
|
|
47
|
+
créait puis refusait d'être publiée, sans explication (vu sur JAF).
|
|
48
|
+
- **`doctor` : traductions faites avant la 2.65.0**, que la mise à jour ne corrige pas :
|
|
49
|
+
⚠ « ancres traduites » (ancre différente de la version principale, liens cassés) et ⚠
|
|
50
|
+
« textes alternatifs » (identiques à la version principale, donc non traduits), page par
|
|
51
|
+
page. Sur Société Paul Ricard : 47 versions anglaises avec des textes alternatifs en français.
|
|
30
52
|
- **Textes rendus à l'identique par l'IA** (noms propres, marques) : comptés comme
|
|
31
53
|
traduits, plus reproposés sans fin, et signalés « à vérifier » (vu sur JAF : 12 textes).
|
|
32
54
|
- **`doctor`, « Langues : contenus »** : une langue ne compte que si sa version est
|
|
@@ -37,6 +59,9 @@
|
|
|
37
59
|
### À brancher dans le projet
|
|
38
60
|
|
|
39
61
|
- Rien dans le code. Redéployer le Studio (`npm run deploy`).
|
|
62
|
+
- Si `doctor` affiche ⚠ « ancres traduites » ou « textes alternatifs » : reprendre les
|
|
63
|
+
versions traduites qu'il nomme (ancre de la version principale ; texte alternatif traduit),
|
|
64
|
+
relire, publier.
|
|
40
65
|
- CLAUDE.md du starter : rubriques PROPAGATION ET TRADUCTION PAR IA et « Ajouter une
|
|
41
66
|
langue » mises à jour (brouillons à relire, puis publier) ; les reprendre.
|
|
42
67
|
|
package/bin/ncf-kit.mjs
CHANGED
|
@@ -648,22 +648,57 @@ async function doctor() {
|
|
|
648
648
|
const refs = m.refs ?? []
|
|
649
649
|
for (const r of refs) langsOf.set(r.id, refs)
|
|
650
650
|
}
|
|
651
|
+
// Pages nommées dans le message (vu sur JAF : « 1 en brouillon seulement », sans dire laquelle).
|
|
652
|
+
const titled = (await q(`*[_id in $ids]{_id, "title": coalesce(title, name, slug.current, _id)}`, {ids: sources})) ?? []
|
|
653
|
+
const titles = new Map(titled.map((d) => [d._id, d.title]))
|
|
654
|
+
const names = (ids) => `${ids.slice(0, 5).map((id) => `« ${titles.get(id) ?? id} »`).join(', ')}${ids.length > 5 ? `, +${ids.length - 5}` : ''}`
|
|
651
655
|
const status = (id, l) => {
|
|
652
656
|
const ref = (langsOf.get(id) ?? []).find((r) => r.lang === l)
|
|
653
657
|
return !ref ? 'missing' : published.has(ref.id) ? 'online' : 'draft'
|
|
654
658
|
}
|
|
655
659
|
const gaps = locales
|
|
656
660
|
.slice(1)
|
|
657
|
-
.map((l) => [l, sources.filter((id) => status(id, l) === 'missing')
|
|
658
|
-
.filter(([, missing, drafts]) => missing || drafts)
|
|
661
|
+
.map((l) => [l, sources.filter((id) => status(id, l) === 'missing'), sources.filter((id) => status(id, l) === 'draft')])
|
|
662
|
+
.filter(([, missing, drafts]) => missing.length || drafts.length)
|
|
659
663
|
gaps.length
|
|
660
664
|
? ko(
|
|
661
665
|
'Langues : contenus',
|
|
662
666
|
`le kit a besoin que chaque langue ait EN LIGNE toutes les pages de la langue principale (${main.toUpperCase()}) ; ${gaps
|
|
663
|
-
.map(([l, missing, drafts]) => `${l.toUpperCase()} : ${[missing ? `${missing} document(s) sans version` : '', drafts ? `${drafts} en brouillon seulement
|
|
667
|
+
.map(([l, missing, drafts]) => `${l.toUpperCase()} : ${[missing.length ? `${missing.length} document(s) sans version (${names(missing)})` : '', drafts.length ? `${drafts.length} en brouillon seulement, à relire puis publier (${names(drafts)})` : ''].filter(Boolean).join(', ')}`)
|
|
664
668
|
.join(' ; ')} : Studio → Pages → Languages (« Translate with AI », brouillons à relire), puis publier chaque version.`,
|
|
665
669
|
)
|
|
666
670
|
: ok('Langues : contenus', `${sources.length} document(s) ${main.toUpperCase()}, chacun publié dans ${locales.length - 1} autre(s) langue(s)`)
|
|
671
|
+
// Traductions faites avant le kit 2.65.0 : ancres traduites (liens cassés) et
|
|
672
|
+
// textes alternatifs restés dans la langue principale. Une mise à jour du kit ne les
|
|
673
|
+
// corrige pas : on les nomme, page par page, pour que l'équipe les reprenne.
|
|
674
|
+
{
|
|
675
|
+
const {auditTranslation} = await import('./translation-audit.mjs')
|
|
676
|
+
const pairs = []
|
|
677
|
+
for (const m of metas) {
|
|
678
|
+
const refs = m.refs ?? []
|
|
679
|
+
const master = refs.find((r) => r.lang === main)
|
|
680
|
+
if (master) for (const r of refs) if (r.lang !== main && published.has(r.id)) pairs.push([master.id, r.id, r.lang])
|
|
681
|
+
}
|
|
682
|
+
const ids = [...new Set(pairs.flatMap(([a, b]) => [a, b]))].slice(0, 600)
|
|
683
|
+
const docs = ids.length ? ((await q(`*[_id in $ids]`, {ids})) ?? []) : []
|
|
684
|
+
const byId = new Map(docs.map((d) => [d._id, d]))
|
|
685
|
+
const anchorPages = []
|
|
686
|
+
const altPages = []
|
|
687
|
+
for (const [a, b, lang] of pairs) {
|
|
688
|
+
if (!byId.has(a) || !byId.has(b)) continue
|
|
689
|
+
const {anchors, alts} = auditTranslation(byId.get(a), byId.get(b))
|
|
690
|
+
const doc = byId.get(b)
|
|
691
|
+
const label = doc._type === 'componentDefaults' ? 'Component defaults' : (titles.get(a) ?? doc.title ?? b)
|
|
692
|
+
const name = `${lang.toUpperCase()} « ${label} »`
|
|
693
|
+
if (anchors.length) anchorPages.push(`${name} (${anchors.length})`)
|
|
694
|
+
if (alts.length) altPages.push(`${name} (${alts.length})`)
|
|
695
|
+
}
|
|
696
|
+
const list = (pages) => `${pages.slice(0, 6).join(', ')}${pages.length > 6 ? `, +${pages.length - 6}` : ''}`
|
|
697
|
+
if (anchorPages.length)
|
|
698
|
+
warn('Langues : ancres traduites', `${anchorPages.length} version(s) traduite(s) dont une ancre diffère de la version principale (traduite par l'IA avant le kit 2.65.0 : les liens qui la visent sont cassés) : ${list(anchorPages)}. Remettre l'ancre de la version principale, puis republier.`)
|
|
699
|
+
if (altPages.length)
|
|
700
|
+
warn('Langues : textes alternatifs', `${altPages.length} version(s) traduite(s) avec des textes alternatifs d'images identiques à la version principale (non traduits avant le kit 2.65.0 ; un nom propre peut rester identique) : ${list(altPages)}. Les vérifier et les traduire (accessibilité et référencement), puis republier.`)
|
|
701
|
+
}
|
|
667
702
|
// Textes « To translate » en attente (échec de l'IA, texte gardé à la main...).
|
|
668
703
|
const todos = (await q(`*[_type == "ncfTranslationTodo" && count(paths) > 0]{"n": count(paths)}`)) ?? []
|
|
669
704
|
const pending = todos.reduce((n, t) => n + (t.n ?? 0), 0)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Contrôle des traductions faites AVANT le kit 2.65.0 (lu par `doctor`) : une mise à jour du
|
|
2
|
+
// kit ne les corrige pas. Compare une version traduite à sa version principale, élément par
|
|
3
|
+
// élément (mêmes _key) :
|
|
4
|
+
// - ancre (champ « anchor » ou « …Anchor ») DIFFÉRENTE de la version principale : l'IA
|
|
5
|
+
// l'avait traduite (« start of school year »), les liens qui la visent sont cassés ;
|
|
6
|
+
// - texte alternatif d'image (« alt ») IDENTIQUE à la version principale : jamais traduit.
|
|
7
|
+
// Pur (sans réseau), testé dans test/translationAudit.test.ts.
|
|
8
|
+
|
|
9
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v)
|
|
10
|
+
const ANCHOR = /^(anchor|.*Anchor)$/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Écarts d'une version traduite : {anchors: [chemin...], alts: [chemin...]}.
|
|
14
|
+
* Seuls les éléments présents des deux côtés (même chemin, mêmes _key) sont comparés.
|
|
15
|
+
*/
|
|
16
|
+
export function auditTranslation(master, translated) {
|
|
17
|
+
const anchors = []
|
|
18
|
+
const alts = []
|
|
19
|
+
const walk = (a, b, path) => {
|
|
20
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
21
|
+
const byKey = new Map(b.filter((i) => isObj(i) && i._key).map((i) => [i._key, i]))
|
|
22
|
+
for (const item of a) if (isObj(item) && item._key && byKey.has(item._key)) walk(item, byKey.get(item._key), `${path}[${item._key}]`)
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
if (!isObj(a) || !isObj(b)) return
|
|
26
|
+
for (const [k, v] of Object.entries(a)) {
|
|
27
|
+
if (k.startsWith('_')) continue
|
|
28
|
+
const w = b[k]
|
|
29
|
+
const at = path ? `${path}.${k}` : k
|
|
30
|
+
if (typeof v === 'string' && ANCHOR.test(k)) {
|
|
31
|
+
if (v && typeof w === 'string' && w && w !== v) anchors.push(at)
|
|
32
|
+
} else if (typeof v === 'string' && k === 'alt' && isObj(a.asset)) {
|
|
33
|
+
if (v.trim() && w === v) alts.push(at)
|
|
34
|
+
} else walk(v, w, at)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
walk(master, translated, '')
|
|
38
|
+
return {anchors, alts}
|
|
39
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1483,7 +1483,7 @@ export declare function ActorName(props: {
|
|
|
1483
1483
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1484
1484
|
* le vérifie.
|
|
1485
1485
|
*/
|
|
1486
|
-
export declare const KIT_VERSION = "2.65.0-rc.
|
|
1486
|
+
export declare const KIT_VERSION = "2.65.0-rc.5";
|
|
1487
1487
|
/**
|
|
1488
1488
|
* Données de la page proposées comme colonnes.
|
|
1489
1489
|
*
|
package/dist/index.js
CHANGED
|
@@ -1423,7 +1423,7 @@ function explainGrantError(error) {
|
|
|
1423
1423
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1424
1424
|
* le vérifie.
|
|
1425
1425
|
*/
|
|
1426
|
-
const KIT_VERSION = "2.65.0-rc.
|
|
1426
|
+
const KIT_VERSION = "2.65.0-rc.5";
|
|
1427
1427
|
/**
|
|
1428
1428
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1429
1429
|
*
|
|
@@ -1931,7 +1931,7 @@ function useKitUpdate() {
|
|
|
1931
1931
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1932
1932
|
}).catch(() => {}), () => controller.abort();
|
|
1933
1933
|
}, []);
|
|
1934
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.65.0-rc.
|
|
1934
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.65.0-rc.5") > 0);
|
|
1935
1935
|
return {
|
|
1936
1936
|
current: KIT_VERSION,
|
|
1937
1937
|
latest,
|
|
@@ -4029,7 +4029,13 @@ const VALUE_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
|
4029
4029
|
"datetime",
|
|
4030
4030
|
"number",
|
|
4031
4031
|
"boolean"
|
|
4032
|
-
]), SKIP_KEYS = /* @__PURE__ */ new Set(["language", "slug"]),
|
|
4032
|
+
]), SKIP_KEYS = /* @__PURE__ */ new Set(["language", "slug"]), NON_TEXT_NAMES = /^(anchor|pageAnchor|.*Anchor|href|url|link|email|mail|phone|tel|telephone|token|customHex|hex|color|colour|icon|code|key|id|slug|path|target|rel)$/i, NON_TEXT_VALUE = /^(?:[\w.+-]+@[\w-]+\.[\w.-]+|\+?[\d\s().-]{6,}|(?:https?:|mailto:|tel:)\S*|[/#]\S*|#[0-9a-f]{3,8})$/i;
|
|
4033
|
+
/** Un texte libre qui n'est pas à traduire (nom du champ, ou valeur technique). */
|
|
4034
|
+
function isNonTextValue(name, value) {
|
|
4035
|
+
return name && NON_TEXT_NAMES.test(name) ? !0 : typeof value == "string" && NON_TEXT_VALUE.test(value.trim());
|
|
4036
|
+
}
|
|
4037
|
+
/** Dernier nom de champ d'un chemin lisible (« sections[k].cta.anchor » → « anchor »). */
|
|
4038
|
+
const lastName = (path) => path.split(".").pop()?.replace(/\[.*$/, ""), isObj$2 = (v) => typeof v == "object" && !!v && !Array.isArray(v), same$2 = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null), keyed$1 = (v) => Array.isArray(v) && v.length > 0 && v.every((i) => isObj$2(i) && typeof i._key == "string");
|
|
4033
4039
|
function typeNames(t) {
|
|
4034
4040
|
let out = [];
|
|
4035
4041
|
for (let c = t; c; c = c.type) c.name && out.push(c.name);
|
|
@@ -4039,7 +4045,9 @@ function typeNames(t) {
|
|
|
4039
4045
|
function kindOf(t, value) {
|
|
4040
4046
|
if (t) {
|
|
4041
4047
|
let names = typeNames(t);
|
|
4042
|
-
if (t.options?.instanceOnly
|
|
4048
|
+
if (t.options?.instanceOnly) return "value";
|
|
4049
|
+
if (names.includes("image") && hasOwnFields(t)) return "object";
|
|
4050
|
+
if (names.some((n) => VALUE_TYPE_NAMES.has(n)) || t.to) return "value";
|
|
4043
4051
|
if (t.jsonType === "array") {
|
|
4044
4052
|
let of = t.of ?? [];
|
|
4045
4053
|
if (of.some((m) => typeNames(m).includes("block"))) return "text";
|
|
@@ -4051,6 +4059,15 @@ function kindOf(t, value) {
|
|
|
4051
4059
|
}
|
|
4052
4060
|
return keyed$1(value) ? "list" : isObj$2(value) ? "object" : "value";
|
|
4053
4061
|
}
|
|
4062
|
+
function hasOwnFields(t) {
|
|
4063
|
+
for (let c = t; c; c = c.type) if (c.fields?.some((f) => ![
|
|
4064
|
+
"asset",
|
|
4065
|
+
"hotspot",
|
|
4066
|
+
"crop",
|
|
4067
|
+
"media"
|
|
4068
|
+
].includes(f.name))) return !0;
|
|
4069
|
+
return !1;
|
|
4070
|
+
}
|
|
4054
4071
|
function fieldType(t, name) {
|
|
4055
4072
|
for (let c = t; c; c = c.type) {
|
|
4056
4073
|
let f = c.fields?.find((x) => x.name === name);
|
|
@@ -4065,15 +4082,17 @@ function itemType(t, item) {
|
|
|
4065
4082
|
/** Tous les textes d'un élément ajouté : à traduire. */
|
|
4066
4083
|
function collectTexts(value, t, path, acc) {
|
|
4067
4084
|
let kind = kindOf(t, value);
|
|
4068
|
-
if (kind === "text"
|
|
4069
|
-
|
|
4070
|
-
|
|
4085
|
+
if (!(kind === "text" && typeof value == "string" && isNonTextValue(lastName(path), value))) {
|
|
4086
|
+
if (kind === "text") value != null && value !== "" && acc.toTranslate.push(path);
|
|
4087
|
+
else if (kind === "object" && isObj$2(value)) for (let [k, v] of Object.entries(value)) k.startsWith("_") || collectTexts(v, fieldType(t, k), `${path}.${k}`, acc);
|
|
4088
|
+
else if (kind === "list" && Array.isArray(value)) for (let item of value) isObj$2(item) && collectTexts(item, itemType(t, item), `${path}[${String(item._key)}]`, acc);
|
|
4089
|
+
}
|
|
4071
4090
|
}
|
|
4072
4091
|
const ABSENT$1 = Symbol("absent");
|
|
4073
4092
|
function merge(target, before, after, t, path, acc) {
|
|
4074
4093
|
if (same$2(before, after)) return target === void 0 ? ABSENT$1 : target;
|
|
4075
4094
|
let kind = kindOf(t, after ?? before);
|
|
4076
|
-
if (kind === "text") return after == null || after === "" ? (target != null && target !== "" && acc.toTranslate.push(path), target === void 0 ? ABSENT$1 : target) : (acc.toTranslate.push(path), target == null || target === "" || same$2(target, before) ? after : target);
|
|
4095
|
+
if (kind === "text" && typeof (after ?? before) == "string" && isNonTextValue(lastName(path), after ?? before) && (kind = "value"), kind === "text") return after == null || after === "" ? (target != null && target !== "" && acc.toTranslate.push(path), target === void 0 ? ABSENT$1 : target) : (acc.toTranslate.push(path), target == null || target === "" || same$2(target, before) ? after : target);
|
|
4077
4096
|
if (kind === "value") return acc.copied.push(path), after === void 0 ? ABSENT$1 : after;
|
|
4078
4097
|
if (kind === "object") {
|
|
4079
4098
|
if (!isObj$2(after)) return acc.copied.push(path), after === void 0 ? ABSENT$1 : after;
|
|
@@ -4226,6 +4245,29 @@ async function linkTranslations(client, sourceId, sourceLanguage, type, created)
|
|
|
4226
4245
|
* traduits par l'IA si `ai` (service du kit), slug traduit et unique, publiée si
|
|
4227
4246
|
* tout est traduit (sinon brouillon et textes « To translate »). Relie la version.
|
|
4228
4247
|
*/
|
|
4248
|
+
/** Champ slug d'un type (registre des pages du kit, sinon « slug » s'il est rempli). */
|
|
4249
|
+
function slugFieldOf(config, type, source) {
|
|
4250
|
+
let field = config.pageTypes.find((t) => t.type === type)?.slugField ?? (source.slug?.current ? "slug" : null);
|
|
4251
|
+
return field && source[field]?.current ? field : null;
|
|
4252
|
+
}
|
|
4253
|
+
/**
|
|
4254
|
+
* Slug d'une version traduite : tiré de son titre (déjà traduit), unique dans la langue
|
|
4255
|
+
* (-2, -3...) ; à défaut de titre, le slug de la version source. JAMAIS « traduit » comme
|
|
4256
|
+
* un texte (vu sur JAF : une reprise avait vidé le slug d'une page).
|
|
4257
|
+
*/
|
|
4258
|
+
async function translatedSlug(client, config, type, doc, source, language) {
|
|
4259
|
+
let field = config.i18n?.field ?? "language", pageType = config.pageTypes.find((t) => t.type === type), slugField = slugFieldOf(config, type, source) ?? "slug", titleField = pageType?.titleField ?? "title", base = slugify(typeof doc[titleField] == "string" ? doc[titleField] : "") || String(source[slugField].current), id = typeof doc._id == "string" ? doc._id.replace(/^drafts\./, "") : "", slug = base;
|
|
4260
|
+
for (let n = 2; await client.fetch(`count(*[_type == $type && ${slugField}.current == $slug && ${field} == $language && !(_id in path("drafts.**")) && _id != $id]) > 0`, {
|
|
4261
|
+
type,
|
|
4262
|
+
slug,
|
|
4263
|
+
language,
|
|
4264
|
+
id
|
|
4265
|
+
}); n++) slug = `${base}-${n}`;
|
|
4266
|
+
return {
|
|
4267
|
+
_type: "slug",
|
|
4268
|
+
current: slug
|
|
4269
|
+
};
|
|
4270
|
+
}
|
|
4229
4271
|
async function createTranslatedVersion(opts) {
|
|
4230
4272
|
let { client, config, type, schemaType, source, sourceId, sourceLanguage, language, ai, publish = !1 } = opts, field = config.i18n?.field ?? "language", result = propagate({}, {}, source, schemaType), { _id, _rev, _createdAt, _updatedAt, ...doc } = structuredClone(result.document), id = translationIdFor(sourceId, sourceLanguage, language), remaining = result.toTranslate, aiError = null, written = [];
|
|
4231
4273
|
if (ai && config.history && remaining.length) try {
|
|
@@ -4242,20 +4284,8 @@ async function createTranslatedVersion(opts) {
|
|
|
4242
4284
|
aiError = cause instanceof Error ? cause.message : String(cause);
|
|
4243
4285
|
}
|
|
4244
4286
|
doc[field] = language, Object.assign(doc, await localizeReferences(client, doc, language));
|
|
4245
|
-
let pageType = config.pageTypes.find((t) => t.type === type), slugField =
|
|
4246
|
-
|
|
4247
|
-
let titleField = pageType?.titleField ?? "title", base = slugify(typeof doc[titleField] == "string" ? doc[titleField] : "") || String(source[slugField].current), slug = base;
|
|
4248
|
-
for (let n = 2; await client.fetch(`count(*[_type == $type && ${slugField}.current == $slug && ${field} == $language && !(_id in path("drafts.**"))]) > 0`, {
|
|
4249
|
-
type,
|
|
4250
|
-
slug,
|
|
4251
|
-
language
|
|
4252
|
-
}); n++) slug = `${base}-${n}`;
|
|
4253
|
-
doc[slugField] = {
|
|
4254
|
-
_type: "slug",
|
|
4255
|
-
current: slug
|
|
4256
|
-
};
|
|
4257
|
-
}
|
|
4258
|
-
slugField && remaining.includes(pageType?.titleField ?? "title") && !remaining.includes(slugField) && (remaining = [...remaining, slugField]);
|
|
4287
|
+
let pageType = config.pageTypes.find((t) => t.type === type), slugField = slugFieldOf(config, type, source);
|
|
4288
|
+
slugField && (doc[slugField] = await translatedSlug(client, config, type, doc, source, language)), slugField && remaining.includes(pageType?.titleField ?? "title") && !remaining.includes(slugField) && (remaining = [...remaining, slugField]);
|
|
4259
4289
|
let complete = ai && !remaining.length && !aiError, published = complete && publish;
|
|
4260
4290
|
await client.createOrReplace({
|
|
4261
4291
|
...doc,
|
|
@@ -4345,7 +4375,7 @@ async function retryTranslatedVersion(opts) {
|
|
|
4345
4375
|
remaining: todo.paths,
|
|
4346
4376
|
aiError: "AI translation is not configured (kit project key missing)"
|
|
4347
4377
|
};
|
|
4348
|
-
let { _rev, _createdAt, _updatedAt, ...doc } = structuredClone(current), remaining = todo.paths, aiError = null, written = [];
|
|
4378
|
+
let { _rev, _createdAt, _updatedAt, ...doc } = structuredClone(current), type = String(current._type), slugField = slugFieldOf(config, type, source), nameOf = (path) => path.split(".").pop()?.replace(/\[.*$/, ""), technical = (path) => isNonTextValue(nameOf(path), valueAtKey(source, path)), slugPending = !!(slugField && todo.paths.includes(slugField)), remaining = todo.paths.filter((p) => p !== slugField && !technical(p)), aiError = null, written = [];
|
|
4349
4379
|
try {
|
|
4350
4380
|
let toSend = remaining.map((path) => valueAtKey(source, path)).map((v) => collectTexts$1(v).some((s) => s.trim()) ? v : void 0), result = await translateValuesSettled(config.history, todo.sourceLanguage, language, toSend.map((v) => v ?? "")), failed = new Set(result.failed);
|
|
4351
4381
|
result.error && (aiError = result.error), remaining = remaining.filter((path, n) => {
|
|
@@ -4359,6 +4389,10 @@ async function retryTranslatedVersion(opts) {
|
|
|
4359
4389
|
} catch (cause) {
|
|
4360
4390
|
aiError = cause instanceof Error ? cause.message : String(cause);
|
|
4361
4391
|
}
|
|
4392
|
+
if (slugPending && slugField) {
|
|
4393
|
+
let titleField = config.pageTypes.find((t) => t.type === type)?.titleField ?? "title";
|
|
4394
|
+
remaining.includes(titleField) ? remaining = [...remaining, slugField] : doc[slugField] = await translatedSlug(client, config, type, doc, source, language);
|
|
4395
|
+
}
|
|
4362
4396
|
let published = publish && !remaining.length && !aiError, tx = client.transaction();
|
|
4363
4397
|
return published ? (tx.createOrReplace({
|
|
4364
4398
|
...doc,
|
|
@@ -11871,7 +11905,7 @@ function withTranslationTodo(Inner, config) {
|
|
|
11871
11905
|
let alive = !0;
|
|
11872
11906
|
return client.getDocument(sourceId).then((doc) => {
|
|
11873
11907
|
if (!alive) return;
|
|
11874
|
-
let
|
|
11908
|
+
let value = valueAtKey(doc, key), text = (value && typeof value == "object" && typeof value.current == "string" ? value.current : "") || (typeof value == "string" ? value : collectTexts$1(value).join("").trim());
|
|
11875
11909
|
setMaster(text || "(empty: follows the component default)");
|
|
11876
11910
|
}).catch(() => alive && setMaster(null)), () => {
|
|
11877
11911
|
alive = !1;
|
|
@@ -12100,6 +12134,37 @@ function withLanguageMismatch(Inner, config) {
|
|
|
12100
12134
|
}
|
|
12101
12135
|
return LanguageMismatch;
|
|
12102
12136
|
}
|
|
12137
|
+
/** Identifiants des documents référencés par `doc` (liens, pages liées...), hors images et fichiers. */
|
|
12138
|
+
function referencedIds(doc) {
|
|
12139
|
+
let out = /* @__PURE__ */ new Set(), walk = (node) => {
|
|
12140
|
+
if (Array.isArray(node)) return node.forEach(walk);
|
|
12141
|
+
if (!node || typeof node != "object") return;
|
|
12142
|
+
let ref = node._ref;
|
|
12143
|
+
typeof ref == "string" && !/^(image|file)-/.test(ref) && out.add(ref.replace(/^drafts\./, ""));
|
|
12144
|
+
for (let [k, v] of Object.entries(node)) k.startsWith("_") || walk(v);
|
|
12145
|
+
};
|
|
12146
|
+
return walk(doc), [...out];
|
|
12147
|
+
}
|
|
12148
|
+
/**
|
|
12149
|
+
* Pages liées depuis `doc` qui n'ont pas de version PUBLIÉE dans chacune des `languages`
|
|
12150
|
+
* (kit >= 2.65.0). La version traduite d'un document qui les vise ne peut pas être
|
|
12151
|
+
* publiée (« Cette page est en FR et n'a pas de version EN », vu sur JAF) : on le dit
|
|
12152
|
+
* AVANT de la créer, avec les pages à traduire d'abord.
|
|
12153
|
+
*/
|
|
12154
|
+
async function linkedWithoutVersion(client, doc, languages, field = "language") {
|
|
12155
|
+
let result = /* @__PURE__ */ new Map(), ids = referencedIds(doc);
|
|
12156
|
+
if (!ids.length || !languages.length) return result;
|
|
12157
|
+
let linked = await client.fetch(`*[_id in $ids && defined(${field})]{
|
|
12158
|
+
_id, "title": coalesce(title, name, slug.current, _id), "language": ${field},
|
|
12159
|
+
"versions": *[_type == "translation.metadata" && references(^._id)][0].translations[]{"language": coalesce(language, _key), "id": value._ref}
|
|
12160
|
+
}`, { ids }), versionIds = linked.flatMap((d) => (d.versions ?? []).map((v) => v.id ?? "")).filter(Boolean), published = new Set(versionIds.length ? await client.fetch("*[_id in $ids]._id", { ids: versionIds }) : []);
|
|
12161
|
+
for (let language of languages) for (let d of linked) {
|
|
12162
|
+
if (d.language === language) continue;
|
|
12163
|
+
let version = (d.versions ?? []).find((v) => v.language === language);
|
|
12164
|
+
version?.id && published.has(version.id) || result.set(language, [...result.get(language) ?? [], d.title]);
|
|
12165
|
+
}
|
|
12166
|
+
return result;
|
|
12167
|
+
}
|
|
12103
12168
|
/**
|
|
12104
12169
|
* Publier la version PRINCIPALE d'une page :
|
|
12105
12170
|
* - page déjà publiée qui a des traductions : « Propagate to other languages? »
|
|
@@ -12194,7 +12259,19 @@ async function findMissing(client, id, source, locales) {
|
|
|
12194
12259
|
return locales.filter((l) => l !== source && !existing.has(l));
|
|
12195
12260
|
}
|
|
12196
12261
|
function PropagateDialog(props) {
|
|
12197
|
-
let { config, id, type, mode, after, onDone } = props, client = useKitClient(), schema = useSchema(), field = config.i18n?.field ?? "language", source = String(after[field] ?? ""), [targets, setTargets] = useState(props.targets), [
|
|
12262
|
+
let { config, id, type, mode, after, onDone } = props, client = useKitClient(), schema = useSchema(), field = config.i18n?.field ?? "language", source = String(after[field] ?? ""), [targets, setTargets] = useState(props.targets), [unlinked, setUnlinked] = useState(/* @__PURE__ */ new Map());
|
|
12263
|
+
useEffect(() => {
|
|
12264
|
+
let alive = !0;
|
|
12265
|
+
return linkedWithoutVersion(client, after, props.targets.map((t) => t.language), field).then((m) => alive && setUnlinked(m)).catch(() => {}), () => {
|
|
12266
|
+
alive = !1;
|
|
12267
|
+
};
|
|
12268
|
+
}, [
|
|
12269
|
+
client,
|
|
12270
|
+
after,
|
|
12271
|
+
props.targets,
|
|
12272
|
+
field
|
|
12273
|
+
]);
|
|
12274
|
+
let [busy, setBusy] = useState(!1), toast = useToast(), [error, setError] = useState(null), [ai, setAi] = useState(!!config.history), [publishNow, setPublishNow] = useState(!1), [overwrite, setOverwrite] = useState(!1), editedCount = targets.reduce((n, t) => n + (t.selected ? t.edited.length : 0), 0), hasTexts = targets.some((t) => t.result.toTranslate.length), apply = async () => {
|
|
12198
12275
|
setBusy(!0), setError(null);
|
|
12199
12276
|
try {
|
|
12200
12277
|
let published = [], drafted = [], aiError = null;
|
|
@@ -12344,15 +12421,42 @@ function PropagateDialog(props) {
|
|
|
12344
12421
|
flex: 1,
|
|
12345
12422
|
children: /* @__PURE__ */ jsxs(Stack, {
|
|
12346
12423
|
gap: 2,
|
|
12347
|
-
children: [
|
|
12348
|
-
|
|
12349
|
-
|
|
12350
|
-
|
|
12351
|
-
|
|
12352
|
-
|
|
12353
|
-
|
|
12354
|
-
|
|
12355
|
-
|
|
12424
|
+
children: [
|
|
12425
|
+
/* @__PURE__ */ jsx(Text, {
|
|
12426
|
+
size: 1,
|
|
12427
|
+
weight: "semibold",
|
|
12428
|
+
children: t.language.toUpperCase()
|
|
12429
|
+
}),
|
|
12430
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
12431
|
+
size: 1,
|
|
12432
|
+
muted: !0,
|
|
12433
|
+
children: [mode === "create" ? `New version (${t.result.toTranslate.length} texts)` : summary(t.result), t.edited.length ? ` · ${t.edited.length} edited by hand` : ""]
|
|
12434
|
+
}),
|
|
12435
|
+
unlinked.get(t.language)?.length ? /* @__PURE__ */ jsx(Card, {
|
|
12436
|
+
tone: "caution",
|
|
12437
|
+
padding: 2,
|
|
12438
|
+
radius: 2,
|
|
12439
|
+
children: /* @__PURE__ */ jsxs(Text, {
|
|
12440
|
+
size: 1,
|
|
12441
|
+
children: [
|
|
12442
|
+
"Links to ",
|
|
12443
|
+
unlinked.get(t.language).length,
|
|
12444
|
+
" page",
|
|
12445
|
+
unlinked.get(t.language).length > 1 ? "s" : "",
|
|
12446
|
+
" with no published ",
|
|
12447
|
+
t.language.toUpperCase(),
|
|
12448
|
+
" version (",
|
|
12449
|
+
unlinked.get(t.language).slice(0, 4).map((title) => `« ${title} »`).join(", "),
|
|
12450
|
+
unlinked.get(t.language).length > 4 ? ", …" : "",
|
|
12451
|
+
"): this version can be saved as a draft, but not published until",
|
|
12452
|
+
unlinked.get(t.language).length > 1 ? " those pages are" : " that page is",
|
|
12453
|
+
" translated and published. Not meant to be translated? In the ",
|
|
12454
|
+
t.language.toUpperCase(),
|
|
12455
|
+
" version, link to its address directly (link type URL) or remove the link."
|
|
12456
|
+
]
|
|
12457
|
+
})
|
|
12458
|
+
}) : null
|
|
12459
|
+
]
|
|
12356
12460
|
})
|
|
12357
12461
|
})]
|
|
12358
12462
|
})
|