website/src/components/LanguagePicker.astro
Max Richter 58b74bb801
Some checks failed
Deploy to GitHub Pages / build (push) Failing after 7m15s
Deploy to GitHub Pages / deploy (push) Has been skipped
feat: some shit
2024-04-03 18:07:54 +02:00

33 lines
638 B
Plaintext

---
import { locales, defaultLocale } from "astro-i18n-aut";
import { useTranslations } from "../i18n/utils";
function translatePath(lang: string) {
const split = Astro.url.pathname.split("/").filter((s) => s.length);
if (split[0] in locales) {
split.shift();
}
if (lang === defaultLocale) {
return `/${split.join("/")}`;
}
return `/${[lang, ...split].join("/")}`;
}
const t = useTranslations(Astro.url);
---
<ul>
{
Object.entries(locales).map(([lang, label]) => (
<li>
<a href={translatePath(lang)} data-astro-prefetch>
{t(label as "de")}
</a>
</li>
))
}
</ul>