Skip to content

getSwitcherData

Generates useful data for a locale switcher component. Here is a basic implementation:

1
---
2
import { getSwitcherData, getLocale } from "i18n:astro";
3
4
const locale = getLocale();
5
const data = getSwitcherData();
6
---
7
8
<select onchange="location = this.value;">
9
{
10
data.map((e) => (
11
<option value={e.href} selected={e.locale === locale}>
12
{e.locale}
13
</option>
14
))
15
}
16
</select>