From 7f25617d7e6d099a8d89eb6ea6bc8e2d788c7ea6 Mon Sep 17 00:00:00 2001 From: Phaired <65019388+Phaired@users.noreply.github.com> Date: Wed, 4 Jun 2025 11:38:54 +0200 Subject: [PATCH 1/3] Add bilingual routing and translations --- README.md | 6 +- src/components/Footer.astro | 6 +- src/components/FormattedDate.astro | 5 +- src/components/Header.astro | 19 ++++-- src/components/LanguageSwitcher.astro | 22 +++++++ src/components/ReadingTime.astro | 8 ++- src/content/blog/blog-with-vps.fr.md | 66 +++++++++++++++++++ src/content/blog/blog-with-vps.md | 1 + src/content/config.ts | 2 + src/content/projects/NBodySimulation.fr.md | 38 +++++++++++ src/content/projects/NBodySimulation.md | 1 + src/content/projects/Steganography.fr.md | 34 ++++++++++ src/content/projects/Steganography.md | 1 + src/i18n/ui.ts | 46 +++++++++++++ src/layouts/Post.astro | 20 +++--- src/pages/[lang]/about.astro | 46 +++++++++++++ src/pages/{ => [lang]}/blog/[...slug].astro | 6 +- src/pages/{ => [lang]}/blog/index.astro | 37 +++++++---- src/pages/[lang]/index.astro | 46 +++++++++++++ .../{ => [lang]}/projects/[...slug].astro | 6 +- src/pages/{ => [lang]}/projects/index.astro | 37 +++++++---- src/pages/about.astro | 58 ---------------- src/pages/index.astro | 52 --------------- src/pages/rss.xml.js | 7 +- 24 files changed, 407 insertions(+), 163 deletions(-) create mode 100644 src/components/LanguageSwitcher.astro create mode 100644 src/content/blog/blog-with-vps.fr.md create mode 100644 src/content/projects/NBodySimulation.fr.md create mode 100644 src/content/projects/Steganography.fr.md create mode 100644 src/pages/[lang]/about.astro rename src/pages/{ => [lang]}/blog/[...slug].astro (70%) rename src/pages/{ => [lang]}/blog/index.astro (75%) create mode 100644 src/pages/[lang]/index.astro rename src/pages/{ => [lang]}/projects/[...slug].astro (70%) rename src/pages/{ => [lang]}/projects/index.astro (75%) delete mode 100644 src/pages/about.astro delete mode 100644 src/pages/index.astro diff --git a/README.md b/README.md index a63a102..32e72c3 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Visit the live site: [remybarranco.fr](https://remybarranco.fr) - Mathematical content support with KaTeX - Responsive design - Automatic asset optimization -- Internationalization support +- Internationalization support (`/en/` and `/fr/` URLs) - RSS feed generation - Sitemap generation - Automatic deployment via GitHub Actions @@ -123,6 +123,10 @@ Your content here... Add new projects as Markdown or MDX files in the `src/content/projects/` directory. +### Translations + +Pages are organized under `/[lang]/` where `lang` is `en` or `fr`. Strings are stored in `src/i18n/ui.ts`. Use the same keys for each language and retrieve them with `useTranslations(lang)` in your pages or components. To add a new translation, duplicate the content file with the `.fr.md` or `.en.md` suffix and set the `lang` frontmatter field. + ## 🤝 Contributing Contributions, issues, and feature requests are welcome! Feel free to check the issues page. diff --git a/src/components/Footer.astro b/src/components/Footer.astro index 125e90d..59aef4a 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -1,9 +1,13 @@ --- +import { useTranslations } from "../i18n/utils"; + +const { lang } = Astro.props; +const t = useTranslations(lang); const today = new Date(); ---