@nocode-factory/sanity-kit 2.65.0-rc.5 → 2.65.0-rc.7
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 +17 -4
- package/bin/ncf-kit.mjs +78 -5
- package/bin/translation-audit.mjs +3 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/tools/pages/LanguagesSync.tsx +15 -4
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -48,7 +48,18 @@
|
|
|
48
48
|
- **`doctor` : traductions faites avant la 2.65.0**, que la mise à jour ne corrige pas :
|
|
49
49
|
⚠ « ancres traduites » (ancre différente de la version principale, liens cassés) et ⚠
|
|
50
50
|
« textes alternatifs » (identiques à la version principale, donc non traduits), page par
|
|
51
|
-
page. Sur Société Paul Ricard : 47 versions
|
|
51
|
+
page, sous le titre de la version TRADUITE. Sur Société Paul Ricard : 47 versions
|
|
52
|
+
anglaises avec des textes alternatifs en français.
|
|
53
|
+
- **`npx ncf-kit translations audit [--apply]`** : le détail (chemin, valeur actuelle, valeur
|
|
54
|
+
attendue) ; `--apply` corrige EN BROUILLON (rien n'est publié) : ancres remises à celle de
|
|
55
|
+
la version principale (règle : une ancre ne se traduit jamais), textes alternatifs marqués
|
|
56
|
+
« To translate » pour Pages → Languages → « Unfinished translations, retry ». Contrôle
|
|
57
|
+
aussi les liens « adresse » vers une ancre de la page (`href: "#pratique"`) ; dit « rien à
|
|
58
|
+
corriger » quand c'est le cas. Validé sur JAF : 60 ancres remises, 25 textes alternatifs
|
|
59
|
+
traduits, doctor à zéro.
|
|
60
|
+
- **Pages → Languages, valeurs par défaut** : comptées depuis le brouillon en cours (une
|
|
61
|
+
traduction en relecture n'est plus « à traduire ») et sans les textes déjà repris par
|
|
62
|
+
« Unfinished translations » (plus de double comptage) ; nommées « Component defaults ».
|
|
52
63
|
- **Textes rendus à l'identique par l'IA** (noms propres, marques) : comptés comme
|
|
53
64
|
traduits, plus reproposés sans fin, et signalés « à vérifier » (vu sur JAF : 12 textes).
|
|
54
65
|
- **`doctor`, « Langues : contenus »** : une langue ne compte que si sa version est
|
|
@@ -59,9 +70,11 @@
|
|
|
59
70
|
### À brancher dans le projet
|
|
60
71
|
|
|
61
72
|
- Rien dans le code. Redéployer le Studio (`npm run deploy`).
|
|
62
|
-
- Si `doctor` affiche ⚠ « ancres traduites » ou « textes alternatifs » :
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
- Si `doctor` affiche ⚠ « ancres traduites » ou « textes alternatifs » : depuis studio/,
|
|
74
|
+
`npx ncf-kit translations audit` (liste), puis `--apply` (brouillons), puis Pages →
|
|
75
|
+
Languages → « Unfinished translations, retry », relire et publier chaque version.
|
|
76
|
+
- CLAUDE.md du starter : règle « une ancre ne se traduit jamais » (rubrique ANCRES DE
|
|
77
|
+
SECTION) ; la reprendre.
|
|
65
78
|
- CLAUDE.md du starter : rubriques PROPAGATION ET TRADUCTION PAR IA et « Ajouter une
|
|
66
79
|
langue » mises à jour (brouillons à relire, puis publier) ; les reprendre.
|
|
67
80
|
|
package/bin/ncf-kit.mjs
CHANGED
|
@@ -42,6 +42,7 @@ function usage(code = 0) {
|
|
|
42
42
|
npx ncf-kit translate-json [--from <langue>] [--apply] textes du site (messages/<langue>.json, titres du registre) traduits par IA
|
|
43
43
|
npx ncf-kit translations [export] [--out <fichier>] champs « À traduire » → JSON (texte source et actuel)
|
|
44
44
|
npx ncf-kit translations apply <fichier> écrit les traductions dans les brouillons
|
|
45
|
+
npx ncf-kit translations audit [--apply] ancres traduites, textes alternatifs non traduits (--apply : corrige en brouillon)
|
|
45
46
|
npx ncf-kit item-types [--apply] éléments de liste sans _type (écrits par script) ; --apply corrige
|
|
46
47
|
|
|
47
48
|
Depuis le dossier du studio (celui de sanity.config.ts et de .env).
|
|
@@ -688,16 +689,17 @@ async function doctor() {
|
|
|
688
689
|
if (!byId.has(a) || !byId.has(b)) continue
|
|
689
690
|
const {anchors, alts} = auditTranslation(byId.get(a), byId.get(b))
|
|
690
691
|
const doc = byId.get(b)
|
|
691
|
-
|
|
692
|
+
// Titre de la version TRADUITE (« Middle school »), celui qu'on cherche dans l'onglet Pages.
|
|
693
|
+
const label = doc._type === 'componentDefaults' ? 'Component defaults' : (doc.title ?? doc.name ?? titles.get(a) ?? b)
|
|
692
694
|
const name = `${lang.toUpperCase()} « ${label} »`
|
|
693
695
|
if (anchors.length) anchorPages.push(`${name} (${anchors.length})`)
|
|
694
696
|
if (alts.length) altPages.push(`${name} (${alts.length})`)
|
|
695
697
|
}
|
|
696
|
-
const list = (pages) => `${pages.slice(0,
|
|
698
|
+
const list = (pages) => `${pages.slice(0, 20).join(', ')}${pages.length > 20 ? `, +${pages.length - 20}` : ''}`
|
|
697
699
|
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)}.
|
|
700
|
+
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)}. Détail et correction en brouillon : npx ncf-kit translations audit, puis --apply ; relire et publier.`)
|
|
699
701
|
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)}.
|
|
702
|
+
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)}. Détail : npx ncf-kit translations audit ; --apply les marque « To translate », puis Pages → Languages → « Unfinished translations, retry » (brouillons), relire et publier.`)
|
|
701
703
|
}
|
|
702
704
|
// Textes « To translate » en attente (échec de l'IA, texte gardé à la main...).
|
|
703
705
|
const todos = (await q(`*[_type == "ncfTranslationTodo" && count(paths) > 0]{"n": count(paths)}`)) ?? []
|
|
@@ -1012,7 +1014,78 @@ async function translations() {
|
|
|
1012
1014
|
console.log(`\n${written} champ(s) écrit(s). Rien n'est publié : relire puis publier chaque langue dans le Studio.`)
|
|
1013
1015
|
return
|
|
1014
1016
|
}
|
|
1015
|
-
|
|
1017
|
+
// AUDIT des traductions faites avant le kit 2.65.0 (kit >= 2.65.0) : ancres différentes
|
|
1018
|
+
// de la version principale (règle : une section garde l'ancre du master dans toutes les
|
|
1019
|
+
// langues) et textes alternatifs d'images identiques (non traduits). Sans --apply : liste.
|
|
1020
|
+
// Avec --apply, en BROUILLON seulement (rien n'est publié) : ancres remises à la valeur de
|
|
1021
|
+
// la version principale ; textes alternatifs marqués « To translate », à traduire par
|
|
1022
|
+
// Studio → Pages → Languages → « Unfinished translations, retry », puis relire et publier.
|
|
1023
|
+
if (sub === 'audit') {
|
|
1024
|
+
const {auditTranslation} = await import('./translation-audit.mjs')
|
|
1025
|
+
const locales = String(env.SANITY_STUDIO_LOCALES ?? process.env.SANITY_STUDIO_LOCALES ?? '').split(',').map((l) => l.trim()).filter(Boolean)
|
|
1026
|
+
if (locales.length < 2) fail('SANITY_STUDIO_LOCALES : une seule langue, rien à auditer.')
|
|
1027
|
+
const main = locales[0]
|
|
1028
|
+
const apply = has('apply')
|
|
1029
|
+
const metas = await query(`*[_type == "translation.metadata"]{"refs": translations[]{"lang": coalesce(language, _key), "id": value._ref}}`)
|
|
1030
|
+
const pairs = []
|
|
1031
|
+
for (const m of metas) {
|
|
1032
|
+
const refs = m.refs ?? []
|
|
1033
|
+
const master = refs.find((r) => r.lang === main)
|
|
1034
|
+
if (master) for (const r of refs) if (r.lang !== main) pairs.push([master.id, r.id, r.lang])
|
|
1035
|
+
}
|
|
1036
|
+
let anchorsFixed = 0
|
|
1037
|
+
let altsMarked = 0
|
|
1038
|
+
let found = 0
|
|
1039
|
+
for (const [masterId, id, lang] of pairs) {
|
|
1040
|
+
const [master, published, draft] = await Promise.all([
|
|
1041
|
+
query(`*[_id == $id][0]`, {id: masterId}),
|
|
1042
|
+
query(`*[_id == $id][0]`, {id}),
|
|
1043
|
+
query(`*[_id == $id][0]`, {id: `drafts.${id}`}),
|
|
1044
|
+
])
|
|
1045
|
+
const target = draft ?? published
|
|
1046
|
+
if (!master || !target) continue
|
|
1047
|
+
const {anchors, alts} = auditTranslation(master, target)
|
|
1048
|
+
if (!anchors.length && !alts.length) continue
|
|
1049
|
+
found++
|
|
1050
|
+
const title = target.title ?? target.name ?? (target._type === 'componentDefaults' ? 'Component defaults' : id)
|
|
1051
|
+
console.log(`\n${lang.toUpperCase()} « ${title} » (${id})`)
|
|
1052
|
+
for (const a of anchors) console.log(` ancre ${a} : « ${valueAt(target, a)} » → « ${valueAt(master, a)} »`)
|
|
1053
|
+
for (const a of alts) console.log(` texte alternatif ${a} : « ${valueAt(target, a)} » (identique à ${main.toUpperCase()})`)
|
|
1054
|
+
if (!apply) continue
|
|
1055
|
+
const draftId = `drafts.${id}`
|
|
1056
|
+
const mutations = []
|
|
1057
|
+
if (!draft) {
|
|
1058
|
+
const {_rev, _updatedAt, _createdAt, ...copy} = published
|
|
1059
|
+
mutations.push({createIfNotExists: {...copy, _id: draftId}})
|
|
1060
|
+
}
|
|
1061
|
+
if (anchors.length) {
|
|
1062
|
+
const set = {}
|
|
1063
|
+
for (const a of anchors) set[patchPath(target, a)] = valueAt(master, a)
|
|
1064
|
+
mutations.push({patch: {id: draftId, set}})
|
|
1065
|
+
}
|
|
1066
|
+
if (alts.length) {
|
|
1067
|
+
const todoId = `ncfTodo.${id}`
|
|
1068
|
+
const todo = await query(`*[_id == $id][0]{paths}`, {id: todoId})
|
|
1069
|
+
mutations.push({createIfNotExists: {_id: todoId, _type: TODO_TYPE, documentId: id, sourceId: masterId, sourceLanguage: main, paths: []}})
|
|
1070
|
+
mutations.push({patch: {id: todoId, set: {paths: [...new Set([...(todo?.paths ?? []), ...alts])]}}})
|
|
1071
|
+
}
|
|
1072
|
+
await mutate(mutations)
|
|
1073
|
+
anchorsFixed += anchors.length
|
|
1074
|
+
altsMarked += alts.length
|
|
1075
|
+
}
|
|
1076
|
+
if (!found) {
|
|
1077
|
+
console.log('✔ Rien à corriger : ancres identiques à la version principale, textes alternatifs traduits.')
|
|
1078
|
+
return
|
|
1079
|
+
}
|
|
1080
|
+
if (!apply) {
|
|
1081
|
+
console.log('\nLecture seule. `npx ncf-kit translations audit --apply` : ancres remises et textes alternatifs marqués « To translate », EN BROUILLON (rien n\'est publié).')
|
|
1082
|
+
return
|
|
1083
|
+
}
|
|
1084
|
+
console.log(`\n✔ ${anchorsFixed} ancre(s) remise(s) à la valeur de la version principale, ${altsMarked} texte(s) alternatif(s) marqué(s) « To translate », en brouillon.`)
|
|
1085
|
+
console.log('Ensuite : Studio → Pages → Languages → « Unfinished translations, retry » (brouillons), relire chaque version, la publier, puis `npx ncf-kit doctor`.')
|
|
1086
|
+
return
|
|
1087
|
+
}
|
|
1088
|
+
fail(`translations : sous-commande inconnue « ${sub} » (export | apply <fichier> | audit [--apply])`)
|
|
1016
1089
|
}
|
|
1017
1090
|
|
|
1018
1091
|
// ─── check-deploy : ne jamais écraser le Studio d'un autre projet ───
|
|
@@ -27,7 +27,9 @@ export function auditTranslation(master, translated) {
|
|
|
27
27
|
if (k.startsWith('_')) continue
|
|
28
28
|
const w = b[k]
|
|
29
29
|
const at = path ? `${path}.${k}` : k
|
|
30
|
-
|
|
30
|
+
// Ancre d'une section ou d'un lien, et lien « adresse » vers une ancre de la page
|
|
31
|
+
// (href « #pratique », vu sur JAF : le bouton restait sur « #practical »).
|
|
32
|
+
if (typeof v === 'string' && (ANCHOR.test(k) || (k === 'href' && v.startsWith('#')))) {
|
|
31
33
|
if (v && typeof w === 'string' && w && w !== v) anchors.push(at)
|
|
32
34
|
} else if (typeof v === 'string' && k === 'alt' && isObj(a.asset)) {
|
|
33
35
|
if (v.trim() && w === v) alts.push(at)
|
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.7";
|
|
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.7";
|
|
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.7") > 0);
|
|
1935
1935
|
return {
|
|
1936
1936
|
current: KIT_VERSION,
|
|
1937
1937
|
latest,
|
|
@@ -4413,7 +4413,7 @@ const EXCLUDED = [
|
|
|
4413
4413
|
"translation.metadata",
|
|
4414
4414
|
BOARD_LAYOUT_TYPE,
|
|
4415
4415
|
TRANSLATION_TODO_TYPE
|
|
4416
|
-
], TITLE = "coalesce(title, name, heading, internalName, slug.current, _id)";
|
|
4416
|
+
], TITLE = "coalesce(title, name, heading, internalName, slug.current, _id)", label = (t) => /componentDefaults/.test(t.documentId) || /componentDefaults/.test(t.title ?? "") ? "Component defaults" : (t.title ?? t.documentId).replace(/^drafts\./, "");
|
|
4417
4417
|
/** Erreur lisible pour l'équipe (le service renvoie parfois un message technique). */
|
|
4418
4418
|
function explain$1(error) {
|
|
4419
4419
|
let e = error.toLowerCase();
|
|
@@ -4460,9 +4460,9 @@ function LanguagesSync() {
|
|
|
4460
4460
|
}), drafts = others.map((language) => ({
|
|
4461
4461
|
language,
|
|
4462
4462
|
count: draftOnly.filter((d) => d.language === language).length
|
|
4463
|
-
})).filter((d) => d.count), defaultsDocs = await client.fetch("*[_type == $type && !(_id in path(\"drafts.**\"))]", { type: defaultsType }), byLang = (lang) => defaultsDocs.find((d) => d[field] === lang) ?? null, sourceLang = byLang(i18n.defaultsSourceLocale) ? i18n.defaultsSourceLocale : main, sourceDoc = byLang(sourceLang), mainDoc = byLang(main), defaults = [];
|
|
4463
|
+
})).filter((d) => d.count), defaultsDocs = await client.fetch("*[_type == $type && !(_id in path(\"drafts.**\"))]", { type: defaultsType }), defaultsDrafts = await client.fetch("*[_type == $type && _id in path(\"drafts.**\")]", { type: defaultsType }), byLang = (lang) => defaultsDocs.find((d) => d[field] === lang) ?? null, currentOf = (doc) => defaultsDrafts.find((d) => d._id === `drafts.${String(doc._id)}`) ?? doc, inTodo = (doc) => new Set(unfinished.filter((t) => t.documentId === String(doc._id)).flatMap((t) => t.paths)), sourceLang = byLang(i18n.defaultsSourceLocale) ? i18n.defaultsSourceLocale : main, sourceDoc = byLang(sourceLang), mainDoc = byLang(main), defaults = [];
|
|
4464
4464
|
if (sourceDoc && mainDoc && sourceLang !== main) {
|
|
4465
|
-
let trace = await readTrace(client, String(sourceDoc._id)), texts = untranslatedPaths(mainDoc, sourceDoc, typeOf(defaultsType), trace).length;
|
|
4465
|
+
let trace = await readTrace(client, String(sourceDoc._id)), pending = inTodo(sourceDoc), texts = untranslatedPaths(mainDoc, currentOf(sourceDoc), typeOf(defaultsType), trace).filter((p) => !pending.has(p)).length;
|
|
4466
4466
|
texts && defaults.push({
|
|
4467
4467
|
language: sourceLang,
|
|
4468
4468
|
exists: !0,
|
|
@@ -4471,11 +4471,11 @@ function LanguagesSync() {
|
|
|
4471
4471
|
});
|
|
4472
4472
|
}
|
|
4473
4473
|
if (sourceDoc) for (let language of i18n.locales.filter((l) => l !== sourceLang)) {
|
|
4474
|
-
let doc = byLang(language), trace = doc ? await readTrace(client, String(doc._id)) : void 0;
|
|
4474
|
+
let doc = byLang(language), trace = doc ? await readTrace(client, String(doc._id)) : void 0, pending = doc ? inTodo(doc) : /* @__PURE__ */ new Set(), texts = untranslatedPaths(sourceDoc, doc ? currentOf(doc) : null, typeOf(defaultsType), trace).filter((p) => !pending.has(p)).length;
|
|
4475
4475
|
defaults.push({
|
|
4476
4476
|
language,
|
|
4477
4477
|
exists: !!doc,
|
|
4478
|
-
texts
|
|
4478
|
+
texts,
|
|
4479
4479
|
from: sourceLang
|
|
4480
4480
|
});
|
|
4481
4481
|
}
|
|
@@ -4539,7 +4539,7 @@ function LanguagesSync() {
|
|
|
4539
4539
|
}
|
|
4540
4540
|
if (pick.unfinished) for (let [n, t] of plan.unfinished.entries()) {
|
|
4541
4541
|
setProgress(`Unfinished translations ${n + 1}/${plan.unfinished.length}`);
|
|
4542
|
-
let what = `${(t.language ?? "").toUpperCase()} « ${t
|
|
4542
|
+
let what = `${(t.language ?? "").toUpperCase()} « ${label(t)} »`;
|
|
4543
4543
|
if (!t.language) {
|
|
4544
4544
|
fail(what, "language of the translated version unknown");
|
|
4545
4545
|
continue;
|
|
@@ -4710,7 +4710,7 @@ function LanguagesSync() {
|
|
|
4710
4710
|
children: [
|
|
4711
4711
|
(t.language ?? "").toUpperCase(),
|
|
4712
4712
|
" « ",
|
|
4713
|
-
t
|
|
4713
|
+
label(t),
|
|
4714
4714
|
" »: ",
|
|
4715
4715
|
t.paths.length,
|
|
4716
4716
|
" text",
|