mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
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.
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
// The receiver's messages follow a language switch while anyone listens,
|
|
// reach a later listener in the current language, and stop following once
|
|
// the controller is destroyed.
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { setLocale, t } from '../i18n/index.js';
|
|
import { SdrController } from './controller.js';
|
|
|
|
const UNAVAILABLE = 'WebUSB is unavailable in this browser';
|
|
|
|
test('a listener hears the message worded again after a switch', () => {
|
|
const c = new SdrController({ storage: null, webUsb: null });
|
|
const seen = [];
|
|
const off = c.subscribe((state) => seen.push(state.message));
|
|
try {
|
|
setLocale('es');
|
|
assert.equal(seen.at(-1), t(UNAVAILABLE));
|
|
assert.notEqual(seen.at(-1), UNAVAILABLE);
|
|
} finally {
|
|
off();
|
|
setLocale('en');
|
|
}
|
|
});
|
|
|
|
test('a listener that subscribes after a switch gets the current language', () => {
|
|
const c = new SdrController({ storage: null, webUsb: null });
|
|
c.subscribe(() => {})();
|
|
setLocale('ru');
|
|
try {
|
|
let first;
|
|
const off = c.subscribe((state) => (first ??= state.message));
|
|
off();
|
|
assert.equal(first, t(UNAVAILABLE));
|
|
} finally {
|
|
setLocale('en');
|
|
}
|
|
});
|
|
|
|
test('a destroyed controller no longer follows the language', async () => {
|
|
const c = new SdrController({ storage: null, webUsb: null });
|
|
c.subscribe(() => {});
|
|
await c.destroy();
|
|
let reworded = 0;
|
|
c._reword = () => reworded++;
|
|
setLocale('es');
|
|
setLocale('en');
|
|
assert.equal(reworded, 0);
|
|
});
|