@ -1,4 +1,4 @@
|
||||
import { DEFAULT_LOCALE, type Locale } from './config';
|
||||
import { DEFAULT_LOCALE, type Locale } from '@/i18n/config';
|
||||
|
||||
/**
|
||||
* 单文件翻译字典。
|
||||
@ -18,18 +18,25 @@ type OtherLocale = Exclude<Locale, typeof DEFAULT_LOCALE>;
|
||||
type TranslationEntry = Partial<Record<OtherLocale, string>>;
|
||||
|
||||
export const dict: Record<string, TranslationEntry> = {
|
||||
Portfolio: { cn: '作品集' },
|
||||
'All Shows': { cn: '全部走秀' },
|
||||
// ── 导航 / Navigation ──
|
||||
'About': { cn: '关于' },
|
||||
'All Shows': { cn: '全部走秀' },
|
||||
'Contact': { cn: '联系' },
|
||||
'Contact Us': { cn: '联系我们' },
|
||||
'Home': { cn: '首页' },
|
||||
'Latest Projects': { cn: '最新项目' },
|
||||
About: { cn: '关于' },
|
||||
'Contact Us': { cn: '联系我们' },
|
||||
Login: { cn: '登录' },
|
||||
Signup: { cn: '注册' },
|
||||
Contact: { cn: '联系' },
|
||||
'Back to top': { cn: '回到顶部' },
|
||||
'Login': { cn: '登录' },
|
||||
'Portfolio': { cn: '作品集' },
|
||||
'Runway Archive': { cn: '走秀档案' },
|
||||
'Signup': { cn: '注册' },
|
||||
|
||||
// ── 控件 / Controls ──
|
||||
'Back to top': { cn: '回到顶部' },
|
||||
'Next': { cn: '下一组' },
|
||||
'Previous': { cn: '上一组' },
|
||||
|
||||
// ── 页脚 / Footer ──
|
||||
'© 2026 PORTFOLIO STUDIO. ALL RIGHTS RESERVED.': { cn: '© 2026 PORTFOLIO STUDIO. 保留所有权利。' },
|
||||
Previous: { cn: '上一组' },
|
||||
Next: { cn: '下一组' },
|
||||
};
|
||||
|
||||
/** 把 {name} 形式的占位符替换成参数值。 */
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { getLocaleByPath } from 'astro:i18n';
|
||||
import { DEFAULT_LOCALE, LOCALES, type Locale } from './config';
|
||||
import { translate } from './dictionary';
|
||||
import { DEFAULT_LOCALE, LOCALES, type Locale } from '@/i18n/config';
|
||||
import { translate } from '@/i18n/dictionary';
|
||||
|
||||
/**
|
||||
* 从 URL 解析语言,委托 Astro 内置的 astro:i18n.getLocaleByPath。
|
||||
@ -29,5 +29,17 @@ export function useTranslations(locale: Locale) {
|
||||
return { t, locale };
|
||||
}
|
||||
|
||||
/**
|
||||
* 一行取「当前语言 + 翻译函数」,干掉每个页面重复的样板:
|
||||
* const { locale, t } = getI18n(Astro)
|
||||
* 内部用 Astro.currentLocale(与 Layout 判断语言的方式一致),
|
||||
* 取不到时回退默认语言。参数只要求含 currentLocale 字段,避免耦合 Astro 全局类型。
|
||||
*/
|
||||
export function getI18n(Astro: { currentLocale?: string | undefined }) {
|
||||
const locale = (Astro.currentLocale as Locale) ?? DEFAULT_LOCALE;
|
||||
const { t } = useTranslations(locale);
|
||||
return { locale, t };
|
||||
}
|
||||
|
||||
export { LOCALES, DEFAULT_LOCALE };
|
||||
export type { Locale };
|
||||
|
||||
Reference in New Issue
Block a user