feat: 多语言将中文设置为默认的语言

This commit is contained in:
2026-04-18 02:15:22 +08:00
parent a94ad59605
commit 47476d408b
8 changed files with 28 additions and 55 deletions
+5 -3
View File
@@ -12,12 +12,14 @@ export function getCopy(lang: string | undefined): SiteCopy {
return copies[DEFAULT_LANG];
}
/** Astro `getStaticPaths`为四种语言生成一页 */
/** Astro `getStaticPaths`默认语言生成无前缀路径,其他语言带前缀 */
export function langStaticPaths() {
return LANGS.map((lang) => ({ params: { lang } }));
return LANGS.map((lang) => ({
params: { lang: lang === DEFAULT_LANG ? undefined : lang },
}));
}
export type { Lang } from './locales';
export type { SiteCopy } from './types';
export { LANGS, DEFAULT_LANG, htmlLang, langLabels, hrefFor, isLang } from './locales';
export { LANGS, DEFAULT_LANG, htmlLang, langLabels, hrefFor, isLang, resolveLang } from './locales';
export type { RouteKey } from './locales';
+8 -2
View File
@@ -26,6 +26,12 @@ export function isLang(value: string | undefined): value is Lang {
export type RouteKey = '' | 'teaching-philosophy' | 'curriculum' | 'faculty' | 'about';
export function hrefFor(lang: Lang, segment: RouteKey): string {
if (!segment) return `/${lang}`;
return `/${lang}/${segment}`;
const prefix = lang === DEFAULT_LANG ? '' : `/${lang}`;
if (!segment) return prefix || '/';
return `${prefix}/${segment}`;
}
/** 从 [...lang] rest 参数解析语言,undefined 时返回默认语言 */
export function resolveLang(param: string | undefined): Lang {
return isLang(param) ? param : DEFAULT_LANG;
}