From 82ca08ec671ecd36d572b644df911f9836dcc560 Mon Sep 17 00:00:00 2001 From: Noa Virellia Date: Mon, 18 May 2026 22:16:37 +0800 Subject: [PATCH] feat(i18n): Layout derives locale/currentPath, threads t to Nav+Footer --- src/layouts/Layout.astro | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 40dda4b..359eb69 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -1,6 +1,7 @@ --- import Nav from '../components/Nav.astro'; import Footer from '../components/Footer.astro'; +import { getTranslations } from '../i18n/utils'; interface Props { title?: string; @@ -16,12 +17,18 @@ const { noindex = false, } = Astro.props; +const locale = Astro.currentLocale ?? 'en'; +const rawPath = Astro.url.pathname; +const currentPath = + locale === 'zh-cn' ? rawPath.replace(/^\/zh-cn/, '') || '/' : rawPath; + +const t = getTranslations(locale); const siteUrl = Astro.site?.href || ''; const canonicalUrl = `${siteUrl.replace(/\/$/, '')}${canonicalPath}`; --- - + @@ -59,9 +66,9 @@ const canonicalUrl = `${siteUrl.replace(/\/$/, '')}${canonicalPath}`; /> -