@uniweb/build 1.13.2 → 1.13.3
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/package.json +5 -5
- package/src/site/plugin.js +5 -3
- package/src/uwx/locale-sync.js +15 -4
- package/src/uwx/site-diff.js +17 -12
- package/src/uwx/site-project.js +62 -47
- package/src/uwx/source-locale.js +21 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.3",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
"js-yaml": "^4.3.2",
|
|
57
57
|
"sharp": "^0.35.5",
|
|
58
58
|
"yaml": "^2.5.0",
|
|
59
|
-
"@uniweb/semantic-parser": "~1.13.0",
|
|
60
|
-
"@uniweb/content-writer": "~1.3.1",
|
|
61
|
-
"@uniweb/theming": "~1.2.1",
|
|
62
59
|
"@uniweb/content-reader": "~1.5.7",
|
|
60
|
+
"@uniweb/content-writer": "~1.3.1",
|
|
61
|
+
"@uniweb/projections": "~1.2.8",
|
|
63
62
|
"@uniweb/schemas": "~1.6.7",
|
|
64
|
-
"@uniweb/
|
|
63
|
+
"@uniweb/semantic-parser": "~1.13.0",
|
|
64
|
+
"@uniweb/theming": "~1.2.1"
|
|
65
65
|
},
|
|
66
66
|
"optionalDependencies": {
|
|
67
67
|
"@uniweb/runtime": "~1.3.3"
|
package/src/site/plugin.js
CHANGED
|
@@ -1170,9 +1170,11 @@ export function siteContentPlugin(options = {}) {
|
|
|
1170
1170
|
|
|
1171
1171
|
let result = html
|
|
1172
1172
|
|
|
1173
|
-
//
|
|
1174
|
-
|
|
1175
|
-
|
|
1173
|
+
// <html lang> is the language this page is in. ⛔ Until 2026-10-30 only the other locales were
|
|
1174
|
+
// rewritten, so a site written in Spanish built its default pages as `lang="en"`, the scaffold's.
|
|
1175
|
+
const lang = activeLocale || resolveDefaultLocale(contentToInject?.config)
|
|
1176
|
+
if (lang) {
|
|
1177
|
+
result = result.replace(/<html([^>]*)\slang="[^"]*"/, `<html$1 lang="${lang}"`)
|
|
1176
1178
|
}
|
|
1177
1179
|
|
|
1178
1180
|
if (!headInjection) return result
|
package/src/uwx/locale-sync.js
CHANGED
|
@@ -302,9 +302,19 @@ export function isLocalizedContent(value) {
|
|
|
302
302
|
* `add(localizedValue)` records, for each non-source locale, `hash(source) → target`
|
|
303
303
|
* (source text hashed exactly as `i18n extract` keys it). Non-string or missing
|
|
304
304
|
* values are skipped (only hashable scalars belong in the hash manifest).
|
|
305
|
+
*
|
|
306
|
+
* With `languages` (`documentLanguages`), a value in any other language is left out, and the
|
|
307
|
+
* language is named in `outside` for the caller to report: the next push of that section removes it.
|
|
305
308
|
*/
|
|
306
|
-
export function createTranslationCollector(sourceLocale, { siteRoot = null } = {}) {
|
|
309
|
+
export function createTranslationCollector(sourceLocale, { siteRoot = null, languages = null } = {}) {
|
|
307
310
|
const byLocale = {} // { locale: { hash: target } }
|
|
311
|
+
const outside = new Set() // the languages read that the site does not have
|
|
312
|
+
|
|
313
|
+
function has(locale) {
|
|
314
|
+
if (!languages || languages.includes(locale)) return true
|
|
315
|
+
outside.add(locale)
|
|
316
|
+
return false
|
|
317
|
+
}
|
|
308
318
|
// ⭐ What says each value read, in the place it was read — the push's own rule there — so the
|
|
309
319
|
// writer keeps an author's entry that says the same thing in another spelling (`reconcileTranslation`).
|
|
310
320
|
const says = {} // { locale: { hash: { plain?: (value) => boolean, values: { [contextKey]: (value) => boolean } } } }
|
|
@@ -328,7 +338,7 @@ export function createTranslationCollector(sourceLocale, { siteRoot = null } = {
|
|
|
328
338
|
const hash = computeHash(source)
|
|
329
339
|
for (const [locale, value] of Object.entries(localizedValue)) {
|
|
330
340
|
if (locale === sourceLocale) continue
|
|
331
|
-
if (typeof value !== 'string') continue
|
|
341
|
+
if (typeof value !== 'string' || !has(locale)) continue
|
|
332
342
|
const table = (byLocale[locale] ||= {})
|
|
333
343
|
noteSays(locale, hash, context, plainText ? saysAsText(value) : saysAsIs(value))
|
|
334
344
|
if (!context) {
|
|
@@ -350,7 +360,7 @@ export function createTranslationCollector(sourceLocale, { siteRoot = null } = {
|
|
|
350
360
|
// read won, and a pull wrote that one string over the author's `{ default, overrides }`.
|
|
351
361
|
// `checks` — what says each element's translation (`deriveStructuralMap`); a value as read, else.
|
|
352
362
|
function addStructuralMap(locale, map, context = null, checks = null) {
|
|
353
|
-
if (locale === sourceLocale || !map || typeof map !== 'object' || Array.isArray(map)) return
|
|
363
|
+
if (locale === sourceLocale || !map || typeof map !== 'object' || Array.isArray(map) || !has(locale)) return
|
|
354
364
|
const table = (byLocale[locale] ||= {})
|
|
355
365
|
for (const [src, target] of Object.entries(map)) {
|
|
356
366
|
if (typeof src !== 'string' || typeof target !== 'string') continue
|
|
@@ -373,6 +383,7 @@ export function createTranslationCollector(sourceLocale, { siteRoot = null } = {
|
|
|
373
383
|
// — null when the caller can't place it (e.g. layout sections have no freeform
|
|
374
384
|
// home), so it's surfaced rather than dropped.
|
|
375
385
|
function noteFreeform(locale, target, source, relpath) {
|
|
386
|
+
if (!has(locale)) return
|
|
376
387
|
freeformPending.push({ locale, target, source, relpath: relpath || null })
|
|
377
388
|
}
|
|
378
389
|
|
|
@@ -390,7 +401,7 @@ export function createTranslationCollector(sourceLocale, { siteRoot = null } = {
|
|
|
390
401
|
return null
|
|
391
402
|
}
|
|
392
403
|
|
|
393
|
-
return { add, addStructuralMap, noteFreeform, keptFreeform, byLocale, says, freeformPending }
|
|
404
|
+
return { add, addStructuralMap, noteFreeform, keptFreeform, has, byLocale, says, freeformPending, outside }
|
|
394
405
|
}
|
|
395
406
|
|
|
396
407
|
/**
|
package/src/uwx/site-diff.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
// Units are DISJOINT: a page's hash excludes its sections, a section's excludes its
|
|
24
24
|
// children, so a change lands in exactly one unit and is never double-reported.
|
|
25
25
|
// Naming comes from the projector's own helpers (`pageDirName`,
|
|
26
|
-
// `
|
|
26
|
+
// `sectionFileBases`) rather than a local copy, so a label always names a file
|
|
27
27
|
// that really exists.
|
|
28
28
|
//
|
|
29
29
|
// It needs TWO bases, and that is the non-obvious part.
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
// reported as unattributed rather than guessed at.
|
|
48
48
|
|
|
49
49
|
import { entityContentHash } from './records.js'
|
|
50
|
-
import {
|
|
50
|
+
import { sectionFileBases, pageDirName, layoutSectionPaths } from './site-project.js'
|
|
51
51
|
import { documentSourceLocale } from './source-locale.js'
|
|
52
52
|
|
|
53
53
|
// A unit's own content, with the nested collections that are their own units
|
|
@@ -94,17 +94,17 @@ export function collectSiteUnits(doc, sourceLocale = documentSourceLocale(doc))
|
|
|
94
94
|
* @param {(path: string, record: object, kind: 'info'|'page'|'section') => void} cb
|
|
95
95
|
*/
|
|
96
96
|
export function walkSiteUnits(doc, cb, sourceLocale = documentSourceLocale(doc)) {
|
|
97
|
-
const walkSections = (sections, dir) => {
|
|
97
|
+
const walkSections = (sections, dir, bases = sectionFileBases(sections)) => {
|
|
98
98
|
for (const record of sections || []) {
|
|
99
99
|
// The projector's own file rule — including an app-created section named from its
|
|
100
|
-
//
|
|
100
|
+
// type. ⚠️ The path NAMES the unit by its id; it is not always the author's file:
|
|
101
101
|
// a pull writes into an existing `1-about.md` or `@about.md` in place
|
|
102
102
|
// (`existingSectionFile`), so a reader mapping a unit to disk looks it up there.
|
|
103
103
|
// (This said "a unit's path here is the file it is written to" until 2026-10-07,
|
|
104
104
|
// and a push recorded no file for a numbered section.)
|
|
105
|
-
const base =
|
|
105
|
+
const base = bases.get(record)
|
|
106
106
|
if (base) cb(`${dir}/${base}.md`, record, 'section')
|
|
107
|
-
walkSections(record.$children, dir)
|
|
107
|
+
walkSections(record.$children, dir, bases)
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
const walkPages = (pages, parentDir) => {
|
|
@@ -251,8 +251,8 @@ export function diffSiteUnits(localDoc, remoteDoc, bases = {}) {
|
|
|
251
251
|
// settle the question. If the remote is known to sit at its base, this unit is
|
|
252
252
|
// not contested no matter what we did to it — pushing our version is the whole
|
|
253
253
|
// point — so "differs, side unknown" would be both untrue and noise. That
|
|
254
|
-
// combination is the normal state
|
|
255
|
-
//
|
|
254
|
+
// combination is the normal state when a copy has no local base, which is exactly
|
|
255
|
+
// when a refusal is most likely, so getting it wrong
|
|
256
256
|
// buried the one contested file under a list of perfectly fine ones.
|
|
257
257
|
if (weChanged === true && theyChanged === true) out.changedBoth.push(path)
|
|
258
258
|
else if (theyChanged === true) out.changedUpstream.push(path)
|
|
@@ -268,17 +268,22 @@ export function diffSiteUnits(localDoc, remoteDoc, bases = {}) {
|
|
|
268
268
|
/**
|
|
269
269
|
* Render a diff as the lines a CLI shows after a staleness refusal, ordered by the
|
|
270
270
|
* cost of getting each one wrong. Returns `[]` when there is nothing to say.
|
|
271
|
+
*
|
|
272
|
+
* `label` says a unit as the reader knows it: a unit's path names it by its id, and the
|
|
273
|
+
* author's file may be `1-hero.md`.
|
|
271
274
|
*/
|
|
272
|
-
export function describeSiteDiff(diff, { limit = 8 } = {}) {
|
|
275
|
+
export function describeSiteDiff(diff, { limit = 8, label = (path) => path } = {}) {
|
|
273
276
|
const lines = []
|
|
274
277
|
// Never let a long list silently truncate into something that reads complete.
|
|
275
|
-
const list = (
|
|
276
|
-
|
|
278
|
+
const list = (paths) => {
|
|
279
|
+
const xs = paths.map(label)
|
|
280
|
+
return xs.length > limit ? `${xs.slice(0, limit).join(', ')} … and ${xs.length - limit} more` : xs.join(', ')
|
|
281
|
+
}
|
|
277
282
|
|
|
278
283
|
if (diff.addedUpstream.length) lines.push(`Added upstream — forcing DELETES these: ${list(diff.addedUpstream)}`)
|
|
279
284
|
if (diff.changedBoth.length) lines.push(`Changed on both sides: ${list(diff.changedBoth)}`)
|
|
280
285
|
if (diff.changedUpstream.length) lines.push(`Changed upstream — forcing discards these: ${list(diff.changedUpstream)}`)
|
|
281
|
-
if (diff.changedLocally.length) lines.push(`Changed by you
|
|
286
|
+
if (diff.changedLocally.length) lines.push(`Changed by you: ${list(diff.changedLocally)}`)
|
|
282
287
|
if (diff.changedUnattributed.length) lines.push(`Differs, side unknown: ${list(diff.changedUnattributed)}`)
|
|
283
288
|
if (diff.addedLocally.length) lines.push(`Added by you (not upstream yet): ${list(diff.addedLocally)}`)
|
|
284
289
|
|
package/src/uwx/site-project.js
CHANGED
|
@@ -57,7 +57,7 @@ import { unwritableNodes } from '@uniweb/content-writer'
|
|
|
57
57
|
import { buildFreeformPath, freeformPathsFor } from '../i18n/freeform.js'
|
|
58
58
|
import { unwrapLocalized, unwrapLocalizedList } from './backfill.js'
|
|
59
59
|
import { LOCALIZED_FIELD_ASSUMPTION } from './localize.js'
|
|
60
|
-
import { documentSourceLocale } from './source-locale.js'
|
|
60
|
+
import { documentLanguages, documentSourceLocale } from './source-locale.js'
|
|
61
61
|
import { siteContentDirs } from './site-dirs.js'
|
|
62
62
|
import { gitAuthoredPages } from './git-authored.js'
|
|
63
63
|
import { layoutAreaRoute, readLayoutFolderSync, DEFAULT_LAYOUT } from '../site/layout-folder.js'
|
|
@@ -480,39 +480,61 @@ export function safeStableIdFilename(stableId) {
|
|
|
480
480
|
}
|
|
481
481
|
|
|
482
482
|
/**
|
|
483
|
-
* The `.md` file base
|
|
484
|
-
* the prune keep-set and the
|
|
485
|
-
* all use, so the path a pull harvests a
|
|
486
|
-
* stamps it back onto.
|
|
483
|
+
* The `.md` file base of each section of a page, nested ones included, since they are written as
|
|
484
|
+
* flat files in the same folder — the ONE rule the projector, the prune keep-set and the
|
|
485
|
+
* push/pull unit walk (`site-diff.js::walkSiteUnits`) all use, so the path a pull harvests a
|
|
486
|
+
* `$uuid` under is the path the next push stamps it back onto.
|
|
487
487
|
*
|
|
488
|
-
* `stable_id || $id` when the record has one (unchanged). ⛔ A section with
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
* `<type-kebab>-<last 8 hex of $uuid>`, e.g. `hero-95993360`.
|
|
488
|
+
* `stable_id || $id` when the record has one (unchanged). ⛔ A section with neither — what the
|
|
489
|
+
* app's editor creates: a `$uuid` and no stable id — used to be SKIPPED, silently, by all three.
|
|
490
|
+
* A pull then left its file out, and a push after any local edit sent the page without it, which
|
|
491
|
+
* the backend deletes (a package's absence of a stored `page_sections` item under a page it sends
|
|
492
|
+
* is a delete). So such a section is named from its type, as a person would name it: `hero`, and
|
|
493
|
+
* `hero-2` beside another. ⛔ Until 2026-10-30 it took the end of its `$uuid`, `hero-e09a1923`.
|
|
495
494
|
*
|
|
496
|
-
* The derived base is already filesystem-safe and starts with a letter, so the
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
* the
|
|
500
|
-
*
|
|
495
|
+
* The derived base is already filesystem-safe and starts with a letter, so the build reads it back
|
|
496
|
+
* verbatim as the section's stable id (no numeric prefix to strip) and `safeStableIdFilename`
|
|
497
|
+
* returns it unchanged — the push path equals the pull path. The first push after such a pull
|
|
498
|
+
* therefore gives the item that stable id; the `$uuid` is re-stamped by path, so the item keeps its
|
|
499
|
+
* identity, and the name stops depending on its neighbours.
|
|
501
500
|
*
|
|
502
|
-
* @
|
|
501
|
+
* @param {object[]} pageSections - a page's section `$`-records
|
|
502
|
+
* @returns {Map<object, string>} each record's base; a record with no stable id and no `$uuid` has none
|
|
503
503
|
*/
|
|
504
|
-
export function
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
const
|
|
515
|
-
|
|
504
|
+
export function sectionFileBases(pageSections) {
|
|
505
|
+
const records = []
|
|
506
|
+
const collect = (list) => {
|
|
507
|
+
for (const record of list || []) {
|
|
508
|
+
records.push(record)
|
|
509
|
+
collect(record?.$children)
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
collect(pageSections)
|
|
513
|
+
const bases = new Map()
|
|
514
|
+
const taken = new Set()
|
|
515
|
+
for (const record of records) {
|
|
516
|
+
const id = recordStableId(record)
|
|
517
|
+
if (!id) continue
|
|
518
|
+
const base = safeStableIdFilename(id)
|
|
519
|
+
bases.set(record, base)
|
|
520
|
+
taken.add(base)
|
|
521
|
+
}
|
|
522
|
+
for (const record of records) {
|
|
523
|
+
if (bases.has(record)) continue
|
|
524
|
+
const hex = typeof record?.$uuid === 'string' ? record.$uuid.replace(/-/g, '').toLowerCase() : ''
|
|
525
|
+
if (!/^[0-9a-f]{8,}$/.test(hex)) continue
|
|
526
|
+
const kebab = String(record?.type || '')
|
|
527
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
528
|
+
.toLowerCase()
|
|
529
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
530
|
+
.replace(/^-+|-+$/g, '')
|
|
531
|
+
const stem = /^[a-z]/.test(kebab) ? kebab : 'section'
|
|
532
|
+
let base = stem
|
|
533
|
+
for (let n = 2; taken.has(base); n++) base = `${stem}-${n}`
|
|
534
|
+
bases.set(record, base)
|
|
535
|
+
taken.add(base)
|
|
536
|
+
}
|
|
537
|
+
return bases
|
|
516
538
|
}
|
|
517
539
|
|
|
518
540
|
/**
|
|
@@ -534,14 +556,15 @@ export function pageSectionsToFiles({ pageDir, pageSections, ctx, pageContext })
|
|
|
534
556
|
const files = [] // the top level's file names, in the document's order
|
|
535
557
|
const childFiles = [] // every nested section's file name
|
|
536
558
|
let nested = false
|
|
559
|
+
const fileBases = sectionFileBases(pageSections)
|
|
537
560
|
const buildEntries = (records, top) => {
|
|
538
561
|
const entries = []
|
|
539
562
|
for (const record of records || []) {
|
|
540
|
-
// Filesystem-safe filename (= stableId when already safe; derived from
|
|
563
|
+
// Filesystem-safe filename (= stableId when already safe; derived from its type
|
|
541
564
|
// for an app-created section with no stable id); the true stableId rides in
|
|
542
565
|
// frontmatter `id:`. The sections: leaf uses the same base so the producer's
|
|
543
566
|
// filename-based resolution matches.
|
|
544
|
-
const fileBase =
|
|
567
|
+
const fileBase = fileBases.get(record)
|
|
545
568
|
if (!fileBase) continue // no stable id AND no `$uuid` → nothing to name it by
|
|
546
569
|
const stableId = recordStableId(record) || fileBase
|
|
547
570
|
// The file the author keeps it in, else a new `<fileBase>.md` (`existingSectionFile`).
|
|
@@ -936,7 +959,7 @@ function subtreeRoutes(record, route, sourceLocale) {
|
|
|
936
959
|
// none, and reading that as "none" would delete what the author wrote.
|
|
937
960
|
function pageSlugToYml(record, canon, existing, sourceLocale, ctx) {
|
|
938
961
|
if (record.is_dynamic) return dynamicOwnSlug(record, existing, sourceLocale)
|
|
939
|
-
const targets = localizedTargets(record.slug, sourceLocale)
|
|
962
|
+
const targets = localizedTargets(record.slug, sourceLocale, ctx)
|
|
940
963
|
const own = isPlainRecord(existing?.slug)
|
|
941
964
|
if (!own && ctx.routes?.siteMap && !record.is_index) {
|
|
942
965
|
if (Object.keys(targets).length) ctx.routes.slugs.set(canon, targets)
|
|
@@ -961,11 +984,11 @@ function dynamicOwnSlug(record, existing, sourceLocale) {
|
|
|
961
984
|
return typeof existing?.slug === 'string' ? own : null
|
|
962
985
|
}
|
|
963
986
|
|
|
964
|
-
// The locales of a pulled localized `slug` other than the source one.
|
|
965
|
-
function localizedTargets(slug, sourceLocale) {
|
|
987
|
+
// The locales of a pulled localized `slug` other than the source one, in the languages the site has.
|
|
988
|
+
function localizedTargets(slug, sourceLocale, ctx) {
|
|
966
989
|
if (!isPlainRecord(slug)) return {}
|
|
967
990
|
return Object.fromEntries(
|
|
968
|
-
Object.entries(slug).filter(([l, v]) => l !== sourceLocale && l !== '@' && !l.startsWith('$') && typeof v === 'string' && v)
|
|
991
|
+
Object.entries(slug).filter(([l, v]) => l !== sourceLocale && l !== '@' && !l.startsWith('$') && typeof v === 'string' && v && (ctx?.collector?.has(l) ?? true))
|
|
969
992
|
)
|
|
970
993
|
}
|
|
971
994
|
|
|
@@ -1055,16 +1078,7 @@ function parentOrderList(ymlPath) {
|
|
|
1055
1078
|
// flat `<base>.md` files in the SAME page dir, so all are kept on prune. Uses the
|
|
1056
1079
|
// safe filename (= stableId when safe) so the keep-set matches the files on disk.
|
|
1057
1080
|
function collectSectionFileBases(pageSections) {
|
|
1058
|
-
|
|
1059
|
-
const walk = (records) => {
|
|
1060
|
-
for (const record of records || []) {
|
|
1061
|
-
const base = sectionFileBase(record)
|
|
1062
|
-
if (base) bases.add(base)
|
|
1063
|
-
if (Array.isArray(record.$children)) walk(record.$children)
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
walk(pageSections)
|
|
1067
|
-
return bases
|
|
1081
|
+
return new Set(sectionFileBases(pageSections).values())
|
|
1068
1082
|
}
|
|
1069
1083
|
|
|
1070
1084
|
// Pass 2 — prune orphan section files (per page dir) and orphan page dirs (per
|
|
@@ -1367,7 +1381,7 @@ export function siteContentDocumentToProject({ document, siteRoot, backend = nul
|
|
|
1367
1381
|
|
|
1368
1382
|
// Collects target-locale translations of localized scalars as they're projected;
|
|
1369
1383
|
// flushed to locales/{locale}.json at the end (the manifest stays derivable).
|
|
1370
|
-
const collector = createTranslationCollector(sourceLocale, { siteRoot })
|
|
1384
|
+
const collector = createTranslationCollector(sourceLocale, { siteRoot, languages: documentLanguages(document, sourceLocale) })
|
|
1371
1385
|
|
|
1372
1386
|
// Put the author's own asset paths back before anything is serialized. Stored
|
|
1373
1387
|
// content carries an id and a serve URL; only the committed map knows the ref
|
|
@@ -1437,6 +1451,7 @@ export function siteContentDocumentToProject({ document, siteRoot, backend = nul
|
|
|
1437
1451
|
report.locales = writeLocaleTranslations(siteRoot, collector.byLocale, '', collector.says)
|
|
1438
1452
|
// Target-locale FREE-FORM bodies → locales/freeform/{locale}/<relpath> + manifest.
|
|
1439
1453
|
report.freeform = writeFreeformTranslations(siteRoot, collector.freeformPending)
|
|
1454
|
+
report.outsideLanguages = [...collector.outside].sort()
|
|
1440
1455
|
writePullIndex(siteRoot, ctx.newIndex)
|
|
1441
1456
|
return report
|
|
1442
1457
|
}
|
package/src/uwx/source-locale.js
CHANGED
|
@@ -55,3 +55,24 @@ export function documentSourceLocale(document) {
|
|
|
55
55
|
languages: settings?.languages,
|
|
56
56
|
})
|
|
57
57
|
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* ⭐ THE LANGUAGES A DOCUMENT SAYS ITS SITE HAS — what a pull may write translations for. What
|
|
61
|
+
* `settings.languages` lists, with the source; the source alone where it lists none, since a push
|
|
62
|
+
* lists every language a site's files make (`uwx/site.js::settingsNested`). `null` for a wildcard,
|
|
63
|
+
* which leaves them to the site's translation files.
|
|
64
|
+
*
|
|
65
|
+
* A section's `content` can hold a language the site does not have: the app keeps a document per
|
|
66
|
+
* language it edits in, whichever languages the site declares. In a file a language is made by its
|
|
67
|
+
* translation file (`i18n/locales.js`), so writing one would add the language to the site.
|
|
68
|
+
*
|
|
69
|
+
* @param {object} document - the site-content `$`-document
|
|
70
|
+
* @param {string} [sourceLocale]
|
|
71
|
+
* @returns {string[]|null}
|
|
72
|
+
*/
|
|
73
|
+
export function documentLanguages(document, sourceLocale = documentSourceLocale(document)) {
|
|
74
|
+
const listed = document?.settings?.languages
|
|
75
|
+
if (listed === '*' || (Array.isArray(listed) && listed.includes('*'))) return null
|
|
76
|
+
const codes = Array.isArray(listed) ? listed.map((l) => (typeof l === 'string' ? l : l?.code)).filter(Boolean) : []
|
|
77
|
+
return [...new Set([sourceLocale, ...codes])]
|
|
78
|
+
}
|