Files
ProxMenux/web/components/language-switcher.tsx
T
MacRimi f8cabb4700 Check translation contracts offline, add Swedish to the installer and enable the website languages
- Offline checks for terminal and website catalogs reject translations that change commands, paths, identifiers or placeholders
- Terminal and documentation texts that broke those contracts are corrected in every language
- Swedish can be chosen in the stable and beta installers
- The website routes, language switcher and exported pages cover the eight languages, with the shared website texts in each of them
- Website documentation translations are generated only when requested
- From PR #475 by @jcastro
2026-10-18 12:58:25 +02:00

60 lines
1.8 KiB
TypeScript

"use client"
import { useLocale, useTranslations } from "next-intl"
import { useRouter, usePathname } from "@/i18n/navigation"
import { Languages } from "lucide-react"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "./ui/dropdown-menu"
import { routing } from "@/i18n/routing"
/**
* Language switcher dropdown for the navbar.
*
* Reads the active locale from next-intl and replaces it in the URL on
* selection. The locale-aware `usePathname` and `useRouter` from
* @/i18n/navigation strip the current `[locale]` prefix when reading
* and re-add the chosen one when navigating, so the user stays on the
* same logical page after switching language.
*/
export function LanguageSwitcher() {
const t = useTranslations("language")
const locale = useLocale()
const router = useRouter()
const pathname = usePathname()
const labels: Record<string, string> = {
en: t("en"),
es: t("es"),
de: t("de"),
fr: t("fr"),
it: t("it"),
pt: t("pt"),
sk: t("sk"),
sv: t("sv"),
}
return (
<DropdownMenu>
<DropdownMenuTrigger className="flex items-center gap-1.5 px-2 py-1 rounded-md hover:bg-secondary transition-colors text-sm font-medium" aria-label={t("switcher")}>
<Languages className="h-4 w-4" />
<span className="uppercase">{locale}</span>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
{routing.locales.map((loc) => (
<DropdownMenuItem
key={loc}
onSelect={() => router.replace(pathname, { locale: loc })}
className={loc === locale ? "font-semibold" : ""}
>
{labels[loc] || loc}
</DropdownMenuItem>
))}
</DropdownMenuContent>
</DropdownMenu>
)
}