From 7c6b554d415d9cf06127f61179b923c71615e986 Mon Sep 17 00:00:00 2001 From: tequ Date: Thu, 9 Apr 2026 12:51:09 +0900 Subject: [PATCH 1/2] Refactor i18n to use Astro's built-in Astro.currentLocale and getRelativeLocaleUrl() instead of manual URL parsing --- astro.config.mjs | 1 + src/components/Footer.astro | 49 +++++++++++++++++++++-------------- src/components/Header.jsx | 6 ++--- src/layouts/BaseLayout.astro | 5 ++-- src/layouts/DocsLayout.astro | 2 +- src/layouts/IndexLayout.astro | 16 +++++------- 6 files changed, 42 insertions(+), 37 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index 9fbc5f0..83ad662 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -16,6 +16,7 @@ export default defineConfig({ starlight({ title: 'Xahau Docs', description: 'Documentation for the Xahau blockchain', + defaultLocale: 'root', locales: { root: { label: 'English', lang: 'en' }, es: { label: 'Español', lang: 'es' }, diff --git a/src/components/Footer.astro b/src/components/Footer.astro index 479381d..074511e 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -1,11 +1,9 @@ --- import { Image } from 'astro:assets' + import { getRelativeLocaleUrl } from 'astro:i18n' import logo from '../assets/xahau-logo.svg' - const LOCALES = ['es', 'ja'] - const firstSegment = Astro.url.pathname.split('/')[1] - const locale = LOCALES.includes(firstSegment) ? firstSegment : 'en' - const p = locale !== 'en' ? `/${locale}` : '' + const locale = Astro.currentLocale ?? 'en' const translations = { en: { @@ -78,7 +76,7 @@ class="flex-none container mx-auto py-12 max-w-7xl p-6 grid grid-cols-1 md:grid-cols-10 gap-4" >
- + Xahau

@@ -92,32 +90,45 @@

Xahau

- {t.about} - {t.features} - {t.ecosystem} - {t.roadmap} - {t.break} + {t.about} + {t.features} + {t.ecosystem} + {t.roadmap} + {t.break} {t.fraud} - {t.media} + {t.media} {t.privacy}

{t.docs}

- {t.getstarted} - {t.protocol} - Hooks - Data APIs - {t.infra} - Whitepaper + {t.getstarted} + {t.protocol} + Hooks + Data APIs + {t.infra} + Whitepaper

{t.connect}

- {t.events} - Dev Contest + {t.events} + Dev Contest X GitHub -
+
diff --git a/src/layouts/IndexLayout.astro b/src/layouts/IndexLayout.astro index ce87a2a..ffc8d24 100644 --- a/src/layouts/IndexLayout.astro +++ b/src/layouts/IndexLayout.astro @@ -1,10 +1,10 @@ --- import '../styles/main.css' + import { getRelativeLocaleUrl } from 'astro:i18n' import worldmap from '../assets/worldmap.svg' import type { IndexLocale } from '../i18n/indexTranslations' import { indexTranslations } from '../i18n/indexTranslations' import BaseLayout from '../layouts/BaseLayout.astro' - import { getRelativeLocaleUrl } from 'astro:i18n' const _frontmatter = Astro.props.frontmatter @@ -95,8 +95,9 @@ {i.feat_more} + {i.feat_more} +