Finally structure for the project
Language versions, translations in separate files.
This commit is contained in:
parent
0a6ccd4339
commit
fbd130eb8b
@ -31,5 +31,9 @@ export default defineConfig({
|
||||
routing: {
|
||||
prefixDefaultLocale: true
|
||||
},
|
||||
fallback: {
|
||||
de: "en",
|
||||
fr: "en"
|
||||
},
|
||||
}
|
||||
});
|
3
src/i18n/cs.js
Normal file
3
src/i18n/cs.js
Normal file
@ -0,0 +1,3 @@
|
||||
export const cs = {
|
||||
title: "CS Test",
|
||||
};
|
3
src/i18n/de.js
Normal file
3
src/i18n/de.js
Normal file
@ -0,0 +1,3 @@
|
||||
export const de = {
|
||||
title: "DE Test",
|
||||
};
|
11
src/i18n/dictionary.js
Normal file
11
src/i18n/dictionary.js
Normal 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
3
src/i18n/en.js
Normal file
@ -0,0 +1,3 @@
|
||||
export const en = {
|
||||
title: "EN Test",
|
||||
};
|
3
src/i18n/fr.js
Normal file
3
src/i18n/fr.js
Normal file
@ -0,0 +1,3 @@
|
||||
export const fr = {
|
||||
title: "FR Test",
|
||||
};
|
@ -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>
|
@ -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">
|
||||
|
Loading…
Reference in New Issue
Block a user