Skip to content

Commit c306c43

Browse files
authored
Fix: i18n not available (#65)
Fija la redirección de la home al idioma del navegador (si es diferente a ES)
1 parent 357541e commit c306c43

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/pages/index.astro

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
---
22
import { i18n } from 'astro:config/client'
33
import IndexPage from '../components/index.astro'
4+
5+
const locales = i18n.locales
6+
const defaultLocale = i18n.defaultLocale
47
---
58

6-
<script is:inline>
9+
<script is:inline define:vars={{ locales, defaultLocale }}>
710
// Get browser language
811
const lang = navigator.language.split('-')[0]
9-
const supported = i18n.locales
10-
const target = supported.includes(lang) ? lang : i18n.defaultLocale
12+
const target = locales.includes(lang) ? lang : defaultLocale
1113

1214
// Redirect immediately
13-
if (target !== i18n.defaultLocale) {
15+
if (target !== defaultLocale) {
1416
window.location.href = `/${target}/`
1517
}
1618
</script>

0 commit comments

Comments
 (0)