refactor(i18n): show the installations status through translateStatusMessage

This commit is contained in:
German Khokhlov committed 2026-11-18 16:52:52 +04:00
1 parent dc13be07c0
commit e4e7b32289
5 files changed
+11 -22

No files matched your search

+1 -1
View File
@@ -20,7 +20,7 @@ const FALLBACK_REASON = msg('Overpass temporarily unavailable');
* @param {number} [now]
* @returns {{text: string, reason?: string, seconds?: number}|{count: number, km: ?number}}
*/
export function describeInstallationFeedback(stats = {}, now = Date.now()) {
function describeInstallationFeedback(stats = {}, now = Date.now()) {
const reason = REASONS[stats.failureReason] || FALLBACK_REASON;
if (stats.loading)
return {
+3 -8
View File
@@ -2,14 +2,9 @@ import {
formatAwarenessLabel,
AWARENESS_RADIUS_M,
} from '../../data/militaryAwarenessEngine.js';
import {
formatNumber,
onLocaleChange,
t,
translateKnown,
} from '../../i18n/index.js';
import { formatNumber, onLocaleChange, t } from '../../i18n/index.js';
import { sourceStatusLabel } from '../../ui/layerNames.js';
import { translateStatusPiece } from '../../ui/statusText.js';
import { translateStatusMessage } from '../../ui/statusText.js';
import { formatQuantity } from '../../ui/unitLabels.js';
import { AWARENESS_PAGE_SIZE, AWARENESS_PAGE_ROTATE_MS } from './policy.js';
import { distanceParts } from '../../data/distanceFormat.js';
@@ -46,7 +41,7 @@ export function presentAwarenessDistance(meters) {
function presentAwarenessReason(summary = {}) {
return summary.reasonTemplate
? t(summary.reasonTemplate, summary.reasonValues)
: translateStatusPiece(summary.reason || '');
: translateStatusMessage(summary.reason || '');
}
/**
@@ -1,8 +1,8 @@
// statusMessage stays English (the analyst's empty note); displays translate it.
import test from 'node:test';
import assert from 'node:assert/strict';
import { setLocale, t, tn, translateKnown } from '../../i18n/index.js';
import { translateStatusPiece } from '../../ui/statusText.js';
import { setLocale, t, tn } from '../../i18n/index.js';
import { translateStatusMessage } from '../../ui/statusText.js';
import { createControls } from './controls.js';
function stats(state) {
@@ -110,16 +110,10 @@ for (const locale of ['es', 'ru']) {
test(`${locale}: installation statusMessage is shown in the UI language`, () => {
inLocale(locale, () => {
for (const [state, english, shown] of cases) {
const shownText = translateStatusPiece(stats(state).statusMessage);
const shownText = translateStatusMessage(stats(state).statusMessage);
assert.notEqual(shownText, english);
assert.equal(shownText, shown());
}
for (const text of [
'Too many mapped sites in view to list them all',
'Installation context unavailable',
]) {
assert.notEqual(translateKnown(text), text);
}
});
});
}
@@ -128,6 +122,6 @@ test('en: installation feedback keeps its English wording', () => {
setLocale('en');
for (const [state, english] of cases) {
assert.equal(stats(state).statusMessage, english);
assert.equal(translateStatusPiece(english), english);
assert.equal(translateStatusMessage(english), english);
}
});
+2 -2
View File
@@ -1,6 +1,6 @@
import { t } from '../i18n/index.js';
import { spaceMissionsIndexFailure } from './contextActions.js';
import { translateStatusPiece } from './statusText.js';
import { translateStatusMessage } from './statusText.js';
import { shouldExpandGlobalContextPanel } from '../rightRailPolicy.js';
export function _initGlobalContextPanel() {
@@ -113,7 +113,7 @@ export function _initGlobalContextPanel() {
if (this.destroyed || searched === false) return false;
const stats = this.installations.getStats?.();
this.showToast(
(stats?.statusMessage && translateStatusPiece(stats.statusMessage)) ||
(stats?.statusMessage && translateStatusMessage(stats.statusMessage)) ||
(stats?.status === 'zoom-in'
? t('Zoom in to search mapped installations')
: t('Nearby installations refreshed')),
+1 -1
View File
@@ -300,7 +300,7 @@ function statusPatternText(piece) {
}
/** One piece of a status line in the UI language, or as it came. */
export function translateStatusPiece(piece) {
function translateStatusPiece(piece) {
const known = translateKnown(piece);
if (known !== piece) return known;
return statusPatternText(piece) ?? piece;