feat: 多语言将中文设置为默认的语言
This commit is contained in:
+5
-3
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user