diff --git a/src/components/Header.astro b/src/components/Header.astro index b45b673..b300f1d 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -2,10 +2,11 @@ interface Props {} import { useTranslations } from "../i18n/utils"; +import type { Params } from "../i18n/utils"; import { Image } from "astro:assets"; import aux from "../../public/aux.svg"; -const { lang } = Astro.params; +const { lang } = Astro.params as Params; const translation = useTranslations(lang); --- diff --git a/src/components/home/Goals.astro b/src/components/home/Goals.astro index 42dd2a6..b821825 100644 --- a/src/components/home/Goals.astro +++ b/src/components/home/Goals.astro @@ -1,7 +1,8 @@ --- import { useTranslations } from "../../i18n/utils"; +import type { Params } from "../../i18n/utils"; -const { lang } = Astro.params; +const { lang } = Astro.params as Params; const translation = useTranslations(lang); --- diff --git a/src/components/home/Hero.astro b/src/components/home/Hero.astro index af81e5b..e3c6bee 100644 --- a/src/components/home/Hero.astro +++ b/src/components/home/Hero.astro @@ -2,8 +2,9 @@ import { useTranslations } from "../../i18n/utils"; import { Image } from "astro:assets"; import aux from "../../../public/aux.svg"; +import type { Params } from "../../i18n/utils"; -const { lang } = Astro.params; +const { lang } = Astro.params as Params; const translation = useTranslations(lang); --- diff --git a/src/components/home/Roadmap.astro b/src/components/home/Roadmap.astro index 819690d..76b1d1c 100644 --- a/src/components/home/Roadmap.astro +++ b/src/components/home/Roadmap.astro @@ -1,7 +1,8 @@ --- import { useTranslations } from "../../i18n/utils"; +import type { Params } from "../../i18n/utils"; -const { lang } = Astro.params; +const { lang } = Astro.params as Params; const translation = useTranslations(lang); --- diff --git a/src/components/home/Values.astro b/src/components/home/Values.astro index 99644bd..a180e3f 100644 --- a/src/components/home/Values.astro +++ b/src/components/home/Values.astro @@ -1,7 +1,8 @@ --- import { useTranslations } from "../../i18n/utils"; +import type { Params } from "../../i18n/utils"; -const { lang } = Astro.params; +const { lang } = Astro.params as Params; const translation = useTranslations(lang); --- diff --git a/src/i18n/utils.ts b/src/i18n/utils.ts index 5d4b88b..d10e23e 100644 --- a/src/i18n/utils.ts +++ b/src/i18n/utils.ts @@ -1,7 +1,21 @@ -import { ui, defaultLang } from "./ui"; +import { ui, defaultLang, languages } from "./ui"; +import type { + InferGetStaticParamsType, + InferGetStaticPropsType, + GetStaticPaths, +} from "astro"; export function useTranslations(lang: keyof typeof ui) { return function t(key: keyof (typeof ui)[typeof defaultLang]) { return ui[lang][key] || ui[defaultLang][key]; }; } + +export const getStaticPaths = (async () => { + return Object.keys(languages).map((name) => ({ + params: { lang: name as keyof typeof languages }, + })); +}) satisfies GetStaticPaths; + +export type Params = InferGetStaticParamsType; +export type Props = InferGetStaticPropsType; diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index d3f4dc0..69d2c5e 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -1,12 +1,13 @@ --- import Header from "../components/Header.astro"; +import type { Params } from "../i18n/utils"; interface Props { title: string; } const { title } = Astro.props; -const { lang } = Astro.params; +const { lang } = Astro.params as Params; --- diff --git a/src/pages/[lang]/index.astro b/src/pages/[lang]/index.astro index 6ce3961..7a5babf 100644 --- a/src/pages/[lang]/index.astro +++ b/src/pages/[lang]/index.astro @@ -1,11 +1,7 @@ --- -import { languages } from "../../i18n/ui"; import Layout from "../../layouts/Layout.astro"; import Home from "../../components/home/Home.astro"; - -export async function getStaticPaths() { - return Object.keys(languages).map((name) => ({ params: { lang: name } })); -} +export { getStaticPaths } from "../../i18n/utils"; ---