mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 17:22:19 +00:00
fix(i18n): translate mapped-site feedback by its shape where it is shown
Add the Mapped Installations feedback shapes (site counts in view or around the contact, and the Overpass retry lines) to statusText.js, and show statusMessage through translateStatusPiece in the Layers panel, the nearby-search toast and the awareness panel. The voice card's analyst notes already fall back to translateStatusLine, so they pick the shapes up too.
This commit is contained in:
1 parent
93ea088f45
commit
dddd1fa03f
6 files changed
+88
-14
No files matched your search
@@ -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"]
|
||||
},
|
||||
|
||||
@@ -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 }) {
|
||||
|
||||
@@ -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')),
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+51
-1
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user