remember language

This commit is contained in:
vcoppe committed 2026-10-17 19:36:57 +02:00
1 parent 128338aa05
commit 8d6885d58b
3 files changed
+36 -1

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ import type { Backend } from './types';
export type { Backend } from './types'; export type { Backend } from './types';
/** Whether the page runs in the desktop app, which has the engine in its own process. */ /** Whether the page runs in the desktop app, which has the engine in its own process. */
function inDesktopApp() { export function inDesktopApp() {
return typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window; return typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;
} }
+7
View File
@@ -15,6 +15,7 @@ import {
import { browser } from '$app/environment'; import { browser } from '$app/environment';
import type { DistanceUnits, TemperatureUnits, VelocityUnits } from '$lib/units/conversions'; import type { DistanceUnits, TemperatureUnits, VelocityUnits } from '$lib/units/conversions';
import { engine } from '$lib/engine'; import { engine } from '$lib/engine';
import { languages } from '$lib/i18n/languages';
import { import {
getArrayValidator, getArrayValidator,
getLayerTreeValidator, getLayerTreeValidator,
@@ -157,6 +158,12 @@ export const settings = {
bottomPanelSize: new Setting('bottomPanelSize', 170), bottomPanelSize: new Setting('bottomPanelSize', 170),
rightPanelSize: new Setting('rightPanelSize', 240), rightPanelSize: new Setting('rightPanelSize', 240),
explorerPanelSize: new Setting('explorerPanelSize', 0), explorerPanelSize: new Setting('explorerPanelSize', 0),
/** The language chosen last, for the desktop app, which always opens the same page. */
language: new Setting<string | undefined>(
'language',
undefined,
getValueValidator<string | undefined>(Object.keys(languages), undefined)
),
/** Takes the saved values (see `Engine.openStorage`). */ /** Takes the saved values (see `Engine.openStorage`). */
connect(stored: StoredSettings) { connect(stored: StoredSettings) {
for (const key in settings) { for (const key in settings) {
@@ -18,6 +18,10 @@
import { loadFiles } from '$lib/actions/file-actions'; import { loadFiles } from '$lib/actions/file-actions';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { page } from '$app/state'; import { page } from '$app/state';
import { goto } from '$app/navigation';
import { get } from 'svelte/store';
import { getURLForLanguage } from '$lib/utils';
import { inDesktopApp } from '$lib/engine/backend';
import { hoveredPoint, slicedStatistics } from '$lib/state/selection-statistics'; import { hoveredPoint, slicedStatistics } from '$lib/state/selection-statistics';
import { engine } from '$lib/engine'; import { engine } from '$lib/engine';
import { boundsManager } from '$lib/state/bounds'; import { boundsManager } from '$lib/state/bounds';
@@ -51,11 +55,35 @@
bottomPanelWidth && bottomPanelWidth >= 540 && $elevationProfile ? 'horizontal' : 'vertical' bottomPanelWidth && bottomPanelWidth >= 540 && $elevationProfile ? 'horizontal' : 'vertical'
); );
// the language of the page, which is in its address (none for English)
let language = $derived(page.params.language ?? 'en');
// whether the language that was chosen last was gone back to (the desktop app)
let languageRestored = $state(false);
$effect(() => {
if (languageRestored) {
settings.language.set(language);
}
});
onMount(async () => { onMount(async () => {
// files that the system opens with the app while it runs // files that the system opens with the app while it runs
engine.onFilesOpened((ids) => boundsManager.fitBoundsOnLoad(ids)); engine.onFilesOpened((ids) => boundsManager.fitBoundsOnLoad(ids));
settings.connect(await engine.openStorage()); settings.connect(await engine.openStorage());
if (inDesktopApp()) {
// the window of the desktop app always opens the same page, in English: it goes to the
// language that was chosen last
const saved = get(settings.language);
if (saved !== undefined && saved !== language) {
await goto(
`${getURLForLanguage(saved, page.url.pathname)}${page.url.search}${page.url.hash}`,
{ replaceState: true }
);
}
languageRestored = true;
}
let files: string[] = JSON.parse(page.url.searchParams.get('files') || '[]'); let files: string[] = JSON.parse(page.url.searchParams.get('files') || '[]');
let ids: string[] = JSON.parse(page.url.searchParams.get('ids') || '[]'); let ids: string[] = JSON.parse(page.url.searchParams.get('ids') || '[]');
let urls: string[] = files.concat(ids.map(getURLForGoogleDriveFile)); let urls: string[] = files.concat(ids.map(getURLForGoogleDriveFile));