import { Group, Stack, Text } from "@mantine/core"; import { IconCheck } from "@tabler/icons-react"; import { localeAttributes, supportedLanguages } from "@homarr/translation"; import { useChangeLocale, useCurrentLocale, useI18n } from "@homarr/translation/client"; import { createChildrenOptions } from "../../../lib/children"; export const languageChildrenOptions = createChildrenOptions>({ useActions: (_, query) => { const normalizedQuery = query.trim().toLowerCase(); const currentLocale = useCurrentLocale(); return supportedLanguages .map((localeKey) => ({ localeKey, attributes: localeAttributes[localeKey] })) .filter( ({ attributes }) => attributes.name.toLowerCase().includes(normalizedQuery) || attributes.translatedName.toLowerCase().includes(normalizedQuery), ) .sort( (languageA, languageB) => Math.min( languageA.attributes.name.toLowerCase().indexOf(normalizedQuery), languageA.attributes.translatedName.toLowerCase().indexOf(normalizedQuery), ) - Math.min( languageB.attributes.name.toLowerCase().indexOf(normalizedQuery), languageB.attributes.translatedName.toLowerCase().indexOf(normalizedQuery), ), ) .map(({ localeKey, attributes }) => ({ key: localeKey, Component() { return ( {attributes.name} ({attributes.translatedName}) {localeKey === currentLocale && } ); }, useInteraction() { const changeLocale = useChangeLocale(); return { type: "javaScript", onSelect: () => changeLocale(localeKey) }; }, })); }, DetailComponent: () => { const t = useI18n(); return ( {t("search.mode.command.group.globalCommand.option.language.children.detail.title")} ); }, });