update tr store in +page.svelte

This commit is contained in:
llama 2025-10-18 17:35:17 +08:00
parent 6f06f81f06
commit 179968d0dc
No known key found for this signature in database
GPG key ID: 0B7543854B9413C3
2 changed files with 5 additions and 10 deletions

View file

@ -7,11 +7,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<script lang="ts">
import type { PageProps } from "./$types";
import * as _tr from "@generated/ftl-launcher";
import { setLang, windowReady, zoomWebview } from "@generated/backend-launcher";
import { getMirrors } from "@generated/backend-launcher";
import { ModuleName, setupI18n } from "@tslib/i18n";
import { onMount } from "svelte";
import { currentLang, zoomFactor } from "./stores";
import { tr, zoomFactor } from "./stores";
import Start from "./Start.svelte";
const { data }: PageProps = $props();
@ -22,21 +23,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
let selectedLang = $state(data.userLocale);
async function onLangChange(lang: string) {
// TODO: setLang could call setupI18n?
await setLang({ val: lang });
await setupI18n({ modules: [ModuleName.LAUNCHER] }, true);
$currentLang = lang;
$tr = _tr;
mirrors = (await getMirrors({})).mirrors;
}
$effect(() => {
onLangChange(selectedLang);
});
$effect(() => {
$currentLang; // rerun on i18n reinit
getMirrors({}).then(({ mirrors: _mirrors }) => (mirrors = _mirrors));
});
$effect(() => {
zoomWebview({ scaleFactor: $zoomFactor });
});

View file

@ -11,6 +11,4 @@ export const mirrorsStore = writable<GetMirrorsResponse_Pair[]>([]);
export const currentLang = writable("");
export const initialLang = writable("");
export const versionsStore = writable<GetVersionsResponse | undefined>(undefined);
export const tr = writable(_tr);
currentLang.subscribe(() => tr.set(_tr));