Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: i18n #343

Merged
merged 14 commits into from
Feb 23, 2024
Merged

feature: i18n #343

merged 14 commits into from
Feb 23, 2024

Conversation

la3rence
Copy link
Owner

@la3rence la3rence commented Jan 28, 2024

Must

  • 文章语言切换
  • 测试同时支持三种语言
  • 索引页按语言重新过滤,移除重复文章
  • RSS Feed 适配
  • 为当前英文文章提供中文版本
  • 测试仅配置默认语言
  • 测试切换默认语言

Optional

  • 网站各类 Menu、Footer 等适配 i18n
  • 适配非文章页 (About, Privacy Policy...)
  • 按用户操作系统语言自动适配默认语言

#342

对于同一篇博客,同时提供比如中英双语的两份 markdown 文件,默认展示默认的语言版本(比如 zh 中文)。进入中文页面后,如果当前文章存在其他语言的版本,则在页面顶部添加 i18n 国际化提示,让用户可以直接跳转到另一种语言(反之亦然)。

对于没有提供非默认语言的其他语言的文章,则页面保持现状,且 URL 不变。

文件名和 URL 实例参考 (设定中文为默认语言,其他语言不受任何限制,只需添加对应 markdown;
默认语言的中间后缀还得想方法去兼容当前现有的 URL,不然历史的 URL 会失效,除非手动写跳转逻辑):

语言 文件名 URL RSS
中文 article.md or article.zh.md example.com/blog/article or example.com/zh/blog/article atom.xml or /zh/atom.xml
英文 article.en.md example.com/en/blog/article /en/atom.xml
日文 article.ja.md example.com/ja/blog/article /ja/atom.xml

首页/索引页只展示默认语言的文章列表,如果该文章不存在默认语言版本则不在首页展示(否则会出现同一篇博客出现重复的情况),基于此,索引页也需要实现 i18n:

example.com 页面只展示默认语言文章,example.com/zh 同样可访问。
example.com/en 只展示有 en 版本的文章。

因此每一篇文章无论用几种语言撰写,都有必要提供一份默认语言的版本。
理论上,如果 locales 只有一种语言(默认),则网站所有 URL 和历史 URL 一致。

lib/ssg.mjs Fixed Show fixed Hide fixed
@la3rence la3rence added the i18n label Jan 28, 2024
@la3rence la3rence marked this pull request as draft January 28, 2024 10:48
@la3rence la3rence changed the title feature: i18n feature(wip): i18n Jan 28, 2024
@k8s-ci-bot k8s-ci-bot added the wip label Jan 28, 2024
@la3rence la3rence self-assigned this Jan 28, 2024
@la3rence la3rence added this to the i18n milestone Jan 28, 2024
lib/ssg.mjs Dismissed Show dismissed Hide dismissed
@la3rence la3rence marked this pull request as ready for review February 23, 2024 12:50
@la3rence la3rence removed the wip label Feb 23, 2024
@la3rence la3rence changed the title feature(wip): i18n feature: i18n Feb 23, 2024
@la3rence la3rence merged commit b6319cd into main Feb 23, 2024
6 checks passed
@delete-merged-branch delete-merged-branch bot deleted the feat/i18n branch February 23, 2024 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants