Skip to content

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

Add site language switcher dropdown

yoma44f2da08aab9
diff --git a/apps/site/src/components/navbar/language-switcher.astro b/apps/site/src/components/navbar/language-switcher.astro
new file mode 100644
index 00000000..5185b91d
--- /dev/null
+++ b/apps/site/src/components/navbar/language-switcher.astro
@@ -0,0 +1,62 @@
+---
+import { getLocalizedPath, getSiteLocale, siteCopy } from "@/i18n";
+
+const { pathname, compact = false } = Astro.props;
+const locale = getSiteLocale(pathname);
+const copy = siteCopy[locale].nav;
+const languageOptions = [
+ {
+ locale: "zh-CN",
+ label: "简体中文",
+ path: getLocalizedPath("zh-CN", pathname),
+ },
+ {
+ locale: "en-US",
+ label: "English",
+ path: getLocalizedPath("en-US", 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}
+ 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>
diff --git a/apps/site/src/components/navbar/navbar.astro b/apps/site/src/components/navbar/navbar.astro
index e325a16e..991dd1f6 100644
--- a/apps/site/src/components/navbar/navbar.astro
+++ b/apps/site/src/components/navbar/navbar.astro
@@ -2,13 +2,12 @@
import Container from "@/components/container.astro";
import Link from "@/components/ui/link.astro";
import Dropdown from "./dropdown.astro";
+import LanguageSwitcher from "./language-switcher.astro";
import { Astronav, MenuItems, MenuIcon } from "astro-navbar";
import { getLocalizedPath, getSiteLocale, siteCopy } from "@/i18n";
const locale = getSiteLocale(Astro.url.pathname);
const copy = siteCopy[locale].nav;
-const alternateLocale = locale === "zh-CN" ? "en-US" : "zh-CN";
-const alternatePath = getLocalizedPath(alternateLocale, Astro.url.pathname);
const menuitems = [
{
title: copy.features,
@@ -84,14 +83,14 @@ const menuitems = [
<div class="lg:hidden flex items-center mt-3 gap-4">
<Link href="https://demo.edgeever.org" target="_blank" style="muted" block size="md">{copy.demo}</Link>
<Link href="https://github.com/msh01/edgeever" target="_blank" size="md" block>GitHub</Link>
- <a href={alternatePath} class="text-sm text-gray-600 hover:text-gray-900">{copy.languageLabel}</a>
+ <LanguageSwitcher pathname={Astro.url.pathname} compact />
</div>
</MenuItems>
</Astronav>
<div>
<div class="hidden lg:flex items-center gap-4">
<a href="https://demo.edgeever.org" target="_blank" class="text-gray-600 hover:text-gray-900 transition">{copy.demo}</a>
- <a href={alternatePath} class="text-gray-600 hover:text-gray-900 transition">{copy.languageLabel}</a>
+ <LanguageSwitcher pathname={Astro.url.pathname} />
<Link href="https://github.com/msh01/edgeever" target="_blank" size="md">GitHub</Link>
</div>
</div>
diff --git a/apps/site/src/i18n.ts b/apps/site/src/i18n.ts
index 79f96c86..78b7d811 100644
--- a/apps/site/src/i18n.ts
+++ b/apps/site/src/i18n.ts
@@ -34,7 +34,8 @@ export const siteCopy = {
about: "关于项目",
contact: "联系我们",
demo: "在线演示",
- languageLabel: "English",
+ language: "语言",
+ languageMenu: "切换语言",
},
hero: {
slogan: "基于 Cloudflare 全家桶自托管的免费开源『印象笔记』",
@@ -108,7 +109,8 @@ export const siteCopy = {
about: "About",
contact: "Contact",
demo: "Demo",
- languageLabel: "简体中文",
+ language: "Language",
+ languageMenu: "Change language",
},
hero: {
slogan: "A free, open-source Evernote alternative self-hosted on Cloudflare.",