@uniweb/build 1.13.4 → 1.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/build",
3
- "version": "1.13.4",
3
+ "version": "1.13.5",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -60,8 +60,8 @@
60
60
  "@uniweb/content-writer": "~1.3.1",
61
61
  "@uniweb/schemas": "~1.6.7",
62
62
  "@uniweb/projections": "~1.2.8",
63
- "@uniweb/theming": "~1.2.1",
64
- "@uniweb/semantic-parser": "~1.13.0"
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/i18n/audit.js CHANGED
@@ -11,6 +11,8 @@ import { readFile, writeFile } from 'fs/promises'
11
11
  import { existsSync } from 'node:fs'
12
12
  import { join } from 'node:path'
13
13
  import { translationKeepsMarkup } from './merge.js'
14
+ import { KEPT_FILE } from './locales.js'
15
+ import { standingFlags } from '../uwx/locale-sync.js'
14
16
 
15
17
  /**
16
18
  * Audit a locale file against the manifest
@@ -42,6 +44,8 @@ export async function auditLocale(localesPath, locale) {
42
44
  }
43
45
 
44
46
  const translations = JSON.parse(await readFile(localePath, 'utf-8'))
47
+ const keptPath = join(localesPath, KEPT_FILE)
48
+ const kept = existsSync(keptPath) ? JSON.parse(await readFile(keptPath, 'utf-8')) : {}
45
49
  const translationHashes = new Set(Object.keys(translations))
46
50
 
47
51
  const valid = []
@@ -57,8 +61,9 @@ export async function auditLocale(localesPath, locale) {
57
61
  const source = unit.source
58
62
  const translation = getTranslationText(translations[hash])
59
63
  // Made from an older source text (`locale-sync.js::settleEntry`). It still shows.
60
- if (translations[hash]?.outdated) {
61
- outdated.push({ hash, source, translation, was: [...new Set(Object.values(translations[hash].outdated))] })
64
+ const standing = standingFlags(translations[hash], translations, locale, kept)
65
+ if (Object.keys(standing).length) {
66
+ outdated.push({ hash, source, translation, was: [...new Set(Object.values(standing))] })
62
67
  continue
63
68
  }
64
69
  valid.push({ hash, source, translation })
package/src/i18n/index.js CHANGED
@@ -16,7 +16,8 @@ import { availableLocales, resolveLocaleList, localesToBuild } from './locales.j
16
16
  import { extractTranslatableContent } from './extract.js'
17
17
  import { dataBlockModels } from './data-models.js'
18
18
  import { syncManifests, formatSyncReport, formatKeptTranslations } from './sync.js'
19
- import { keepEditedTranslations, rowsWantTranslation, manifestRows } from './outdated.js'
19
+ import { keepEditedTranslations, rowsWantTranslation, manifestRows, settleFlags } from './outdated.js'
20
+ import { readKept, standingFlags } from '../uwx/locale-sync.js'
20
21
  import { mergeTranslations, generateAllLocales } from './merge.js'
21
22
  import { auditLocale, cleanLocale, formatAuditReport } from './audit.js'
22
23
  import {
@@ -186,6 +187,7 @@ export async function extractManifest(siteRoot, siteContent, options = {}) {
186
187
  // Generate sync report
187
188
  const report = syncManifests(previousManifest, manifest)
188
189
 
190
+ settleFlags(siteRoot, { sourceLocale: manifest.defaultLocale, dryRun })
189
191
  // What the manifest is about to forget says what an edited text's translation was made from.
190
192
  report.kept = keepEditedTranslations(siteRoot, manifestRows(previousManifest), manifestRows(manifest), {
191
193
  sourceLocale: manifest.defaultLocale,
@@ -272,6 +274,7 @@ export async function getTranslationStatus(siteRoot, options = {}) {
272
274
  const totalUnits = Object.keys(manifest.units).length
273
275
 
274
276
  const status = {}
277
+ const kept = readKept(siteRoot)
275
278
 
276
279
  for (const locale of locales) {
277
280
  const localePath = join(localesPath, `${locale}.json`)
@@ -296,7 +299,7 @@ export async function getTranslationStatus(siteRoot, options = {}) {
296
299
 
297
300
  for (const hash of Object.keys(manifest.units)) {
298
301
  // An entry flagged `outdated` still renders, and is not this text's translation.
299
- if (translations[hash]?.outdated) {
302
+ if (Object.keys(standingFlags(translations[hash], translations, locale, kept)).length) {
300
303
  outdated++
301
304
  } else if (translatedHashes.has(hash)) {
302
305
  translated++
@@ -17,7 +17,7 @@
17
17
  import { computeHash } from './hash.js'
18
18
  import { toPlainText } from './merge.js'
19
19
  import { isSmallEdit, wordOverlap } from './word-overlap.js'
20
- import { discoverLocales, loadLocaleTranslations, translationFor, addTranslationEntries } from '../uwx/locale-sync.js'
20
+ import { discoverLocales, loadLocaleTranslations, translationFor, addTranslationEntries, readKept, standingFlags } from '../uwx/locale-sync.js'
21
21
 
22
22
  // A language's words for a text here. Not an empty one, nor the text's own: `uniweb i18n init` starts a
23
23
  // language's file with each text's source, and that is nothing to keep.
@@ -144,3 +144,29 @@ export function keepEditedTranslations(siteRoot, previous, current, { sourceLoca
144
144
  }
145
145
  return kept
146
146
  }
147
+
148
+ /**
149
+ * Take out of each language's file a flag whose entry has been written over (`standingFlags`), so the file
150
+ * says what a push and `uniweb i18n status` already read. On a site with no backend nothing else would.
151
+ *
152
+ * @param {string} siteRoot
153
+ * @param {object} [o]
154
+ * @param {string} [o.sourceLocale]
155
+ * @param {boolean} [o.dryRun]
156
+ */
157
+ export function settleFlags(siteRoot, { sourceLocale = null, dryRun = false } = {}) {
158
+ if (dryRun) return
159
+ const kept = readKept(siteRoot)
160
+ for (const [locale, table] of Object.entries(languageTables(siteRoot, sourceLocale))) {
161
+ const settled = {}
162
+ for (const [hash, entry] of Object.entries(table)) {
163
+ if (!entry?.outdated) continue
164
+ const standing = standingFlags(entry, table, locale, kept)
165
+ if (Object.keys(standing).length === Object.keys(entry.outdated).length) continue
166
+ const { outdated: _flags, ...rest } = entry
167
+ if (Object.keys(standing).length) settled[hash] = { ...rest, outdated: standing }
168
+ else settled[hash] = Object.keys(rest).length === 1 && typeof rest.default === 'string' ? rest.default : rest
169
+ }
170
+ if (Object.keys(settled).length) addTranslationEntries(siteRoot, locale, settled)
171
+ }
172
+ }
@@ -180,6 +180,44 @@ export function restoreKept(localized, held, files = null) {
180
180
  return out
181
181
  }
