import styles from "./Panes.module.scss";
import { Text } from "preact-i18n";
import { dispatch } from "../../../redux";
import { connectState } from "../../../redux/connector";
import {
Language,
LanguageEntry,
Languages as Langs,
} from "../../../context/Locale";
import Emoji from "../../../components/common/Emoji";
import Checkbox from "../../../components/ui/Checkbox";
import Tip from "../../../components/ui/Tip";
import tokiponaSVG from "../assets/toki_pona.svg";
type Props = {
locale: Language;
};
type Key = [string, LanguageEntry];
function Entry({ entry: [x, lang], locale }: { entry: Key } & Props) {
return (
{
if (v) {
dispatch({
type: "SET_LOCALE",
locale: x as Language,
});
}
}}>
{lang.emoji === "🙂" ? (

) : (
)}
{lang.display}
);
}
export function Component(props: Props) {
const languages = Object.keys(Langs).map((x) => [
x,
Langs[x as keyof typeof Langs],
]) as Key[];
// Get the user's system language
const preferredLanguage =
navigator.languages
?.filter((lang) =>
languages.find((l) => l[0] == lang.split("-")[0]),
)?.[0]
?.split("-")[0] ?? "en";
// This moves the user's system language to the top of the language list
const prefLangKey = languages.find((lang) => lang[0] == preferredLanguage);
if (prefLangKey) {
languages.splice(
0,
0,
languages.splice(languages.indexOf(prefLangKey), 1)[0],
);
}
return (
{languages
.filter(([, lang]) => !lang.cat)
.map(([x, lang]) => (
))}
{languages
.filter(([, lang]) => lang.cat === "const")
.map(([x, lang]) => (
))}
{languages
.filter(([, lang]) => lang.cat === "alt")
.map(([x, lang]) => (
))}
{" "}
);
}
export const Languages = connectState(Component, (state) => {
return {
locale: state.locale,
};
});