feat(docs): add translations for doc search (#15180)

This commit is contained in:
Zhongxiang Wang 2023-12-17 19:24:38 +08:00 committed by GitHub
parent e5a3a13760
commit abb217649f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 3 deletions

View File

@ -1,5 +1,47 @@
{
"search": "Search",
"empty": "No results",
"index": "en"
"algolia": {
"placeholder": "Search docs",
"translations": {
"button": {
"buttonText": "Search",
"buttonAriaLabel": "Search"
},
"modal": {
"searchBox": {
"resetButtonTitle": "Clear the query",
"resetButtonAriaLabel": "Clear the query",
"cancelButtonText": "Cancel",
"cancelButtonAriaLabel": "Cancel"
},
"startScreen": {
"recentSearchesTitle": "Recent",
"noRecentSearchesText": "No recent searches",
"saveRecentSearchButtonTitle": "Save this search",
"removeRecentSearchButtonTitle": "Remove this search from history",
"favoriteSearchesTitle": "Favorite",
"removeFavoriteSearchButtonTitle": "Remove this search from favorites"
},
"errorScreen": {
"titleText": "Unable to fetch results",
"helpText": "You might want to check your network connection."
},
"footer": {
"selectText": "to select",
"selectKeyAriaLabel": "Enter key",
"navigateText": "to navigate",
"navigateUpKeyAriaLabel": "Arrow up",
"navigateDownKeyAriaLabel": "Arrow down",
"closeText": "to close",
"closeKeyAriaLabel": "Escape key",
"searchByText": "Search by"
},
"noResultsScreen": {
"noResultsText": "No results for",
"suggestedQueryText": "Try searching for",
"reportMissingResultsText": "Believe this query should return results?",
"reportMissingResultsLinkText": "Let us know."
}
}
}
}
}

View File

@ -6,6 +6,7 @@ import docsearch from '@docsearch/js'
import { isClient } from '@vueuse/core'
import { useLang } from '../../composables/lang'
// import type { DefaultTheme } from '../config'
import searchLocale from '../../../i18n/component/search.json'
import type { DocSearchHit } from '@docsearch/react/dist/esm/types'
const props = defineProps<{
@ -58,11 +59,14 @@ function initialize(userOptions: any) {
// if the user has multiple locales, the search results should be filtered
// based on the language
const facetFilters = props.multilang ? [`language:${lang.value}`] : []
const algoliaLocale = searchLocale[lang.value].algolia
docsearch(
Object.assign({}, userOptions, {
container: '#docsearch',
indexName: 'element-plus',
placeholder: algoliaLocale.placeholder,
translations: algoliaLocale.translations,
searchParameters: Object.assign({}, userOptions.searchParameters, {
// pass a custom lang facetFilter to allow multiple language search
// https://github.com/algolia/docsearch-configs/pull/3942