import { createMemo, For, type Component, type JSX } from "solid-js"; import Scaffold from "../material/Scaffold"; import { AppBar, IconButton, List, ListItem, ListItemButton, ListItemSecondaryAction, ListItemText, ListSubheader, Radio, Switch, Toolbar, } from "@suid/material"; import { ArrowBack } from "@suid/icons-material"; import iso639_1 from "iso-639-1"; import { autoMatchLangTag, createTranslator, SUPPORTED_LANGS, } from "../platform/i18n"; import { Title } from "../material/typography"; import type { Template } from "@solid-primitives/i18n"; import { useStore } from "@nanostores/solid"; import { $settings } from "./stores"; import { useNavigator } from "../platform/StackedRouter"; const ChooseLang: Component = () => { const { pop } = useNavigator(); const [t] = createTranslator( () => import("./i18n/lang-names.json"), (code) => import(`./i18n/${code}.json`) as Promise<{ default: Record & { ["lang.auto"]: Template<{ detected: string }>; }; }>, ); const settings = useStore($settings); const code = () => settings().language; const unsupportedLangCodes = createMemo(() => { return iso639_1.getAllCodes().filter((x) => !["zh", "en"].includes(x)); }); const matchedLangCode = createMemo(() => autoMatchLangTag()); const onCodeChange = (code?: string) => { $settings.setKey("language", code); }; return ( {t("Choose Language")} } > { onCodeChange(code() ? undefined : matchedLangCode()); }} > {t("lang.auto", { detected: t(`lang.${matchedLangCode()}`) ?? matchedLangCode(), })} {t("Supported")}}> {(c) => ( {t(`lang.${c}`)} )} {t("Unsupported")}}> {(code) => ( {iso639_1.getNativeName(code)} )} ); }; export default ChooseLang;