@nocode-factory/sanity-kit 2.39.0 → 2.40.0

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/bin/ncf-kit.mjs CHANGED
@@ -35,7 +35,7 @@ function usage(code = 0) {
35
35
  npx ncf-kit doctor [--web <dossier>] [--offline] vérifie que le projet est complet
36
36
  npx ncf-kit check-environments [--page <chemin>] test prod / préprod, BLOQUANT (postbuild du site)
37
37
  npx ncf-kit check-deploy avant sanity deploy : l'appId est bien le Studio de CE projet
38
- npx ncf-kit translate-json [--apply] textes du site (messages/<langue>.json, titres du registre) traduits par IA
38
+ npx ncf-kit translate-json [--from <langue>] [--apply] textes du site (messages/<langue>.json, titres du registre) traduits par IA
39
39
  npx ncf-kit translations [export] [--out <fichier>] champs « À traduire » → JSON (texte source et actuel)
40
40
  npx ncf-kit translations apply <fichier> écrit les traductions dans les brouillons
41
41
 
@@ -762,8 +762,13 @@ async function translateJson() {
762
762
  const env = {...parseEnv(read(join(studioDir, '.env'))), ...parseEnv(read(join(studioDir, '.env.production.local')))}
763
763
  const locales = String(flag('locales') ?? env.SANITY_STUDIO_LOCALES ?? '').split(',').map((l) => l.trim()).filter(Boolean)
764
764
  const main = flag('main') ?? locales[0]
765
+ // Langue des textes SOURCE : le master par défaut ; --from <langue> pour partir
766
+ // d'un fichier de référence (ex. nouveau projet au master allemand créé depuis le
767
+ // starter : --from fr crée messages/de.json et les titres « de » du registre).
768
+ const from = flag('from') ?? main
769
+ const targets = locales.filter((l) => l !== from)
765
770
  const apply = has('apply')
766
- if (locales.length < 2 || !main) fail('Site monolingue (SANITY_STUDIO_LOCALES) : rien à traduire.')
771
+ if (!main || !targets.length) fail('Rien à traduire : une seule langue (SANITY_STUDIO_LOCALES), identique à la source. Nouveau master ? --from <langue d\'un fichier existant>.')
767
772
  const key = env.SANITY_STUDIO_NCF_PROJECT_KEY
768
773
  if (!key) fail('SANITY_STUDIO_NCF_PROJECT_KEY absent : `npx ncf-kit setup` d\'abord (clé du service du kit).')
769
774
  const endpoint = (flag('endpoint') ?? env.SANITY_STUDIO_NCF_ENDPOINT ?? DEFAULT_ENDPOINT).replace(/\/$/, '')
@@ -773,7 +778,7 @@ async function translateJson() {
773
778
  const r = await request(`${endpoint}/translate`, {
774
779
  method: 'POST',
775
780
  headers: {'content-type': 'application/json'},
776
- body: JSON.stringify({key, from: main, to, texts: texts.slice(i, i + 200)}),
781
+ body: JSON.stringify({key, from, to, texts: texts.slice(i, i + 200)}),
777
782
  })
778
783
  if (!r.ok || !Array.isArray(r.body.texts)) fail(`Traduction refusée (${r.status}) : ${JSON.stringify(r.body).slice(0, 200)}`)
779
784
  out.push(...r.body.texts)
@@ -785,10 +790,10 @@ async function translateJson() {
785
790
 
786
791
  // 1. Fichiers de messages.
787
792
  const messagesDir = join(web, 'i18n', 'messages')
788
- const mainFile = join(messagesDir, `${main}.json`)
793
+ const mainFile = join(messagesDir, `${from}.json`)
789
794
  if (existsSync(mainFile)) {
790
795
  const source = JSON.parse(readFileSync(mainFile, 'utf8'))
791
- for (const locale of locales.filter((l) => l !== main)) {
796
+ for (const locale of targets) {
792
797
  const file = join(messagesDir, `${locale}.json`)
793
798
  const target = existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : {}
794
799
  const missing = []
@@ -832,15 +837,15 @@ async function translateJson() {
832
837
  if (Array.isArray(v)) v.forEach(visit)
833
838
  else if (isObj(v)) {
834
839
  const keys = Object.keys(v)
835
- if (keys.length && keys.includes(main) && keys.every((k) => /^[a-z]{2}(-[A-Za-z]{2})?$/.test(k)) && typeof v[main] === 'string') maps.push(v)
840
+ if (keys.length && keys.includes(from) && keys.every((k) => /^[a-z]{2}(-[A-Za-z]{2})?$/.test(k)) && typeof v[from] === 'string') maps.push(v)
836
841
  else Object.values(v).forEach(visit)
837
842
  }
838
843
  }
839
844
  visit(routes)
840
- for (const locale of locales.filter((l) => l !== main)) {
845
+ for (const locale of targets) {
841
846
  const todo = maps.filter((m) => m[locale] === undefined)
842
847
  if (!todo.length) continue
843
- const translated = apply ? await translate(locale, todo.map((m) => m[main])) : todo.map((m) => m[main])
848
+ const translated = apply ? await translate(locale, todo.map((m) => m[from])) : todo.map((m) => m[from])
844
849
  todo.forEach((m, i) => (m[locale] = translated[i]))
845
850
  changes += todo.length
846
851
  console.log(`${apply ? '✔' : '•'} site-routes.json : ${todo.length} titre(s) ${locale} ${apply ? 'traduit(s)' : 'à traduire'}`)
package/dist/index.d.ts CHANGED
@@ -1090,7 +1090,7 @@ export declare function ActorName(props: {
1090
1090
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1091
1091
  * le vérifie.
1092
1092
  */
1093
- export declare const KIT_VERSION = "2.39.0";
1093
+ export declare const KIT_VERSION = "2.40.0";
1094
1094
  /**
1095
1095
  * Données de la page proposées comme colonnes.
1096
1096
  *
package/dist/index.js CHANGED
@@ -1260,7 +1260,7 @@ function explainGrantError(error) {
1260
1260
  * quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
1261
1261
  * le vérifie.
1262
1262
  */
1263
- const KIT_VERSION = "2.39.0";
1263
+ const KIT_VERSION = "2.40.0";
1264
1264
  /**
1265
1265
  * Signale ce Studio au service du kit, une fois par montage.
1266
1266
  *
@@ -1603,7 +1603,7 @@ function useKitUpdate() {
1603
1603
  !controller.signal.aborted && body?.version && setLatest(body.version);
1604
1604
  }).catch(() => {}), () => controller.abort();
1605
1605
  }, []);
1606
- let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.39.0") > 0);
1606
+ let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.40.0") > 0);
1607
1607
  return {
1608
1608
  current: KIT_VERSION,
1609
1609
  latest,