基于 Astro 内置 i18n 路由实现多语言支持
AstroPaperI18n — Astro 博客模板
作者 yousef8
AstroPaperI18n 是 AstroPaper 博客主题的国际化分支,基于 Astro 内置 i18n 路由增加多语言与 RTL 支持。
看看你的网站会是什么样
浏览真实页面截图,比较内容排版与手机效果。点击下方缩略图切换,放大查看整页细节。
全部页面与视图 3
截图用于了解视觉与布局,交互效果请以实际项目为准。
值得关注的模板亮点
从已有项目资料中,快速了解它的特点。
完整 RTL 支持,LTR 与 RTL 界面表现一致
界面文案、数字与日期的本地化,以及语言切换器
使用 TypeScript 提供类型安全的 i18n 集成
sitemap、RSS 与 OG 图片生成均支持 i18n
使用 Vitest 对 i18n 配置与工具进行单元测试
模板详细介绍
AstroPaperI18n 是 yousef8 维护的 AstroPaper 主题分支,目标是在保留原主题 UI 的前提下加入国际化能力。它使用 Astro 的 i18n 路由实现多语言页面,作者为阿拉伯语母语者,因此特别处理了 RTL 语言(如阿拉伯语、波斯语)的界面方向,使 LTR 与 RTL 下界面保持一致。
功能层面,该分支提供界面文案、数字与日期的本地化翻译,语言切换器,无障碍相关翻译,以及基于 TypeScript 的类型安全 i18n 集成;同时为 sitemap、RSS 和 OG 图片生成加入 i18n 支持。需要注意的是,OG 图片生成依赖的 satori 不支持 RTL 语言,RTL 的 OG 图片会出现布局问题;路由翻译(Route translations)仍处于计划阶段。
使用方式上,需要为每种语言在 src/i18n/locales 下创建翻译文件,在 src/i18n/config.ts 中定义语言配置(名称、翻译、BCP-47 语言标签、布局方向、Google 字体名),about 页面改为独立内容集合,博客文章需放在 src/content/blog 下以语言键命名的目录中,否则不会被站点收录。项目包含 Vitest 单元测试,覆盖 i18n 配置与工具,但 src/utils 与 src/config.ts 的测试尚未完成。已知问题包括屏幕阅读器模式下的样式损坏。
适合你的项目吗?
适用场景
- 需要为 AstroPaper 博客增加多语言版本的场景
- 需要阿拉伯语、波斯语等 RTL 语言支持的博客
- 希望按语言分别组织博客文章与 about 页面内容
- 需要多语言 sitemap、RSS 与 OG 图片的站点
适合人群
- 使用 Astro 并希望基于 AstroPaper 构建多语言博客的开发者
- 需要 RTL 语言支持的阿拉伯语或波斯语内容站点
- 接受通过翻译文件与语言配置手动扩展语言的用户
上手与定制指南
结合仓库当前版本的说明,按下面的资料检查内容、配置与运行要求。
- 1
在 src/i18n/locales 下按 <locale_key>.ts 命名创建翻译文件,并导出 I18nStrings 类型变量
- 2
在 src/i18n/config.ts 的 localeToProfile 中配置语言名称、翻译、BCP-47 语言标签、布局方向与 Google 字体名
- 3
about 页面使用独立内容集合,文件命名为 about.<locale_key>.md
- 4
博客文章需放在 src/content/blog 下以语言键命名的目录中,语言目录之外的文章不会被站点收录
- 5
修改语言配置后可能需要重启开发服务器才能看到变化
授权与来源资料
使用条件与限制
免费使用 · 保留许可声明本次收录的是公开仓库中采用 MIT 许可的免费版本;免费范围为该版本代码,不代表外部服务或第三方素材免费。
使用时需要遵守
- 允许免费使用、修改、商用和分发该版本代码。
- 分发代码副本或实质性部分时,保留原作者版权声明和完整 MIT 许可声明。
- 代码按现状提供;担保与责任限制以原许可证及适用法律为准。
额外费用与待核对事项
- 演示图片、字体、图标及其他第三方素材需按各自许可核对,不能仅凭代码的 MIT 许可判断。
- 域名、托管、数据库、支付或 AI 等外部服务可能另外收费。
- OG 图片生成依赖的 satori 不支持 RTL 语言,因此阿拉伯语、波斯语等 RTL 语言的 OG 图片会出现布局问题,无法正常渲染。
- 博客文章必须放在 src/content/blog 下以语言键命名的目录中,放在语言目录之外的文章不会被站点收录。
- 修改语言配置后可能需要重启开发服务器才能看到变化。
- 路由翻译(Route translations)功能尚未实现,仍处于计划阶段,当前版本不提供该能力。
- 屏幕阅读器模式下的样式目前是损坏的,需要修复,该场景下界面显示不正常。
查看原文依据
Permission is hereby granted, free of charge
许可证原文
Note: satori does not support RTL languages, causing layout issues for RTL OG images.
README 原文
Any blog outside locale folder will not be considered by the site.
README 原文
**Note:** you may need to restart the dev server to see the changes.
README 原文
- [ ] Route translations.
README 原文
https://github.com/yousef8/AstroPaperI18n/blob/main/LICENSEhttps://github.com/yousef8/AstroPaperI18n/blob/main/README.md- [ ] Styling in screen reader mode is currently broken and requires fixes.
README 原文
DeepSeek 根据仓库许可证和 README 整理 ·2026-10-12。结果仅覆盖已读取资料,依赖、图片、字体及后续条款变更以各自原文为准。
项目核对记录与介绍依据
模板资料
- 来源平台
- GitHub
- 资料与维护参考分
- 资料较完整 · 77 / 100
- 技术栈
- Astro
- 网站类型
- 博客
这个分数如何计算
本站按许可资料(最高30分)、演示链接(12分)、预览图(10分)、Star数(15分)、记录的维护时间(15分)、描述完整度(8分)、功能记录(5分)和分类资料(5分)计算。它不是代码、安全或性能测试,也不是 Google 评分;有链接不代表已实测可用。
这个项目需要核对什么
- 记录的仓库更新时间
- 2025-03-02
- 截图检查日期
- 2026-10-12
已收录演示链接。请用你的内容与屏幕尺寸检查;有演示不代表表单、认证或支付已经可用。
目录记录的主要技术栈是 Astro。请通过依赖清单和锁文件核对实际版本与托管要求。这些说明基于收录资料,不代表代码审计或部署实测。
查看具体选型方法 →介绍的制作与核对状态
介绍由 AI 辅助整理目录与仓库资料。仓库作者不等于这篇介绍的审核者。
审核声明: [email protected] · 2026-10-13
查看当时使用的来源资料
SHA-256: 92858ecf929a104c848c11c23eb73c63e194f23a04ed6a43f5a9fc1257d7e94c
2026-10-12T18:35:26.285Z
来源文件 / 仓库# AstroPaper with I18n
🌍 [اقرأنى بالعربية](README.ar.md)
<div align='center'>

