We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 357541e commit c306c43Copy full SHA for c306c43
1 file changed
src/pages/index.astro
@@ -1,16 +1,18 @@
1
---
2
import { i18n } from 'astro:config/client'
3
import IndexPage from '../components/index.astro'
4
+
5
+const locales = i18n.locales
6
+const defaultLocale = i18n.defaultLocale
7
8
-<script is:inline>
9
+<script is:inline define:vars={{ locales, defaultLocale }}>
10
// Get browser language
11
const lang = navigator.language.split('-')[0]
- const supported = i18n.locales
- const target = supported.includes(lang) ? lang : i18n.defaultLocale
12
+ const target = locales.includes(lang) ? lang : defaultLocale
13
14
// Redirect immediately
- if (target !== i18n.defaultLocale) {
15
+ if (target !== defaultLocale) {
16
window.location.href = `/${target}/`
17
}
18
</script>
0 commit comments