-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adjust i18n config + documentation
- Loading branch information
Showing
13 changed files
with
260 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Internationalization | ||
|
||
## Site Level i18n Config | ||
|
||
To leverage multi-language support in VuePress, you first need to use the following file structure: | ||
|
||
``` | ||
/ | ||
├─ README.md | ||
├─ foo.md | ||
├─ /nested/ | ||
│ └─ README.md | ||
└─ /zh/ | ||
├─ README.md | ||
├─ foo.md | ||
└─ /zh/nested/ | ||
└─ README.md | ||
``` | ||
|
||
Then, specify the `locales` option in `.vuepress/config.js`: | ||
|
||
``` js | ||
module.exports = { | ||
locales: { | ||
// The key is the path for the locale to be nested under. | ||
// As a special case, the default locale can use '/' as its path. | ||
'/': { | ||
lang: 'en-US', // this will be set as the lang attribute on <html> | ||
title: 'VuePress', | ||
description: 'Vue-powered Static Site Generator' | ||
}, | ||
'/zh/': { | ||
lang: 'zh-CN', | ||
title: 'VuePress', | ||
description: 'Vue 驱动的静态网站生成器' | ||
} | ||
} | ||
} | ||
``` | ||
|
||
If a locale does not have `title` or `description` VuePress will fallback to the root level values. You can omit the root level `title` and `description` as long as they are provided in each locale. | ||
|
||
## Default Theme i18n Config | ||
|
||
The default theme also has built-in i18n support via `themeConfig.locales`, using the same `{ path: config }` format. Each locale can have its own [nav](../default-theme-config/#navbar-links) and [sidebar](../default-theme-config/#sidebar) config, in addition to a few other text values used across the site: | ||
|
||
``` js | ||
module.exports = { | ||
locales: { /* ... */ }, | ||
themeConfig: { | ||
locales: { | ||
'/': { | ||
// text for the language dropdown | ||
selectText: 'Languages', | ||
// label for this locale in the language dropdown | ||
label: 'English', | ||
// text for the edit-on-github link | ||
editLinkText: 'Edit this page on GitHub', | ||
nav: [ | ||
{ text: 'Nested', link: '/nested/' } | ||
], | ||
sidebar: { | ||
'/': [/* ... */], | ||
'/nested/': [/* ... */] | ||
} | ||
}, | ||
'/zh/': { | ||
selectText: '选择语言', | ||
label: '简体中文', | ||
editLinkText: '在 GitHub 上编辑此页', | ||
nav: [ | ||
{ text: '嵌套', link: '/zh/nested/' } | ||
], | ||
sidebar: { | ||
'/zh/': [/* ... */], | ||
'/zh/nested/': [/* ... */] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# 多语言支持 | ||
|
||
## 站点多语言配置 | ||
|
||
要启用 VuePress 的多语言支持,首先需要使用如下的文件结构: | ||
|
||
``` | ||
/ | ||
├─ README.md | ||
├─ foo.md | ||
├─ /nested/ | ||
│ └─ README.md | ||
└─ /zh/ | ||
├─ README.md | ||
├─ foo.md | ||
└─ /zh/nested/ | ||
└─ README.md | ||
``` | ||
|
||
然后,在 `.vuepress/config.js` 中提供 `locales` 选项: | ||
|
||
``` js | ||
module.exports = { | ||
locales: { | ||
// 键名是该语言所属的子路径 | ||
// 作为特例,默认语言可以使用 '/' 作为其路径。 | ||
'/': { | ||
lang: 'en-US', // 将会被设置为 <html> 的 lang 属性 | ||
title: 'VuePress', | ||
description: 'Vue-powered Static Site Generator' | ||
}, | ||
'/zh/': { | ||
lang: 'zh-CN', | ||
title: 'VuePress', | ||
description: 'Vue 驱动的静态网站生成器' | ||
} | ||
} | ||
} | ||
``` | ||
|
||
如果一个语言没有声明 `title` 或者 `description`,VuePress 将会尝试使用配置顶层的对应值。如果每个语言都声明了 `title` 和 `description`,则顶层的这两个值可以被省略。 | ||
|
||
## 默认主题多语言配置 | ||
|
||
默认主题也内置了多语言支持,可以通过 `themeConfig.locales` 来配置。该选项接受同样的 `{ path: config }` 格式的值。每个语言除了可以配置一些站点中用到的文字之外,还可以拥有自己的 [导航栏](../default-theme-config/#导航栏) 和 [侧边栏](../default-theme-config/#侧边栏) 配置: | ||
|
||
``` js | ||
module.exports = { | ||
locales: { /* ... */ }, | ||
themeConfig: { | ||
locales: { | ||
'/': { | ||
selectText: 'Languages', | ||
label: 'English', | ||
editLinkText: 'Edit this page on GitHub', | ||
nav: [ | ||
{ text: 'Nested', link: '/nested/' } | ||
], | ||
sidebar: { | ||
'/': [/* ... */], | ||
'/nested/': [/* ... */] | ||
} | ||
}, | ||
'/zh/': { | ||
// 多语言下拉菜单的标题 | ||
selectText: '选择语言', | ||
// 该语言在下拉菜单中的标签 | ||
label: '简体中文', | ||
// 编辑链接文字 | ||
editLinkText: '在 GitHub 上编辑此页', | ||
nav: [ | ||
{ text: '嵌套', link: '/zh/nested/' } | ||
], | ||
sidebar: { | ||
'/zh/': [/* ... */], | ||
'/zh/nested/': [/* ... */] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.