feat(i18n): /en/ 双语骨架——路由/切换/hreflang/回退/AI 标注
- astro i18n(zh 默认无前缀,en /en/)+ locale.ts 路径工具
- Header 语言切换(同路径跨前缀跳转,预构建毫秒级)
- /en/index + /en/archives/{slug}(postsEn 优先,缺译回退 zh 正文
+ AiTranslatedBadge 虚线标注 TMT);en RSS(标题回退同策略)
- BaseLayout hreflang 双向 + x-default 指向 zh 源
- posts-en 集合(postsSchema.extend locked 润色锁)
- 坑:ts 端点文件误带 --- 开头会以 undefined:2:7 报 Unexpected token
验证: astro build 18 页 exit 0;/en/ 六文章路由+首页+rss 产物断言过;
zh 侧零回归(11 页不变);hreflang 抽查 dist/index.html
Spec: 2026-10-25_add-blog-i18n
Co-authored-by: GLM-5.3
This commit is contained in:
1 parent
cf42081614
commit
c74815b516
11 files changed
+273
-4
No files matched your search
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* UI 双语字典:组件静态文案的单一事实源。
|
||||
* 约定:key 稳定小写蛇形;zh 是源语言(先有),en 跟随;
|
||||
* 车道协作:op-gitea 扩展本表并串接五组件(Footer/SearchDialog/gallery/moments/about)。
|
||||
*/
|
||||
export type Locale = 'zh' | 'en';
|
||||
|
||||
const dict = {
|
||||
skip_to_content: { zh: '跳到正文', en: 'Skip to content' },
|
||||
nav_posts: { zh: '文章', en: 'Posts' },
|
||||
nav_gallery: { zh: '图库', en: 'Gallery' },
|
||||
nav_about: { zh: '关于', en: 'About' },
|
||||
search_label: { zh: '搜索', en: 'Search' },
|
||||
search_placeholder: { zh: '搜索文章…(Esc 关闭)', en: 'Search posts… (Esc to close)' },
|
||||
search_hint: { zh: '索引由 Pagefind 构建期生成 · 静态站零后端', en: 'Index built by Pagefind · zero-backend static site' },
|
||||
footer_copyright: { zh: '©', en: '©' },
|
||||
reading_time_min: { zh: '分钟', en: 'min' },
|
||||
category_reading: { zh: '阅读', en: 'Reading' },
|
||||
category_tech: { zh: '技术', en: 'Tech' },
|
||||
category_photo: { zh: '照片', en: 'Photo' },
|
||||
latest_photos: { zh: '最新影像', en: 'Latest photos' },
|
||||
enter_gallery: { zh: '进入图库 →', en: 'Gallery →' },
|
||||
open_source_projects: { zh: '开源 · Projects', en: 'Open Source · Projects' },
|
||||
self_hosted: { zh: '自托管', en: 'self-hosted' },
|
||||
prev_post: { zh: '上一篇', en: 'Previous' },
|
||||
next_post: { zh: '下一篇', en: 'Next' },
|
||||
ai_translated_note: {
|
||||
zh: '本文由机器翻译自中文原文,欢迎指正。',
|
||||
en: 'Machine-translated from the Chinese original. Corrections welcome.',
|
||||
},
|
||||
} as const;
|
||||
|
||||
export type UiKey = keyof typeof dict;
|
||||
|
||||
/** 取串:locale 缺省 zh;未知 key 原样返回(编译期 tsc 已挡)。 */
|
||||
export function t(key: UiKey, locale: Locale = 'zh'): string {
|
||||
return dict[key][locale] ?? dict[key].zh;
|
||||
}
|
||||
Reference in new issue
Block a user