|
| 1 | +# Internationalization |
| 2 | + |
| 3 | +## Site Level i18n Config |
| 4 | + |
| 5 | +To leverage multi-language support in VuePress, you first need to use the following file structure: |
| 6 | + |
| 7 | +``` |
| 8 | +/ |
| 9 | +├─ README.md |
| 10 | +├─ foo.md |
| 11 | +├─ /nested/ |
| 12 | +│ └─ README.md |
| 13 | +└─ /zh/ |
| 14 | + ├─ README.md |
| 15 | + ├─ foo.md |
| 16 | + └─ /zh/nested/ |
| 17 | + └─ README.md |
| 18 | +``` |
| 19 | + |
| 20 | +Then, specify the `locales` option in `.vuepress/config.js`: |
| 21 | + |
| 22 | +``` js |
| 23 | +module.exports = { |
| 24 | + locales: { |
| 25 | + // The key is the path for the locale to be nested under. |
| 26 | + // As a special case, the default locale can use '/' as its path. |
| 27 | + '/': { |
| 28 | + lang: 'en-US', // this will be set as the lang attribute on <html> |
| 29 | + title: 'VuePress', |
| 30 | + description: 'Vue-powered Static Site Generator' |
| 31 | + }, |
| 32 | + '/zh/': { |
| 33 | + lang: 'zh-CN', |
| 34 | + title: 'VuePress', |
| 35 | + description: 'Vue 驱动的静态网站生成器' |
| 36 | + } |
| 37 | + } |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +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. |
| 42 | + |
| 43 | +## Default Theme i18n Config |
| 44 | + |
| 45 | +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: |
| 46 | + |
| 47 | +``` js |
| 48 | +module.exports = { |
| 49 | + locales: { /* ... */ }, |
| 50 | + themeConfig: { |
| 51 | + locales: { |
| 52 | + '/': { |
| 53 | + // text for the language dropdown |
| 54 | + selectText: 'Languages', |
| 55 | + // label for this locale in the language dropdown |
| 56 | + label: 'English', |
| 57 | + // text for the edit-on-github link |
| 58 | + editLinkText: 'Edit this page on GitHub', |
| 59 | + nav: [ |
| 60 | + { text: 'Nested', link: '/nested/' } |
| 61 | + ], |
| 62 | + sidebar: { |
| 63 | + '/': [/* ... */], |
| 64 | + '/nested/': [/* ... */] |
| 65 | + } |
| 66 | + }, |
| 67 | + '/zh/': { |
| 68 | + selectText: '选择语言', |
| 69 | + label: '简体中文', |
| 70 | + editLinkText: '在 GitHub 上编辑此页', |
| 71 | + nav: [ |
| 72 | + { text: '嵌套', link: '/zh/nested/' } |
| 73 | + ], |
| 74 | + sidebar: { |
| 75 | + '/zh/': [/* ... */], |
| 76 | + '/zh/nested/': [/* ... */] |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | +} |
| 82 | +``` |
0 commit comments