feat: déclare la langue du site en français

This commit is contained in:
Jalil Arfaoui 2025-01-14 19:12:43 +01:00
parent c7d74fd44a
commit 203c5ab3fd
3 changed files with 13 additions and 41 deletions

View file

@ -37,11 +37,6 @@ const socialImage = structuredData?.image?.src
? (Astro.url.origin + structuredData.image.src) ? (Astro.url.origin + structuredData.image.src)
: Astro.url.origin + socialImageRes.src; // Get the full URL of the image (https://stackoverflow.com/a/9858694) : Astro.url.origin + socialImageRes.src; // Get the full URL of the image (https://stackoverflow.com/a/9858694)
const languages: { [key: string]: string } = {
en: "",
fr: "fr",
};
function createHref(lang: string, prefix: string, path: string): string { function createHref(lang: string, prefix: string, path: string): string {
const hasPrefix = path.startsWith(`/${prefix}/`); const hasPrefix = path.startsWith(`/${prefix}/`);

View file

@ -7,7 +7,7 @@ import { SITE } from "@data/constants";
import type { Thing, WithContext } from "schema-dts"; import type { Thing, WithContext } from "schema-dts";
// Setting expected props // Setting expected props
const { title = SITE.title, meta, structuredData, lang = "en" } = Astro.props; const { title = SITE.title, meta, structuredData, lang = "fr" } = Astro.props;
// Interface to type-check the properties // Interface to type-check the properties
interface Props { interface Props {

View file

@ -1,47 +1,24 @@
--- ---
// Import section components
import MainLayout from "@/layouts/MainLayout.astro"; import MainLayout from "@/layouts/MainLayout.astro";
import Btn404 from "@components/ui/buttons/Btn404.astro"; import Btn404 from "@components/ui/buttons/Btn404.astro";
import { SITE } from "@data/constants"; import { SITE } from "@data/constants";
// Define types for translations type Texts = {
type TranslationKeys = "en" | "fr";
type Translations = {
[key in TranslationKeys]: {
pageTitle: string; pageTitle: string;
subTitle: string; subTitle: string;
content: string; content: string;
btnTitle: string; btnTitle: string;
}; };
};
// Define variables for page content const texts: Texts = {
const defaultLang: TranslationKeys = "en";
const translations: Translations = {
en: {
pageTitle: `Page Not Found | ${SITE.title}`,
subTitle: "Oops, this isn't the tool you were looking for!",
content:
"Don't let this hiccup slow you down. Let's get you back to building your masterpiece.",
btnTitle: "Go Back",
},
fr: {
pageTitle: `Page Non Trouvée | ${SITE.title}`, pageTitle: `Page Non Trouvée | ${SITE.title}`,
subTitle: "Oops, ce n'est pas l'outil que vous recherchiez!", subTitle: "Oops, ce n'est pas l'outil que vous recherchiez!",
content: content:
"Ne laissez pas ce contretemps vous ralentir. Revenons à la construction de votre chef-d'œuvre.", "Ne laissez pas ce contretemps vous ralentir. Revenons à la construction de votre chef-d'œuvre.",
btnTitle: "Retournez", btnTitle: "Retournez",
},
}; };
// Determine language from the URL const { pageTitle, subTitle, content, btnTitle } = texts;
const urlPath = Astro.url.pathname;
const langCodeMatch = urlPath.match(/^\/(en|fr)\//);
const lang: TranslationKeys = langCodeMatch
? (langCodeMatch[1] as TranslationKeys)
: defaultLang;
const { pageTitle, subTitle, content, btnTitle } = translations[lang];
--- ---
<MainLayout title={pageTitle}> <MainLayout title={pageTitle}>