33 lines
638 B
Plaintext
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>
|