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 { Close as CloseIcon } 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"; type ChooseLangProps = { code?: string; onCodeChange: (ncode?: string) => void; onClose?: JSX.EventHandlerUnion; }; const ChooseLang: Component = (props) => { const [t] = createTranslator( () => import("./i18n/lang-names.json"), (code) => import(`./i18n/${code}.json`) as Promise<{ default: Record & { ["lang.auto"]: Template<{ detected: string }>; }; }>, ); const unsupportedLangCodes = createMemo(() => { return iso639_1.getAllCodes().filter((x) => !["zh", "en"].includes(x)); }); const matchedLangCode = createMemo(() => autoMatchLangTag()); return ( {t("Choose Language")} } > { props.onCodeChange(props.code ? undefined : matchedLangCode()); }} > {t("lang.auto", { detected: t(`lang.${matchedLangCode()}`) ?? matchedLangCode(), })} {t("Supported")}}> {(code) => ( {t(`lang.${code}`)} )} {t("Unsupported")}}> {(code) => ( {iso639_1.getNativeName(code)} )} ); }; export default ChooseLang;