182
182
 
183
+ /**
184
+ * ⭐ WORDS WRITTEN OVER A FLAGGED TRANSLATION END ITS FLAG, as an edit in the app's cell does: whoever typed
185
+ * them reviewed it, whatever they left beside them in the file. What the flag was made with is what the app
186
+ * keeps for the older text, else that text's own entry, which a file edit's flag leaves in place. With
187
+ * neither left to compare, it holds. ⛔ Until 2026-10-31 a new `default` beside `outdated` stayed flagged: a
188
+ * push wrote the map's entry from it.
189
+ *
190
+ * @param {string} words - what the row reads
191
+ * @param {string} older - the text the flag names
192
+ * @param {Array} [held] - the inline content the app keeps for that text in this language
193
+ * @param {object} table - the language's translation file
194
+ * @param {object} context - the row's translation context
195
+ * @returns {boolean}
196
+ */
197
+ function flagHolds(words, older, held, table, context) {
198
+ const made = Array.isArray(held) ? elementText({ content: held }) : toPlainText(translationFor(table[computeHash(older)], context))
199
+ return typeof made !== 'string' || computeHash(made) === computeHash(words)
200
+ }
201
+
202
+ /**
203
+ * An entry's flags that still hold, by place (`flagHolds`): what it is outdated in, whatever else it says.
204
+ *
205
+ * @param {*} entry - a translation file's entry
206
+ * @param {object} table - the language's translation file
207
+ * @param {string} locale
208
+ * @param {object} [kept] - what `readKept` gives
209
+ * @returns {{ [place: string]: string }}
210
+ */
211
+ export function standingFlags(entry, table, locale, kept = {}) {
212
+ return Object.fromEntries(
213
+ Object.entries(entry?.outdated || {}).filter(([place, older]) => {
214
+ const context = { key: place }
215
+ const words = toPlainText(translationFor(entry, context))
216
+ return typeof words === 'string' && flagHolds(words, older, kept[place]?.['@']?.translations?.[older]?.[locale], table, context)
217
+ }),
218
+ )
219
+ }
220
+
183
221
  /**
184
222
  * ⭐ WHICH ROWS ARE OUTDATED IS THE TRANSLATION FILES' TO SAY, and the app reads it from `@.translations`:
185
223
  * a row is outdated when its translation is kept there under a similar text (`olderSourceOf`). So a flagged
@@ -206,14 +244,17 @@ function mapWithFlags(at, localized, { sourceLocale, translations, context, free
206
244
  const read = blockElements(localized[locale])
207
245
  if (read.length !== rows.length) continue
208
246
  const keys = rows.map((row) => elementText(row))
209
- const olderAt = (key) => (key ? table[computeHash(key)]?.outdated?.[place] : undefined)
210
- const claimed = new Set(keys.map(olderAt))
211
- keys.forEach((key, i) => {
212
- const older = olderAt(key)
213
- if (typeof older === 'string' && older !== key && !map?.[older]?.[locale]) (writable()[older] ||= {})[locale] = read[i].content
247
+ const flagged = keys.map((key, i) => {
248
+ const older = key ? table[computeHash(key)]?.outdated?.[place] : undefined
249
+ if (typeof older !== 'string' || older === key) return null
250
+ return flagHolds(elementText(read[i]), older, map?.[older]?.[locale], table, context) ? older : null
251
+ })
252
+ const claimed = new Set(flagged)
253
+ flagged.forEach((older, i) => {
254
+ if (older && !map?.[older]?.[locale]) (writable()[older] ||= {})[locale] = read[i].content
214
255
  })
215
256
  keys.forEach((key, i) => {
216
- if (!key || olderAt(key) || translationFor(table[computeHash(key)], context) === undefined) return
257
+ if (!key || flagged[i] || translationFor(table[computeHash(key)], context) === undefined) return
217
258
  const says = elementText(read[i])
218
259
  for (const [older, byLocale] of Object.entries(map || {})) {
219
260
  if (older === key || claimed.has(older) || !Array.isArray(byLocale?.[locale]) || !isSmallEdit(older, key)) continue