---
import {
currentLocale,
LOCALE_DIRS,
localePageHref,
warmLocaleIndex,
} from "./site-nav/locale-links";
import bootstrap from "../scripts/language-preference.js?raw";
// Use the same real-page index as the switcher: never guess a translated URL.
await warmLocaleIndex();
const pathname = Astro.url.pathname;
const locale = currentLocale(pathname);
const entryId = locale === "en" ? pathname : pathname.slice(locale.length + 1);
const targets = Object.fromEntries(
LOCALE_DIRS.flatMap((lang) => {
const href = localePageHref(entryId, lang);
return href ? [[lang, href]] : [];
}),
);
---
<script is:inline data-language-targets={JSON.stringify(targets)} data-language-locales={JSON.stringify(LOCALE_DIRS)} set:html={bootstrap} />