diff --git a/astro.config.mjs b/astro.config.mjs index c7d3759..fca267b 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -31,5 +31,9 @@ export default defineConfig({ routing: { prefixDefaultLocale: true }, + fallback: { + de: "en", + fr: "en" + }, } }); \ No newline at end of file diff --git a/src/i18n/cs.js b/src/i18n/cs.js new file mode 100644 index 0000000..3769d8a --- /dev/null +++ b/src/i18n/cs.js @@ -0,0 +1,3 @@ +export const cs = { + title: "CS Test", +}; \ No newline at end of file diff --git a/src/i18n/de.js b/src/i18n/de.js new file mode 100644 index 0000000..d909d71 --- /dev/null +++ b/src/i18n/de.js @@ -0,0 +1,3 @@ +export const de = { + title: "DE Test", +}; \ No newline at end of file diff --git a/src/i18n/dictionary.js b/src/i18n/dictionary.js new file mode 100644 index 0000000..4b6e154 --- /dev/null +++ b/src/i18n/dictionary.js @@ -0,0 +1,11 @@ +import { cs } from "./cs"; +import { de } from "./de"; +import { en } from "./en"; +import { fr } from "./fr"; + +export const dictionary = { + en: en, + fr: fr, + de: de, + cs: cs +}; \ No newline at end of file diff --git a/src/i18n/en.js b/src/i18n/en.js new file mode 100644 index 0000000..4c08b8f --- /dev/null +++ b/src/i18n/en.js @@ -0,0 +1,3 @@ +export const en = { + title: "EN Test", +}; \ No newline at end of file diff --git a/src/i18n/fr.js b/src/i18n/fr.js new file mode 100644 index 0000000..ce595a0 --- /dev/null +++ b/src/i18n/fr.js @@ -0,0 +1,3 @@ +export const fr = { + title: "FR Test", +}; \ No newline at end of file diff --git a/src/pages/[lang]/index.astro b/src/pages/[lang]/index.astro index 73d472d..acd7cf0 100644 --- a/src/pages/[lang]/index.astro +++ b/src/pages/[lang]/index.astro @@ -1,6 +1,8 @@ --- import { getLocaleByPath } from "astro:i18n"; import MainLayout from "../../layouts/MainLayout.astro"; +import { dictionary } from "../../i18n/dictionary"; +const { title } = dictionary[Astro.currentLocale]; export async function getStaticPaths() { return ["en", "fr", "cs", "de"].map((lang) => { @@ -9,11 +11,9 @@ export async function getStaticPaths() { } --- - +

Welcome

- "homeP1" {Astro.url.toString()} - {getLocaleByPath(Astro.currentLocale)}

\ No newline at end of file diff --git a/src/pages/index.astro b/src/pages/index.astro index 718121f..e5916c9 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,6 +1,12 @@ --- import { getLocaleByPath } from "astro:i18n"; import MainLayout from "../layouts/MainLayout.astro"; + +// Don't remove - redirects user to language version for the preffered language +if (Astro.preferredLocale) { + return Astro.redirect(`/${Astro.preferredLocale}/`); +} + ---