Complete public brief locale switching

This commit is contained in:
2569718930@qq.com
2026-06-24 18:53:22 +08:00
parent 3439e0e47a
commit 578f547fa7
10 changed files with 477 additions and 112 deletions
@@ -7,6 +7,7 @@ import {
} from "@/components/landing/LandingAuthActions";
import {
LANDING_LOCALE_COOKIE,
landingLocaleHref,
pickLandingLocale,
type LandingLocale,
} from "@/components/landing/landingLocale";
@@ -324,7 +325,7 @@ function InstitutionalLandingScreen({ locale }: { locale: LandingLocale }) {
<Link href="/docs/chart-guide" className="hover:text-slate-950">
{isEn ? "Guide" : "读图"}
</Link>
<Link href="/briefs" className="hover:text-slate-950">
<Link href={landingLocaleHref("/briefs", locale)} className="hover:text-slate-950">
{isEn ? "Briefs" : "简报"}
</Link>
<a href="#pricing" className="hover:text-slate-950">
@@ -104,7 +104,11 @@ export function runTests() {
"landing supported cities must render names and station codes from the generated city groups",
);
assert(source.includes("#contact"), "landing navigation must expose the contact section");
assert(source.includes('href="/briefs"'), "landing navigation must expose public Weather Market Brief assets");
assert(
source.includes("landingLocaleHref") &&
source.includes('href={landingLocaleHref("/briefs", locale)}'),
"landing navigation must expose public Weather Market Brief assets while preserving the current locale",
);
assert(source.includes('isEn ? "Briefs" : "简报"'), "landing page must label the public brief entry in both languages");
assert(source.includes('id="contact"'), "landing page must include a contact section");
assert(source.includes("yhrsc30@gmail.com"), "landing page must show the operator contact email");
@@ -38,3 +38,10 @@ export function pickLandingLocale(
export function nextLandingLocale(locale: LandingLocale): LandingLocale {
return locale === "zh-CN" ? "en-US" : "zh-CN";
}
export function landingLocaleHref(pathname: string, locale: LandingLocale): string {
const [pathWithQuery, hash] = pathname.split("#", 2);
const separator = pathWithQuery.includes("?") ? "&" : "?";
const localizedPath = `${pathWithQuery}${separator}${LANDING_LOCALE_QUERY_PARAM}=${encodeURIComponent(locale)}`;
return hash ? `${localizedPath}#${hash}` : localizedPath;
}