diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json index 43bc3d4de9..190e377e98 100644 --- a/scripts/package-boundaries.json +++ b/scripts/package-boundaries.json @@ -566,7 +566,8 @@ "src/i18n/locale.js", "src/i18n/locales/es.json", "src/i18n/locales/ru.json", - "src/ui/layerNames.js" + "src/ui/layerNames.js", + "src/ui/statusText.js" ], "external": [] }, @@ -1242,7 +1243,9 @@ "src/i18n/locale.js", "src/i18n/locales/es.json", "src/i18n/locales/ru.json", - "src/ui/unitLabels.js" + "src/ui/unitLabels.js", + "src/ui/layerNames.js", + "src/ui/statusText.js" ], "external": ["cesium"] }, diff --git a/src/layers/awareness/panel.js b/src/layers/awareness/panel.js index 5fe2a0ac8a..f8f3d55eb9 100644 --- a/src/layers/awareness/panel.js +++ b/src/layers/awareness/panel.js @@ -2,7 +2,8 @@ import { formatAwarenessLabel, AWARENESS_RADIUS_M, } from '../../data/militaryAwarenessEngine.js'; -import { formatNumber, t, translateKnown } from '../../i18n/index.js'; +import { formatNumber, t } from '../../i18n/index.js'; +import { translateStatusPiece } from '../../ui/statusText.js'; import { formatQuantity } from '../../ui/unitLabels.js'; import { AWARENESS_PAGE_SIZE, AWARENESS_PAGE_ROTATE_MS } from './policy.js'; @@ -39,7 +40,7 @@ function presentAwarenessDistance(meters) { function presentAwarenessReason(summary = {}) { return summary.reasonTemplate ? t(summary.reasonTemplate, summary.reasonValues) - : translateKnown(summary.reason || ''); + : translateStatusPiece(summary.reason || ''); } export function createPanel({ state: layerState, services, parts, source }) { diff --git a/src/ui/contextBindings.js b/src/ui/contextBindings.js index 16a21df4f4..ef663eb702 100644 --- a/src/ui/contextBindings.js +++ b/src/ui/contextBindings.js @@ -1,4 +1,5 @@ import { t } from '../i18n/index.js'; +import { translateStatusPiece } from './statusText.js'; import { shouldExpandGlobalContextPanel } from '../rightRailPolicy.js'; export function _initGlobalContextPanel() { @@ -109,7 +110,7 @@ export function _initGlobalContextPanel() { if (this.destroyed || searched === false) return false; const stats = this.installations.getStats?.(); this.showToast( - stats?.statusMessage || + (stats?.statusMessage && translateStatusPiece(stats.statusMessage)) || (stats?.status === 'zoom-in' ? t('Zoom in to search mapped installations') : t('Nearby installations refreshed')), diff --git a/src/ui/layerPanel.js b/src/ui/layerPanel.js index 109d96c60a..7a69f74281 100644 --- a/src/ui/layerPanel.js +++ b/src/ui/layerPanel.js @@ -11,14 +11,12 @@ import { } from './layerNames.js'; export { localizeLayerName } from './layerNames.js'; import { createWeatherPanel } from './weatherPanel.js'; -import { translateFeedError, translateStatusLine } from './statusText.js'; import { - formatNumber, - getLocale, - msg, - t, - translateKnown, -} from '../i18n/index.js'; + translateFeedError, + translateStatusLine, + translateStatusPiece, +} from './statusText.js'; +import { formatNumber, getLocale, msg, t } from '../i18n/index.js'; // Feed-state values are machine ids (QA hooks, CSS feed-* classes); only the // label translates. @@ -672,7 +670,7 @@ export class LayerPanel { typeof stats.statusMessage === 'string' && stats.statusMessage.trim() ) { - return `${source} · ${translateKnown(stats.statusMessage.trim())}`; + return `${source} · ${translateStatusPiece(stats.statusMessage.trim())}`; } const ago = stats.lastUpdate ? this._timeAgo(stats.lastUpdate) : t('never'); if (stats.loading) { diff --git a/src/ui/statusText.js b/src/ui/statusText.js index b0899d55e1..b241abdbff 100644 --- a/src/ui/statusText.js +++ b/src/ui/statusText.js @@ -208,9 +208,59 @@ const STATUS_PIECE_PATTERNS = [ ], ]; +// Mapped Installations feedback (installationFeedback in +// data/installationFeedback.js): getStats().statusMessage is English data, and +// the Layers panel, the toast, the awareness panel and the voice card's analyst +// note show it through here. Keep these in step with that helper. +const MAPPED_SITE_PATTERNS = [ + [ + /^(.+) — retrying in (\d+)s$/, + ([, reason, seconds]) => + t('{reason} — retrying in {seconds}s', { + reason: translateKnown(reason), + seconds, + }), + ], + [ + /^(.+) — retry pending$/, + ([, reason]) => + t('{reason} — retry pending', { reason: translateKnown(reason) }), + ], + [/^No mapped sites in view$/, () => t('No mapped sites in view')], + [ + /^(\d+) mapped sites? in view$/, + ([, count]) => + tn( + Number(count), + '{count} mapped site in view', + '{count} mapped sites in view', + ), + ], + [ + /^No mapped sites within (\d+) km of the contact$/, + ([, km]) => + t('No mapped sites within {km} km of the contact', { + km: formatNumber(Number(km)), + }), + ], + [ + /^(\d+) mapped sites? within (\d+) km of the contact$/, + ([, count, km]) => + tn( + Number(count), + '{count} mapped site within {km} km of the contact', + '{count} mapped sites within {km} km of the contact', + { km: formatNumber(Number(km)) }, + ), + ], +]; + /** A status piece by its shape in the UI language, or null. */ function statusPatternText(piece) { - for (const [pattern, format] of STATUS_PIECE_PATTERNS) { + for (const [pattern, format] of [ + ...STATUS_PIECE_PATTERNS, + ...MAPPED_SITE_PATTERNS, + ]) { const match = pattern.exec(piece); if (match) return format(match); } diff --git a/src/voice/analystEmptyNotes.test.mjs b/src/voice/analystEmptyNotes.test.mjs index b0de16ebd5..101fe06179 100644 --- a/src/voice/analystEmptyNotes.test.mjs +++ b/src/voice/analystEmptyNotes.test.mjs @@ -74,6 +74,14 @@ const transitCoverage = [ 'transit: No feed here yet · 12 regions available', ]; +// Mapped Installations' statusMessage (data/installationFeedback.js). +const installationNotes = [ + 'military-installations: No mapped sites in view', + 'military-installations: No mapped sites within 25 km of the contact', + 'military-installations: Overpass timed out — retrying in 30s', + 'military-installations: Zoom in to search mapped installations', +]; + for (const locale of ['es', 'ru']) { for (const [layerKey, caveat] of cases) { test(`${locale}: analyst note "${caveat}" is translated`, () => { @@ -85,6 +93,19 @@ for (const locale of ['es', 'ru']) { }); } + test(`${locale}: Mapped Installations' empty note is translated on the analyst card`, () => { + inLocale(locale, () => { + for (const caveat of installationNotes) { + const notes = notesFor('military-installations', caveat); + assert.ok(notes.length > 0, 'the note is shown'); + assert.doesNotMatch( + notes.join(' | '), + /mapped sites|retrying|Overpass timed out|Zoom in/, + ); + } + }); + }); + test(`${locale}: Transit's empty note is translated on the analyst card`, () => { inLocale(locale, () => { for (const caveat of transitCoverage) {