-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #291 fix #628 fix #631 fix #902 fix #955 fix #1253 fix #1381 Co-authored-by: Hiroki Okada <hirokio@tutanota.com> Co-authored-by: Sadegh Barati <sadeghbaratiwork@gmail.com>
- Loading branch information
1 parent
471f00a
commit 8de2f44
Showing
65 changed files
with
784 additions
and
386 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,99 @@ | ||
# Internationalization | ||
|
||
To use the built-in i18n features, one needs to create a directory structure as follows: | ||
|
||
``` | ||
docs/ | ||
├─ es/ | ||
│ ├─ foo.md | ||
├─ fr/ | ||
│ ├─ foo.md | ||
├─ foo.md | ||
``` | ||
|
||
Then in `docs/.vitepress/config.ts`: | ||
|
||
```ts | ||
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... | ||
} | ||
} | ||
}) | ||
``` | ||
|
||
The following properties can be overridden for each locale (including root): | ||
|
||
```ts | ||
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 | ||
} | ||
``` | ||
|
||
Refer [`DefaultTheme.Config`](https://github.com/vuejs/vitepress/blob/main/types/default-theme.d.ts) interface for details on customizing the placeholder texts of the default theme. Don't override `themeConfig.algolia` or `themeConfig.carbonAds` at locale-level. Refer [Algolia docs](./theme-search#i18n) for using multilingual search. | ||
|
||
**Pro tip:** Config file can be stored at `docs/.vitepress/config/index.ts` too. It might help you organize stuff by creating a configuration file per locale and then merge and export them from `index.ts`. | ||
|
||
## Separate directory for each locale | ||
|
||
The following is a perfectly fine structure: | ||
|
||
``` | ||
docs/ | ||
├─ en/ | ||
│ ├─ foo.md | ||
├─ es/ | ||
│ ├─ foo.md | ||
├─ fr/ | ||
├─ foo.md | ||
``` | ||
|
||
However, VitePress won't redirect `/` to `/en/` by default. You'll need to configure your server for that. For example, on Netlify, you can add a `docs/public/_redirects` file like this: | ||
|
||
``` | ||
/* /es/:splat 302 Language=es | ||
/* /fr/:splat 302 Language=fr | ||
/* /en/:splat 302 | ||
``` | ||
|
||
**Pro tip:** If using the above approach, you can use `nf_lang` cookie to persist user's language choice. A very basic way to do this is register a watcher inside the [setup](./theme-introduction#using-a-custom-theme) function of custom theme: | ||
|
||
```ts | ||
// docs/.vitepress/theme/index.ts | ||
import DefaultTheme from 'vitepress/theme' | ||
|
||
export default { | ||
...DefaultTheme, | ||
setup() { | ||
const { lang } = useData() | ||
watchEffect(() => { | ||
if (inBrowser) { | ||
document.cookie = `nf_lang=${lang.value}; expires=Mon, 1 Jan 2024 00:00:00 UTC; path=/` | ||
} | ||
}) | ||
} | ||
} | ||
``` | ||
|
||
## RTL Support (Experimental) | ||
|
||
For RTL support, specify `dir: 'rtl'` in config and use some RTLCSS PostCSS plugin like <https://github.com/MohammadYounes/rtlcss>, <https://github.com/vkalinichev/postcss-rtl> or <https://github.com/elchininet/postcss-rtlcss>. You'll need to configure your PostCSS plugin to use `:where([dir="ltr"])` and `:where([dir="rtl"])` as prefixes to prevent CSS specificity issues. |
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 |
---|---|---|
@@ -1,3 +1,85 @@ | ||
# Search | ||
|
||
Documentation coming soon... | ||
VitePress supports searching your docs site using [Algolia DocSearch](https://docsearch.algolia.com/docs/what-is-docsearch). Refer their getting started guide. In your `.vitepress/config.ts` you'll need to provide at least the following to make it work: | ||
|
||
```ts | ||
import { defineConfig } from 'vitepress' | ||
|
||
export default defineConfig({ | ||
themeConfig: { | ||
algolia: { | ||
appId: '...', | ||
apiKey: '...', | ||
indexName: '...' | ||
} | ||
} | ||
}) | ||
``` | ||
|
||
If you are not eligible for DocSearch, you might wanna use some community plugins like <https://github.com/emersonbottero/vitepress-plugin-search> or explore some custom solutions on [this GitHub thread](https://github.com/vuejs/vitepress/issues/670). | ||
|
||
## i18n | ||
|
||
You can use a config like this to use multilingual search: | ||
|
||
```ts | ||
import { defineConfig } from 'vitepress' | ||
|
||
export default defineConfig({ | ||
// ... | ||
themeConfig: { | ||
// ... | ||
|
||
algolia: { | ||
appId: '...', | ||
apiKey: '...', | ||
indexName: '...', | ||
locales: { | ||
zh: { | ||
placeholder: '搜索文档', | ||
translations: { | ||
button: { | ||
buttonText: '搜索文档', | ||
buttonAriaLabel: '搜索文档' | ||
}, | ||
modal: { | ||
searchBox: { | ||
resetButtonTitle: '清除查询条件', | ||
resetButtonAriaLabel: '清除查询条件', | ||
cancelButtonText: '取消', | ||
cancelButtonAriaLabel: '取消' | ||
}, | ||
startScreen: { | ||
recentSearchesTitle: '搜索历史', | ||
noRecentSearchesText: '没有搜索历史', | ||
saveRecentSearchButtonTitle: '保存至搜索历史', | ||
removeRecentSearchButtonTitle: '从搜索历史中移除', | ||
favoriteSearchesTitle: '收藏', | ||
removeFavoriteSearchButtonTitle: '从收藏中移除' | ||
}, | ||
errorScreen: { | ||
titleText: '无法获取结果', | ||
helpText: '你可能需要检查你的网络连接' | ||
}, | ||
footer: { | ||
selectText: '选择', | ||
navigateText: '切换', | ||
closeText: '关闭', | ||
searchByText: '搜索提供者' | ||
}, | ||
noResultsScreen: { | ||
noResultsText: '无法找到相关结果', | ||
suggestedQueryText: '你可以尝试查询', | ||
reportMissingResultsText: '你认为该查询应该有结果?', | ||
reportMissingResultsLinkText: '点击反馈' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
``` | ||
|
||
[These options](https://github.com/vuejs/vitepress/blob/main/types/docsearch.d.ts) can be overridden. Refer official Algolia docs to learn more about them. |
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
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.