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,12 +1,25 @@
|
||||
import { useTranslations, type Lang } from "@/i18n/utils";
|
||||
import { personalInfo } from "@/lib/data";
|
||||
import { motion } from "framer-motion";
|
||||
import { useState, useEffect } from "react";
|
||||
import { defaultLang } from "@/i18n/ui";
|
||||
|
||||
interface FooterProps {
|
||||
lang: Lang;
|
||||
lang?: Lang;
|
||||
}
|
||||
|
||||
export default function Footer({ lang }: FooterProps) {
|
||||
export default function Footer({ lang: propLang }: FooterProps) {
|
||||
// 优先使用props传入的语言,如果没有则尝试从HTML lang属性获取
|
||||
const [lang, setLang] = useState<Lang>(propLang || defaultLang);
|
||||
|
||||
useEffect(() => {
|
||||
// 在客户端运行时,从HTML lang属性获取当前语言
|
||||
const htmlLang = document.documentElement.lang as Lang;
|
||||
if (htmlLang && (!propLang || htmlLang !== lang)) {
|
||||
setLang(htmlLang);
|
||||
}
|
||||
}, [propLang, lang]);
|
||||
|
||||
const t = useTranslations(lang);
|
||||
return (
|
||||
<footer className="border-t border-purple-500/10 py-6 bg-gradient-to-b from-background to-muted/20 backdrop-blur-sm">
|
||||
|
||||
Reference in New Issue
Block a user