国际化
要使用内置的 i18n 功能,需要创建一个目录结构,如下所示:
docs/
├─ es/
│ ├─ foo.md
├─ fr/
│ ├─ foo.md
├─ foo.md
然后,在 docs/.vitepress/config.js
中:
js
import { defineConfig } from 'vitepress'
export default defineConfig({
// shared properties and other top-level stuff...
locales: {
root: {
label: 'English',
lang: 'en'
},
fr: {
label: 'French',
lang: 'fr', // optional, will be added as `lang` attribute on `html` tag
link: '/fr/guide' // default /fr/ -- shows on navbar translations menu, can be external
// other locale specific properties...
themeConfig: {
nav: nav-french(), // shows on navbar menu of french translations
docFooter: {
prev: 'Previous Page',
next: 'Next Page'
}
}
}
}
})
可以为每个区域(包括根)设置覆盖以下属性:
js
interface LocaleSpecificConfig<ThemeConfig = any> {
lang?: string
dir?: string
title?: string
titleTemplate?: string | boolean
description?: string
head?: HeadConfig[] // will be merged with existing head entries, duplicate meta tags are automatically removed
themeConfig?: ThemeConfig // will be shallow merged, common stuff can be put in top-level themeConfig entry
}
有关自定义默认主题的占位符文本的详细信息,请参阅 DefaultTheme.Config
界面。不要在区域设置级别覆盖 themeConfig.algolia
或 themeConfig.carbonAds
。请参阅 Algolia 文档以使用多语言搜索。
专业提示:配置文件也可以存储在 docs/.vitepress/config/index.js
。它可以通过为每个区域设置创建一个配置文件,然后从 index.js
合并和导出它们来帮助您组织内容。
为每个区域设置单独的目录
下面是一个完美的结构:
docs/
├─ en/
│ ├─ foo.md
├─ es/
│ ├─ foo.md
├─ fr/
├─ foo.md
但是,默认情况下,VitePress 不会重定向 /
到 /en/
。