From 203c5ab3fdc27db1b4bd804c69ed525a9a4d2ca3 Mon Sep 17 00:00:00 2001 From: Jalil Arfaoui Date: Tue, 14 Jan 2025 19:12:43 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20d=C3=A9clare=20la=20langue=20du=20site?= =?UTF-8?q?=20en=20fran=C3=A7ais?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Meta.astro | 5 ---- src/layouts/MainLayout.astro | 2 +- src/pages/404.astro | 47 +++++++++--------------------------- 3 files changed, 13 insertions(+), 41 deletions(-) diff --git a/src/components/Meta.astro b/src/components/Meta.astro index ca9c226..22c071c 100644 --- a/src/components/Meta.astro +++ b/src/components/Meta.astro @@ -37,11 +37,6 @@ const socialImage = 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) -const languages: { [key: string]: string } = { - en: "", - fr: "fr", -}; - function createHref(lang: string, prefix: string, path: string): string { const hasPrefix = path.startsWith(`/${prefix}/`); diff --git a/src/layouts/MainLayout.astro b/src/layouts/MainLayout.astro index 8fb6bcc..2d76e95 100644 --- a/src/layouts/MainLayout.astro +++ b/src/layouts/MainLayout.astro @@ -7,7 +7,7 @@ import { SITE } from "@data/constants"; import type { Thing, WithContext } from "schema-dts"; // 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 Props { diff --git a/src/pages/404.astro b/src/pages/404.astro index e6b4bb2..fa77e20 100644 --- a/src/pages/404.astro +++ b/src/pages/404.astro @@ -1,47 +1,24 @@ --- -// Import section components import MainLayout from "@/layouts/MainLayout.astro"; import Btn404 from "@components/ui/buttons/Btn404.astro"; import { SITE } from "@data/constants"; -// Define types for translations -type TranslationKeys = "en" | "fr"; -type Translations = { - [key in TranslationKeys]: { - pageTitle: string; - subTitle: string; - content: string; - btnTitle: string; - }; +type Texts = { + pageTitle: string; + subTitle: string; + content: string; + btnTitle: string; }; -// Define variables for page content -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}`, - subTitle: "Oops, ce n'est pas l'outil que vous recherchiez!", - content: - "Ne laissez pas ce contretemps vous ralentir. Revenons à la construction de votre chef-d'œuvre.", - btnTitle: "Retournez", - }, +const texts: Texts = { + pageTitle: `Page Non Trouvée | ${SITE.title}`, + subTitle: "Oops, ce n'est pas l'outil que vous recherchiez!", + content: + "Ne laissez pas ce contretemps vous ralentir. Revenons à la construction de votre chef-d'œuvre.", + btnTitle: "Retournez", }; -// Determine language from the URL -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]; +const { pageTitle, subTitle, content, btnTitle } = texts; ---