mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 01:32: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
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user