快捷菜单
常用功能一站直达
更多功能请点顶栏「快捷菜单」
starlight主题默认是英文的,如何配置成默认中文呢?
把 Starlight 设为默认中文,核心是改 astro.config.mjs 的 defaultLocale 和 locales,并调整文件目录。
astro.config.mjs,设置:defaultLocale: 'root'locales 里用 root 对应中文 1// astro.config.mjs
2import { defineConfig } from 'astro/config';
3import starlight from '@astrojs/starlight';
4
5export default defineConfig({
6 integrations: [
7 starlight({
8 title: '我的中文文档',
9 // 设为默认中文
10 defaultLocale: 'root',
11 locales: {
12 // 根目录存放中文内容 src/content/docs/
13 root: {
14 label: '简体中文',
15 lang: 'zh-CN',
16 },
17 },
18 }),
19 ],
20});src/content/docs/en/ 下的所有文件src/content/docs/(根目录)en 文件夹 1// astro.config.mjs
2import { defineConfig } from 'astro/config';
3import starlight from '@astrojs/starlight';
4
5export default defineConfig({
6 integrations: [
7 starlight({
8 title: '我的文档',
9 // 默认语言改为中文
10 defaultLocale: 'zh-cn',
11 locales: {
12 // 中文:src/content/docs/zh-cn/
13 'zh-cn': {
14 label: '简体中文',
15 lang: 'zh-CN',
16 },
17 // 英文:src/content/docs/en/
18 en: {
19 label: 'English',
20 },
21 },
22 }),
23 ],
24});src/content/docs/zh-cn/zh-cn/en//zh-cn/(默认中文)astro dev/en/ 或 /zh-cn//zh-cn/要不要我给你一份可直接复制的完整 astro.config.mjs 配置(单语/双语二选一)?
编辑astro.config.mjs
核心配置:
1 // 设为默认中文
2 defaultLocale: 'root',
3 locales: {
4 // 根目录存放中文内容 src/content/docs/
5 root: {
6 label: '简体中文',
7 lang: 'zh-CN',
8 },完整配置:
1
2// @ts-check
3import { defineConfig } from 'astro/config';
4import starlight from '@astrojs/starlight';
5
6// https://astro.build/config
7export default defineConfig({
8 integrations: [
9 starlight({
10 title: 'My Docs',
11
12 // 设为默认中文
13 defaultLocale: 'root',
14 locales: {
15 // 根目录存放中文内容 src/content/docs/
16 root: {
17 label: '简体中文',
18 lang: 'zh-CN',
19 },
20 },
21
22
23 social: [{ icon: 'github', label: 'GitHub', href: 'https://github.com/withastro/starlight' }],
24 sidebar: [
25 {
26 label: '指南',
27 items: [
28 { label: '示例指南', link: '/guides/example/' },
29 ],
30 },
31 {
32 label: '参考',
33 items: [
34 { label: '示例参考', link: '/reference/example/' },
35 ],
36 },
37 ],
38 }),
39 ],
40});日历 · 精选 · 友链 · 更多
如果内容对你有帮助,欢迎请我喝杯咖啡 ☕



One的公众号
爱折腾博客的小白