mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +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
+12
-4
@@ -1,3 +1,4 @@
|
||||
import { onLocaleChange } from '../i18n/index.js';
|
||||
import { useImagerySplitStore } from './stores/imagerySplit.js';
|
||||
import { applicationPinia } from './vueRuntime.js';
|
||||
|
||||
@@ -16,6 +17,9 @@ function defaultViewportWidth() {
|
||||
);
|
||||
}
|
||||
|
||||
// A title or label given as a function is worded when published.
|
||||
const worded = (text) => (typeof text === 'function' ? text() : text);
|
||||
|
||||
function defaultValueText(beforePercent, afterPercent) {
|
||||
return `A ${beforePercent} percent, B ${afterPercent} percent`;
|
||||
}
|
||||
@@ -30,7 +34,9 @@ function defaultValueText(beforePercent, afterPercent) {
|
||||
* `onChange` reports pointer and keyboard changes so the owner can mirror
|
||||
* them, and `requestRender` fires whenever the clamped value actually
|
||||
* changes. `destroy` is idempotent: it withdraws the line, clears the CSS
|
||||
* property and restores the scene split captured at creation once.
|
||||
* property and restores the scene split captured at creation once. The
|
||||
* titles and label may be functions, which are called again after a locale
|
||||
* change, like `formatValueText`.
|
||||
*/
|
||||
export function createImagerySplit({
|
||||
scene,
|
||||
@@ -72,9 +78,9 @@ export function createImagerySplit({
|
||||
handleClass: handleClass ?? null,
|
||||
beforeLabel,
|
||||
afterLabel,
|
||||
beforeTitle: beforeTitle ?? null,
|
||||
afterTitle: afterTitle ?? null,
|
||||
ariaLabel: ariaLabel ?? null,
|
||||
beforeTitle: worded(beforeTitle) ?? null,
|
||||
afterTitle: worded(afterTitle) ?? null,
|
||||
ariaLabel: worded(ariaLabel) ?? null,
|
||||
valueNow: beforePercent,
|
||||
valueText: formatValueText(beforePercent, 100 - beforePercent),
|
||||
},
|
||||
@@ -144,6 +150,7 @@ export function createImagerySplit({
|
||||
};
|
||||
|
||||
apply(initialValue, { render: false });
|
||||
const offLocale = onLocaleChange(publish);
|
||||
|
||||
return {
|
||||
getValue() {
|
||||
@@ -166,6 +173,7 @@ export function createImagerySplit({
|
||||
pointerId = null;
|
||||
captor = null;
|
||||
destroyed = true;
|
||||
offLocale();
|
||||
store.withdraw(key);
|
||||
if (cssProperty) cssTarget.style.removeProperty(cssProperty);
|
||||
if (scene && restoreValue != null) scene.splitPosition = restoreValue;
|
||||
|
||||
Reference in new issue
Block a user