Skip to content

feat: 全局搜索框支持中文提示 #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions docs/.vuepress/theme/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { ThemeLocaleData } from 'vuepress-theme-hope'
import type { SearchProLocaleData } from 'vuepress-plugin-search-pro'
import { NotFoundMsgList } from './constant'

/**
* 支持中文
* 参考:https://theme-hope.vuejs.press/zh/config/i18n.html
*/
const localCN: ThemeLocaleData = {
const themeLocalCN: ThemeLocaleData = {
lang: 'zh-CN',
navbarLocales: {
langName: '简体中文',
Expand Down Expand Up @@ -76,5 +77,26 @@ const localCN: ThemeLocaleData = {
* 自定义语言,支持文案
*/
export const i18n = {
'/': localCN,
'/': themeLocalCN,
}

/**
* 搜索框支持中文
* 参考:https://plugin-search-pro.vuejs.press/zh/config.html#locales
*/
export const searchProCNLocals: SearchProLocaleData = {
placeholder: '请输入需要搜索的关键字',
search: '搜索文档',
searching: '搜索中',
cancel: '取消',
select: '选择',
navigate: '切换',
exit: '关闭',
loading: '正在努力搜索中...',
queryHistory: '搜素文字历史',
resultHistory: '搜索结果',
emptyHistory: '没有搜索历史',
emptyResult: '无法找到相关结果',
defaultTitle: '搜索文档',
autocomplete: '自动补齐',
}
19 changes: 5 additions & 14 deletions docs/.vuepress/theme/theme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { hopeTheme } from 'vuepress-theme-hope'
import { AUTHOR_INFO, COPYRIGHT, FOOTER_HTML_INFO } from './constant'
import { i18n } from './i18n'
import { i18n, searchProCNLocals } from './i18n'
import navbar from './navbar'
import sidebar from './sidebar'

Expand Down Expand Up @@ -159,19 +159,10 @@ export const themeConfig = {
},
},
searchPro: {
// 索引全部内容
indexContent: true,
// 为分类和标签添加索引
customFields: [
{
getter: (page: any) => page.frontmatter.category,
formatter: '分类:$content',
},
{
getter: page => page.frontmatter.tag,
formatter: '标签:$content',
},
],
// 参考:https://plugin-search-pro.vuejs.press/zh/config.html#locales
locales: {
'/': searchProCNLocals,
},
},
// 代码高亮:https://theme-hope.vuejs.press/zh/guide/feature/code-block.html
shiki: {
Expand Down
Loading