Finally structure for the project

Language versions, translations in separate files.
This commit is contained in:
Blboun3 2024-03-25 14:41:07 +01:00
parent 0a6ccd4339
commit fbd130eb8b
No known key found for this signature in database
8 changed files with 36 additions and 3 deletions

View File

@ -31,5 +31,9 @@ export default defineConfig({
routing: {
prefixDefaultLocale: true
},
fallback: {
de: "en",
fr: "en"
},
}
});

3
src/i18n/cs.js Normal file
View File

@ -0,0 +1,3 @@
export const cs = {
title: "CS Test",
};

3
src/i18n/de.js Normal file
View File

@ -0,0 +1,3 @@
export const de = {
title: "DE Test",
};

11
src/i18n/dictionary.js Normal file
View File

@ -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
};

3
src/i18n/en.js Normal file
View File

@ -0,0 +1,3 @@
export const en = {
title: "EN Test",
};

3
src/i18n/fr.js Normal file
View File

@ -0,0 +1,3 @@
export const fr = {
title: "FR Test",
};

View File

@ -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() {
}
---
<MainLayout title="sitetitle" description="sitedescription" lang={Astro.currentLocale}>
<MainLayout title={title} description="sitedescription" lang={Astro.currentLocale}>
<h1>Welcome</h1>
<p>
"homeP1"
{Astro.url.toString()}
{getLocaleByPath(Astro.currentLocale)}
</p>
</MainLayout>

View File

@ -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}/`);
}
---
<MainLayout title="sitetitle" description="sitedescription" lang="en">