diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index 47932bc..2b28cf2 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -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(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 (