feat: some shit
This commit is contained in:
24
src/components/LanguagePicker.astro
Normal file
24
src/components/LanguagePicker.astro
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
import { locales, defaultLocale, getLocale } from "astro-i18n-aut";
|
||||
import { useTranslations } from "../i18n/utils";
|
||||
|
||||
const reg = new RegExp(`^\/(${Object.keys(locales).join("|")})\/`);
|
||||
function translatePath(lang: string) {
|
||||
const p = Astro.url.pathname.replace(reg, "").replace(/^\//, "");
|
||||
if (lang === defaultLocale) return `/${p}`;
|
||||
return `/${lang}/${p}`;
|
||||
}
|
||||
|
||||
const locale = getLocale(Astro.url);
|
||||
const t = useTranslations(locale);
|
||||
---
|
||||
|
||||
<ul>
|
||||
{
|
||||
Object.entries(locales).map(([lang, label]) => (
|
||||
<li>
|
||||
<a href={translatePath(lang)}>{t(label as "de")}</a>
|
||||
</li>
|
||||
))
|
||||
}
|
||||
</ul>
|
||||
Reference in New Issue
Block a user