Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

2.2 KB
Raw Blame
---
import { getLocalizedPath, getSiteLocale, siteCopy, siteLocaleDataAttribute, siteLocaleLabels, siteLocales } from "@/i18n";

const { pathname, compact = false } = Astro.props;
const locale = getSiteLocale(pathname);
const copy = siteCopy[locale].nav;
const languageOptions = siteLocales.map((item) => ({
  locale: item,
  label: siteLocaleLabels[item],
  path: getLocalizedPath(item, pathname),
}));
const currentLanguageLabel = languageOptions.find((item) => item.locale === locale)?.label ?? copy.language;
---

<details class:list={["group relative", compact && "w-full"]}>
  <summary
    class:list={[
      "flex cursor-pointer list-none items-center justify-between gap-2 rounded-lg border border-slate-200 bg-white text-gray-600 transition hover:border-slate-300 hover:text-gray-900 [&::-webkit-details-marker]:hidden",
      compact ? "w-full px-3 py-2 text-sm" : "px-3 py-2 text-sm",
    ]}
    aria-label={copy.languageMenu}
  >
    <span>{currentLanguageLabel}</span>
    <svg class="h-3.5 w-3.5 transition group-open:rotate-180" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
      <path fill-rule="evenodd" d="M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z" clip-rule="evenodd" />
    </svg>
  </summary>
  <div
    class:list={[
      "z-50 mt-2 overflow-hidden rounded-xl border border-slate-200 bg-white p-1 shadow-lg",
      compact ? "w-full" : "absolute right-0 w-40",
    ]}
  >
    {
      languageOptions.map((item) => (
        <a
          href={item.path}
          {...{ [siteLocaleDataAttribute]: item.locale }}
          class:list={[
            "flex items-center justify-between rounded-lg px-3 py-2 text-sm transition",
            item.locale === locale
              ? "bg-slate-100 font-semibold text-slate-950"
              : "text-slate-600 hover:bg-slate-50 hover:text-slate-950",
          ]}
          aria-current={item.locale === locale ? "true" : undefined}
          lang={item.locale}
        >
          <span>{item.label}</span>
          {item.locale === locale && (
            <span class="text-xs text-brand-text" aria-hidden="true">✓</span>
          )}
        </a>
      ))
    }
  </div>
</details>