refactor(i18n): simplify language handling across components
use Astro.currentLocale as single source of truth for language remove manual lang prop passing to components components now read language from document lang attribute
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
---
|
||||
import BlogLayout from '../../layouts/BlogLayout.astro';
|
||||
import BlogList from '../../components/BlogList.tsx';
|
||||
import { type Lang } from '@/i18n/utils';
|
||||
import { defaultLang } from '@/i18n/ui';
|
||||
|
||||
// 使用Astro.currentLocale获取当前语言环境
|
||||
const lang = Astro.currentLocale as Lang || defaultLang;
|
||||
|
||||
// Sample blog data - inline for now
|
||||
const blogPosts = [
|
||||
|
||||
@@ -7,13 +7,14 @@ import { useTranslations, type Lang } from "@/i18n/utils";
|
||||
import { defaultLang } from "@/i18n/ui";
|
||||
import { personalInfo } from "@/lib/data";
|
||||
|
||||
const lang: Lang = defaultLang;
|
||||
// 使用Astro.currentLocale获取当前语言环境
|
||||
const lang = Astro.currentLocale as Lang || defaultLang;
|
||||
const t = useTranslations(lang);
|
||||
const pageTitle = t('site.title');
|
||||
---
|
||||
|
||||
<Layout title={pageTitle}>
|
||||
<GlassHeader lang={lang} client:only="react" />
|
||||
<GlassHeader client:only="react" />
|
||||
<main class="min-h-screen">
|
||||
<!-- Hero Section - Inlined Content -->
|
||||
<section class="py-32 relative overflow-hidden min-h-screen flex items-center">
|
||||
|
||||
@@ -5,13 +5,14 @@ import Footer from "@/components/Footer";
|
||||
import { useTranslations, type Lang } from "@/i18n/utils";
|
||||
import { defaultLang } from "@/i18n/ui";
|
||||
|
||||
const lang: Lang = defaultLang;
|
||||
// 使用Astro.currentLocale获取当前语言环境
|
||||
const lang = Astro.currentLocale as Lang || defaultLang;
|
||||
const t = useTranslations(lang);
|
||||
const pageTitle = t('projects.title');
|
||||
---
|
||||
|
||||
<Layout title={pageTitle}>
|
||||
<GlassHeader lang={lang} client:only="react" />
|
||||
<GlassHeader client:only="react" />
|
||||
<main class="min-h-screen">
|
||||
<!-- Projects Hero Section -->
|
||||
<section class="py-24 relative overflow-hidden">
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
---
|
||||
import BlogLayout from '../../../layouts/BlogLayout.astro';
|
||||
import BlogList from '../../../components/BlogList.tsx';
|
||||
import { type Lang } from '@/i18n/utils';
|
||||
import { defaultLang } from '@/i18n/ui';
|
||||
|
||||
// 使用Astro.currentLocale获取当前语言环境
|
||||
const lang = Astro.currentLocale as Lang || defaultLang;
|
||||
|
||||
// 示例博客数据 - 暂时内联
|
||||
const blogPosts = [
|
||||
|
||||
@@ -3,16 +3,18 @@ import Layout from "@/layouts/Layout.astro";
|
||||
import GlassHeader from "@/components/GlassHeader.tsx";
|
||||
import SkillsMarquee from "@/components/SkillsMarquee.tsx";
|
||||
import Footer from "@/components/Footer.tsx";
|
||||
import { useTranslations } from "@/i18n/utils";
|
||||
import { useTranslations, type Lang } from "@/i18n/utils";
|
||||
import { defaultLang } from "@/i18n/ui";
|
||||
import { personalInfo } from "@/lib/data";
|
||||
|
||||
const lang: "en" | "zh" = 'zh';
|
||||
// 使用Astro.currentLocale获取当前语言环境
|
||||
const lang = Astro.currentLocale as Lang || defaultLang;
|
||||
const t = useTranslations(lang);
|
||||
const pageTitle = t('site.title');
|
||||
---
|
||||
|
||||
<Layout title={pageTitle}>
|
||||
<GlassHeader lang={lang} client:only="react" />
|
||||
<GlassHeader client:only="react" />
|
||||
<main class="min-h-screen">
|
||||
<!-- Hero Section - Inlined Content -->
|
||||
<section class="py-32 relative overflow-hidden min-h-screen flex items-center">
|
||||
|
||||
@@ -5,13 +5,14 @@ import Footer from "@/components/Footer";
|
||||
import { useTranslations, type Lang } from "@/i18n/utils";
|
||||
import { defaultLang } from "@/i18n/ui";
|
||||
|
||||
const lang: Lang = 'zh';
|
||||
// 使用Astro.currentLocale获取当前语言环境
|
||||
const lang = Astro.currentLocale as Lang || defaultLang;
|
||||
const t = useTranslations(lang);
|
||||
const pageTitle = t('projects.title');
|
||||
---
|
||||
|
||||
<Layout title={pageTitle}>
|
||||
<GlassHeader lang={lang} client:only="react" />
|
||||
<GlassHeader client:only="react" />
|
||||
<main class="min-h-screen">
|
||||
<!-- Projects Hero Section -->
|
||||
<section class="py-24 relative overflow-hidden">
|
||||
|
||||
Reference in New Issue
Block a user