</div>
[](http://commitizen.github.io/cz-cli/)  
This repository is a fork of the [AstroPaper](https://github.com/satnaing/astro-paper) theme, enhanced to support internationalization (i18n).
The fork Builds upon the original AstroPaper theme to integrate i18n functionality.
I18n integration is implemented using [Astorjs i18n routing](https://docs.astro.build/en/guides/internationalization/)
As I'm a native Arabic speaker, I made sure the i18n integration supports RTL languages (etc Arabic, Persian,...).
If god wills, this fork will maintain synchronization with the original [AstroPaper](https://github.com/satnaing/astro-paper) theme.
This Fork does not modify the original theme’s UI; it solely adds i18n support.
## Table Of Contents
- [🔥 Features](#-features)
- [UI Enhancements](#ui-enhancements)
- [i18n Features](#i18n-features)
- [🧪 Testing](#-testing)
- [Lighthouse Score](#lighthouse-score)
- [📖 How To Use](#-how-to-use)
- [🛠️ Configuration](#%EF%B8%8F-configuration)
- [🔧 Site Configurations](#-site-configurations)
- [🌐 Locale Configurations](#-locale-configurations)
- [🧞 Commands](#-commands)
- [🚧 Known Issues](#-known-issues)
## 🔥 Features
This project includes all the features of the original [AstroPaper](https://github.com/satnaing/astro-paper) theme, with the following enhancements:
### UI Enhancements
- [x] **Direction Agnostic:**
- [x] Full RTL support.
- [x] Consistent UI for both `LTR` and `RTL` directions.
### i18n Features
- [x] UI translations, including numbers and dates.
- [x] Language switcher.
- [x] Accessibility-related translations.
- [x] Type-safe i18n integration using TypeScript.
- [x] Sitemaps with i18n support ([`@astrojs/sitemap`](https://docs.astro.build/en/guides/integrations-guide/sitemap/)).
- [x] OG image generation with i18n support
- Note: satori does not support RTL languages, causing layout issues for RTL OG images.
- [x] RSS Feeds with i18n support ([`@astrojs/rss`](https://docs.astro.build/en/guides/rss/)).
- [ ] 📋 **Planned:**
- [ ] Route translations.
### 🧪 Testing
- [x] Unit testing with [Vitest](https://vitest.dev/)
- [x] Unit testing for i18n configurations and utilities
- [ ] Unit testing for [src/utils](/src/utils)
- [ ] Unit testing for [src/config.ts](/src/config.ts)
## Lighthouse Score
Click to view full report
<p align="center">
<a href="https://pagespeed.web.dev/analysis/https-yousef8-github-io-AstroPaperI18n-ar/d2cqwqovpv?form_factor=desktop">
<img width="710" alt="AstroPaper I18n Lighthouse Score" src="AstroPaper-lighthouse-score.svg">
<a>
</p>
## 📖 How To Use
### 1- Create translations file
Go to [src/i18n/locales](/src/i18n/locales) and create a file for your locale (e.g. es, ja, etc..), it should be named as `<locale_key>.ts` (e.g. es.ts, ja.ts, etc..).
Export a variable of `I18nStrings` type from `@i18n/types` with all the translations as key value pairs.
Take a look at the type at [/src/i18n/types.ts](/src/i18n/types.ts) and example file [/src/i18n/locales/ar.ts](/src/i18n/locales/ar.ts)
### 2- Define locale configuration
Go to [src/i18n/config.ts](/src/i18n/config.ts) and define a locale profile for your locale inside the configuration object `localeToProfile`.
Locale configuration is used to define the name of the locale, the translations, the language tag, the UI layout direction, and the Google font name.
Create a locale key which must be in all lowercase and complient with BCP-47 names. (eg. ar, en, es, ja, etc..), it's value is an object with the following keys:
- Assign a name to the `name` key in your locale profile, it will be used in the language picker.
- Assign translations file you created in step 1 to the `messages` key in your locale profile.
- Language tag must be in BCP47 name compliant, it's used to localize date and time in original AstroPaper theme, but it's **scope was expanded to localize all the numbers too**. (eg. en-US, ar-EG, es-ES, ja-JP, etc..)
- Google font name is used only in [OG images](https://magefan.com/blog/open-graph-meta-tags).
- set the `default` key to `true` if you want to set it, if no locale is set as default, the first locale in the object is used as the default.
- set the `direction` key to one of supported values `rtl | ltr | auto` corresponds to html `dir` tag directives values
**Note:** you may need to restart the dev server to see the changes.
**Note:** [satori](https://github.com/vercel/satori) does not support RTL languages, causing layout issues for RTL [OG images](https://magefan.com/blog/open-graph-meta-tags).
### 3- Add about page
The about page now has it's own [content collection](https://docs.astro.build/en/guides/content-collections/) because this theme supports i18n and you will likely need about page content in multiple locales.
Go to [src/content/about](/src/content/about) and create a file for your locale, it should be named as `about.<locale_key>.md` (e.g. about.en.md, about.es.md, etc..).
Same frontmatter keys as in original AstroPaper theme are supported `title` and `description` for the page title and description.
### 4- Add your content
Under [src/conent/blog](/src/content/blog) create a folder with your locale key (e.g. es, ja, etc..) as it's name and add your content in markdown format.
Any blog outside locale folder will not be considered by the site.
That's it, you're done 🎈🎉 🥳!
See [AstroPaper Docs](https://github.com/satnaing/astro-paper?tab=readme-ov-file#-documentation) for more info as this project builds upon it while to only support i18n, but everything else should be the same.
## 🛠️ Configuration
The same way to [use and configure AstroTheme](https://github.com/satnaing/astro-paper?tab=readme-ov-file#-project-structure), but with some changes.
### 🔧 Site Configurations
`SITE.title` and `SITE.desc` configuration has been replaced with `site.title` and `site.desc` translation, which is now used across whole site.
```diff
// src/config.ts
export const SITE: Site = {
//...
- title: "AstroPaper I18n",
- desc: "A fork of AstroPaper theme with support for I18n",
//...
};
```
```diff
// src/i18n/types.ts
export interface I18nStrings {
+ "site.title": string;
+ "site.desc": string;
// ... other translations
```
### 🌐 Locale Configurations
Locale configuration has been moved from `src/config.ts` to a dedicated file for better organization.
```diff
// src/config.ts
-export const LOCALE = {
- lang: "en", // html lang code. Set this empty and default will be "en"
- langTag: ["en-EN"], // BCP 47 Language Tags. Set this empty [] to use the environment default
-} as const;
export const LOGO_IMAGE = {
```
Instead Locale configuration is now handled in `src/i18n/config.ts`:
```ts
// src/i18n/config.ts
export const localeToProfile = {
// local key must be all lowercase and complaint with BCP-47
ar: {
name: "العربية", // Name presented in language picker
messages: ARLocale, // Locale translations
langTag: "ar-EG", // BCP 47 Language Tag (used for dates, numbers, and sitemap)
direction: "rtl", // UI layout direction
googleFontName: "Cairo", // For OG image generation, font must support 400 and 700 weights, replace spaces with '+'
},
en: {
name: "English",
messages: ENLocale,
langTag: "en-US",
direction: "ltr",
googleFontName: "IBM+Plex+Mono",
default: true,
},
} satisfies Record<string, LocaleProfile>;
```
## 🧞 Commands
Same [commands as in original theme](https://github.com/satnaing/astro-paper/tree/main?tab=readme-ov-file#-commands) with addition to
| Command | Action |
| :------------------- | :------------------------------------------------------------------------------------------ |
| `npm test` | Run all unit tests once and exit [learn more](https://vitest.dev/guide/cli.html#vitest-run) |
| `npm run test:watch` | Run unit tests in watch mode [learn more](https://vitest.dev/guide/cli.html#vitest-watch) |
| `npm run coverage` | Generate unit testing coverage report [learn more](https://vitest.dev/guide/coverage.html) |
## 🚧 Known Issues
- [ ] Styling in screen reader mode is currently broken and requires fixes.
- Contributions are welcome!
看看同类模板
对比同技术栈与用途的模板,找到更适合的视觉与内容结构。

astrowind
⭕️ AstroWind: A free template using Astro v7 and Tailwind CSS v4. Astro starter theme.
Astro · 博客

astro-paper
A minimal, accessible and SEO-friendly Astro blog theme.
Astro · 博客

fuwari
✨A static blog template built with Astro.
Astro · 博客

Firefly
Firefly 是一款基于 Astro 的静态博客主题,由 CuteLeaf 在 saicaca 的 Fuwari 模板基础上二次开发,主打清新美观的视觉风格。
Astro · 博客

astro-theme-cactus
A simple Astro theme. Use it to create your blog or website.
Astro · 作品集

astrofy
Astrofy is a free and open-source template for your Personal Portfolio Website built with Astro and TailwindCS…
Astro · 作品集
