mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Switch language in place, without a reload
Choosing a language in the picker now applies it at once. The choice is stored and ?lang is kept in step through replaceState, and the picker keeps focus. Code that writes translated text itself re-presents it on a switch: onLocaleChange() lets an owner listen, removed at teardown, and status writers hand over a function of the locale (voice cards, scene director, SDR, draw hints, imagery split, map sources, Bhote Koshi media) so the words are rebuilt rather than re-sent. The HUD, cockpit, radio, CCTV, launch, awareness and credit texts follow the same hook, and applyDocumentTranslations can be applied again without undoing text code wrote since. The unsaved-work registry and persistLocaleAndReload existed only to guard the reload, so they go, with their catalog entries.
This commit is contained in:
1 parent
ba20bc13d8
commit
b20c80e590
87 files changed
+1194
-777
No files matched your search
+22
-1
@@ -8,7 +8,7 @@ import {
|
||||
reduceLoadingFeedback,
|
||||
reduceTrafficSyncFeedback,
|
||||
} from '../loadingFeedback.js';
|
||||
import { getLocale, t, msg } from '../i18n/index.js';
|
||||
import { getLocale, msg, onLocaleChange, t } from '../i18n/index.js';
|
||||
import { localizeLayerName } from './layerPanel.js';
|
||||
import { translateFeedError } from './statusText.js';
|
||||
import { useStatusStore } from './stores/status.js';
|
||||
@@ -127,6 +127,11 @@ export class ShellFeedback {
|
||||
this.readLayers = readLayers;
|
||||
this.store = store;
|
||||
this.destroyed = false;
|
||||
// The chips keep the English they were given, to show it again in a new
|
||||
// locale.
|
||||
this._loadingSource = { label: msg('LOADING LIVE DATA'), detail: '' };
|
||||
this._trafficLabel = msg('syncing road network');
|
||||
this._offLocale = onLocaleChange(() => this._relocalize());
|
||||
this._loadingFeedbackState = createLoadingFeedbackState();
|
||||
this._trafficSyncFeedbackState = createTrafficSyncFeedbackState();
|
||||
this._loadingFeedbackEvent = null;
|
||||
@@ -184,6 +189,7 @@ export class ShellFeedback {
|
||||
// signal rather than another animated loading stage. The progress is
|
||||
// written on every change INCLUDING the empty settled value: the reducer
|
||||
// clears it once the sync lands.
|
||||
if (presentation.label) this._trafficLabel = presentation.label;
|
||||
this._publishTraffic({
|
||||
visible: presentation.visible,
|
||||
...(presentation.label && {
|
||||
@@ -228,6 +234,7 @@ export class ShellFeedback {
|
||||
this._publishLoading({ hidden: true, state: null });
|
||||
return;
|
||||
}
|
||||
this._loadingSource = presentation;
|
||||
const localized = localizeLoadingPresentation(presentation);
|
||||
// The LABEL flaps ("LOADING LIVE DATA" -> "LOAD COMPLETE") only when it
|
||||
// changes, which matters here: this runs on every 60 ms and 500 ms tick.
|
||||
@@ -241,6 +248,19 @@ export class ShellFeedback {
|
||||
});
|
||||
}
|
||||
|
||||
/** Show the chips' last text in the current locale. */
|
||||
_relocalize() {
|
||||
if (this.destroyed) return;
|
||||
if (this._loadingSource) {
|
||||
const { label, detail } = localizeLoadingPresentation(
|
||||
this._loadingSource,
|
||||
);
|
||||
this._publishLoading({ label, detail });
|
||||
}
|
||||
if (this._trafficLabel)
|
||||
this._publishTraffic({ label: localizeStatusLabel(this._trafficLabel) });
|
||||
}
|
||||
|
||||
_publishLoading(patch) {
|
||||
const next = { ...this._loadingView, ...patch };
|
||||
if (Object.keys(next).every((key) => next[key] === this._loadingView[key]))
|
||||
@@ -329,6 +349,7 @@ export class ShellFeedback {
|
||||
destroy() {
|
||||
if (this.destroyed) return;
|
||||
this.destroyed = true;
|
||||
this._offLocale();
|
||||
this._stopLoadingFeedbackTicker();
|
||||
clearInterval(this._trafficChipTicker);
|
||||
this._trafficChipTicker = null;
|
||||
|
||||
Reference in new issue
Block a user