From b951f3b7fe33bbbe6fdd4366eb722b0d29c4cc72 Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Mon, 20 Jan 2025 20:45:49 +0800 Subject: [PATCH] feat: improve built-in locales --- plugins/plugin-search/src/node/locales/de.ts | 18 +++++ plugins/plugin-search/src/node/locales/en.ts | 17 +++++ plugins/plugin-search/src/node/locales/fr.ts | 18 +++++ .../plugin-search/src/node/locales/index.ts | 24 +++++++ plugins/plugin-search/src/node/locales/ja.ts | 18 +++++ plugins/plugin-search/src/node/locales/ru.ts | 18 +++++ .../plugin-search/src/node/locales/zh-tw.ts | 18 +++++ plugins/plugin-search/src/node/locales/zh.ts | 17 +++++ .../plugin-search/src/node/searchPlugin.ts | 10 ++- theme/src/node/config/index.ts | 1 - theme/src/node/config/resolveLocaleOptions.ts | 4 +- theme/src/node/config/resolveProvideData.ts | 14 ++-- theme/src/node/config/resolveSearchOptions.ts | 33 --------- theme/src/node/locales/de.ts | 60 ---------------- theme/src/node/locales/en.ts | 17 ----- theme/src/node/locales/fr.ts | 60 ---------------- theme/src/node/locales/index.ts | 72 +++++++------------ theme/src/node/locales/ja.ts | 60 ---------------- theme/src/node/locales/ru.ts | 60 ---------------- theme/src/node/locales/zh-tw.ts | 60 ---------------- theme/src/node/locales/zh.ts | 60 ---------------- theme/src/node/plugins/getPlugins.ts | 5 +- 22 files changed, 192 insertions(+), 472 deletions(-) create mode 100644 plugins/plugin-search/src/node/locales/de.ts create mode 100644 plugins/plugin-search/src/node/locales/en.ts create mode 100644 plugins/plugin-search/src/node/locales/fr.ts create mode 100644 plugins/plugin-search/src/node/locales/index.ts create mode 100644 plugins/plugin-search/src/node/locales/ja.ts create mode 100644 plugins/plugin-search/src/node/locales/ru.ts create mode 100644 plugins/plugin-search/src/node/locales/zh-tw.ts create mode 100644 plugins/plugin-search/src/node/locales/zh.ts delete mode 100644 theme/src/node/config/resolveSearchOptions.ts diff --git a/plugins/plugin-search/src/node/locales/de.ts b/plugins/plugin-search/src/node/locales/de.ts new file mode 100644 index 000000000..26a5c7188 --- /dev/null +++ b/plugins/plugin-search/src/node/locales/de.ts @@ -0,0 +1,18 @@ +/** 德语 */ +import type { SearchLocaleOptions } from '../../shared/index.js' + +export const deSearchLocale: Partial = { + placeholder: 'Dokumente durchsuchen', + resetButtonTitle: 'Suche zurücksetzen', + backButtonTitle: 'Schließen', + noResultsText: 'Keine Suchergebnisse:', + footer: { + selectText: 'Auswählen', + selectKeyAriaLabel: 'Eingabe', + navigateText: 'Wechseln', + navigateUpKeyAriaLabel: 'Nach oben', + navigateDownKeyAriaLabel: 'Nach unten', + closeText: 'Schließen', + closeKeyAriaLabel: 'Beenden', + }, +} diff --git a/plugins/plugin-search/src/node/locales/en.ts b/plugins/plugin-search/src/node/locales/en.ts new file mode 100644 index 000000000..5db1c546f --- /dev/null +++ b/plugins/plugin-search/src/node/locales/en.ts @@ -0,0 +1,17 @@ +import type { SearchLocaleOptions } from '../../shared/index.js' + +export const enSearchLocale: Partial = { + placeholder: 'Search', + resetButtonTitle: 'Reset search', + backButtonTitle: 'Close search', + noResultsText: 'No results for', + footer: { + selectText: 'to select', + selectKeyAriaLabel: 'enter', + navigateText: 'to navigate', + navigateUpKeyAriaLabel: 'up arrow', + navigateDownKeyAriaLabel: 'down arrow', + closeText: 'to close', + closeKeyAriaLabel: 'escape', + }, +} diff --git a/plugins/plugin-search/src/node/locales/fr.ts b/plugins/plugin-search/src/node/locales/fr.ts new file mode 100644 index 000000000..2a9357433 --- /dev/null +++ b/plugins/plugin-search/src/node/locales/fr.ts @@ -0,0 +1,18 @@ +/** 法语 */ +import type { SearchLocaleOptions } from '../../shared/index.js' + +export const frSearchLocale: Partial = { + placeholder: 'Rechercher dans la documentation', + resetButtonTitle: 'Réinitialiser la recherche', + backButtonTitle: 'Fermer', + noResultsText: 'Aucun résultat trouvé :', + footer: { + selectText: 'sélectionner', + selectKeyAriaLabel: 'Entrée', + navigateText: 'naviguer', + navigateUpKeyAriaLabel: 'haut', + navigateDownKeyAriaLabel: 'bas', + closeText: 'fermer', + closeKeyAriaLabel: 'sortie', + }, +} diff --git a/plugins/plugin-search/src/node/locales/index.ts b/plugins/plugin-search/src/node/locales/index.ts new file mode 100644 index 000000000..e7f2353dc --- /dev/null +++ b/plugins/plugin-search/src/node/locales/index.ts @@ -0,0 +1,24 @@ +/** + * 多语言预设 + * 除 /zh/ 、 /en/ 外,其它语言预设通过 AI 生成,不保证准确 + * 如有错误,欢迎提 issue + */ +import type { DefaultLocaleInfo } from '@vuepress/helper' +import type { SearchLocaleOptions } from '../../shared/index.js' +import { deSearchLocale } from './de.js' +import { enSearchLocale } from './en.js' +import { frSearchLocale } from './fr.js' +import { jaSearchLocale } from './ja.js' +import { ruSearchLocale } from './ru.js' +import { zhTwSearchLocale } from './zh-tw.js' +import { zhSearchLocale } from './zh.js' + +export const SEARCH_LOCALES: DefaultLocaleInfo> = [ + [['en', 'en-US'], enSearchLocale], + [['zh', 'zh-CN', 'zh-Hans', 'zh-Hant'], zhSearchLocale], + [['zh-TW'], zhTwSearchLocale], + [['de', 'de-DE'], deSearchLocale], + [['fr', 'fr-FR'], frSearchLocale], + [['ru', 'ru-RU'], ruSearchLocale], + [['ja', 'ja-JP'], jaSearchLocale], +] diff --git a/plugins/plugin-search/src/node/locales/ja.ts b/plugins/plugin-search/src/node/locales/ja.ts new file mode 100644 index 000000000..946c0f2ac --- /dev/null +++ b/plugins/plugin-search/src/node/locales/ja.ts @@ -0,0 +1,18 @@ +/** 日语 */ +import type { SearchLocaleOptions } from '../../shared/index.js' + +export const jaSearchLocale: Partial = { + placeholder: 'ドキュメントを検索', + resetButtonTitle: '検索をリセット', + backButtonTitle: '閉じる', + noResultsText: '検索結果がありません:', + footer: { + selectText: '選択', + selectKeyAriaLabel: '入力', + navigateText: '切り替え', + navigateUpKeyAriaLabel: '上へ', + navigateDownKeyAriaLabel: '下へ', + closeText: '閉じる', + closeKeyAriaLabel: '終了', + }, +} diff --git a/plugins/plugin-search/src/node/locales/ru.ts b/plugins/plugin-search/src/node/locales/ru.ts new file mode 100644 index 000000000..5c06700c3 --- /dev/null +++ b/plugins/plugin-search/src/node/locales/ru.ts @@ -0,0 +1,18 @@ +/** 俄语 */ +import type { SearchLocaleOptions } from '../../shared/index.js' + +export const ruSearchLocale: Partial = { + placeholder: 'Поиск по документации', + resetButtonTitle: 'Сбросить поиск', + backButtonTitle: 'Закрыть', + noResultsText: 'Нет результатов поиска:', + footer: { + selectText: 'Выбрать', + selectKeyAriaLabel: 'Ввод', + navigateText: 'Переключить', + navigateUpKeyAriaLabel: 'Вверх', + navigateDownKeyAriaLabel: 'Вниз', + closeText: 'Закрыть', + closeKeyAriaLabel: 'Выход', + }, +} diff --git a/plugins/plugin-search/src/node/locales/zh-tw.ts b/plugins/plugin-search/src/node/locales/zh-tw.ts new file mode 100644 index 000000000..bce9bfd56 --- /dev/null +++ b/plugins/plugin-search/src/node/locales/zh-tw.ts @@ -0,0 +1,18 @@ +/** 繁体中文 */ +import type { SearchLocaleOptions } from '../../shared/index.js' + +export const zhTwSearchLocale: Partial = { + placeholder: '搜索文檔', + resetButtonTitle: '重置搜索', + backButtonTitle: '關閉', + noResultsText: '無搜索結果:', + footer: { + selectText: '選擇', + selectKeyAriaLabel: '輸入', + navigateText: '切換', + navigateUpKeyAriaLabel: '向上', + navigateDownKeyAriaLabel: '向下', + closeText: '關閉', + closeKeyAriaLabel: '退出', + }, +} diff --git a/plugins/plugin-search/src/node/locales/zh.ts b/plugins/plugin-search/src/node/locales/zh.ts new file mode 100644 index 000000000..4e3fb81c6 --- /dev/null +++ b/plugins/plugin-search/src/node/locales/zh.ts @@ -0,0 +1,17 @@ +import type { SearchLocaleOptions } from '../../shared/index.js' + +export const zhSearchLocale: Partial = { + placeholder: '搜索文档', + resetButtonTitle: '重置搜索', + backButtonTitle: '关闭', + noResultsText: '无搜索结果:', + footer: { + selectText: '选择', + selectKeyAriaLabel: '输入', + navigateText: '切换', + navigateUpKeyAriaLabel: '向上', + navigateDownKeyAriaLabel: '向下', + closeText: '关闭', + closeKeyAriaLabel: '退出', + }, +} diff --git a/plugins/plugin-search/src/node/searchPlugin.ts b/plugins/plugin-search/src/node/searchPlugin.ts index 103f00534..14b9ce99d 100644 --- a/plugins/plugin-search/src/node/searchPlugin.ts +++ b/plugins/plugin-search/src/node/searchPlugin.ts @@ -1,8 +1,9 @@ import type { Plugin } from 'vuepress/core' import type { SearchPluginOptions } from '../shared/index.js' -import { addViteOptimizeDepsInclude } from '@vuepress/helper' +import { addViteOptimizeDepsInclude, getFullLocaleConfig } from '@vuepress/helper' import chokidar from 'chokidar' import { getDirname, path } from 'vuepress/utils' +import { SEARCH_LOCALES } from './locales/index.js' import { onSearchIndexRemoved, onSearchIndexUpdated, prepareSearchIndex } from './prepareSearchIndex.js' const __dirname = getDirname(import.meta.url) @@ -18,7 +19,12 @@ export function searchPlugin({ clientConfigFile: path.resolve(__dirname, '../client/config.js'), define: { - __SEARCH_LOCALES__: locales, + __SEARCH_LOCALES__: getFullLocaleConfig({ + app, + name: '@vuepress-plume/plugin-search', + default: SEARCH_LOCALES, + config: locales, + }), __SEARCH_OPTIONS__: searchOptions, }, diff --git a/theme/src/node/config/index.ts b/theme/src/node/config/index.ts index 9a2075ced..8ee99c5f7 100644 --- a/theme/src/node/config/index.ts +++ b/theme/src/node/config/index.ts @@ -4,7 +4,6 @@ export * from './resolveLocaleOptions.js' export * from './resolveNotesOptions.js' export * from './resolveProvideData.js' -export * from './resolveSearchOptions.js' export * from './resolveThemeData.js' export * from './resolveThemeOption.js' diff --git a/theme/src/node/config/resolveLocaleOptions.ts b/theme/src/node/config/resolveLocaleOptions.ts index fc14cf87a..d63620946 100644 --- a/theme/src/node/config/resolveLocaleOptions.ts +++ b/theme/src/node/config/resolveLocaleOptions.ts @@ -1,7 +1,7 @@ import type { App } from 'vuepress' import type { PlumeThemeData, PlumeThemeLocaleOptions } from '../../shared/index.js' import { hasOwn, uniq } from '@pengzhanbo/utils' -import { entries, fromEntries, getLocaleConfig, isPlainObject } from '@vuepress/helper' +import { entries, fromEntries, getFullLocaleConfig, isPlainObject } from '@vuepress/helper' import { LOCALE_OPTIONS } from '../locales/index.js' import { THEME_NAME } from '../utils/index.js' @@ -43,7 +43,7 @@ const FALLBACK_OPTIONS: PlumeThemeData = { export function resolveLocaleOptions(app: App, { locales, ...options }: PlumeThemeLocaleOptions): PlumeThemeLocaleOptions { const resolvedOptions: PlumeThemeLocaleOptions = { ...mergeLocaleOptions(FALLBACK_OPTIONS, options), - locales: getLocaleConfig({ + locales: getFullLocaleConfig({ app, name: THEME_NAME, default: LOCALE_OPTIONS, diff --git a/theme/src/node/config/resolveProvideData.ts b/theme/src/node/config/resolveProvideData.ts index f30f016fe..23c85ad0e 100644 --- a/theme/src/node/config/resolveProvideData.ts +++ b/theme/src/node/config/resolveProvideData.ts @@ -1,24 +1,22 @@ import type { App } from 'vuepress' import type { PlumeThemePluginOptions } from '../../shared/index.js' -import { entries, fromEntries, getLocalePaths, inferRootLocalePath, isPlainObject } from '@vuepress/helper' +import { getFullLocaleConfig, isPlainObject } from '@vuepress/helper' import { PRESET_LOCALES } from '../locales/index.js' export function resolveProvideData( app: App, plugins: PlumeThemePluginOptions, ): Record { - const root = inferRootLocalePath(app) - const locales = [...getLocalePaths(app), root] return { // 注入水印配置 __PLUME_WM_FP__: isPlainObject(plugins.watermark) ? plugins.watermark.fullPage !== false : true, // 注入多语言配置 - __PLUME_PRESET_LOCALE__: fromEntries( - entries(PRESET_LOCALES) - .filter(([locale]) => locales.includes(locale)) - .map(([locale, value]) => [locale === root ? '/' : locale, value]), - ), + __PLUME_PRESET_LOCALE__: getFullLocaleConfig({ + app, + name: 'vuepress-theme-plume/preset-locales', + default: PRESET_LOCALES, + }), } } diff --git a/theme/src/node/config/resolveSearchOptions.ts b/theme/src/node/config/resolveSearchOptions.ts deleted file mode 100644 index d7581c099..000000000 --- a/theme/src/node/config/resolveSearchOptions.ts +++ /dev/null @@ -1,33 +0,0 @@ -import type { SearchPluginOptions } from '@vuepress-plume/plugin-search' -import type { DocSearchPluginOptions } from '@vuepress/plugin-docsearch' -import type { App } from 'vuepress' -import { getLocaleConfig } from '@vuepress/helper' -import { DOCSEARCH_LOCALES, SEARCH_LOCALES } from '../locales/index.js' - -export function resolveSearchOptions( - app: App, - { locales, ...options }: SearchPluginOptions = {}, -): SearchPluginOptions { - return { - ...options, - locales: getLocaleConfig({ - app, - default: SEARCH_LOCALES, - config: locales, - }), - } -} - -export function resolveDocsearchOptions( - app: App, - { locales, ...options }: DocSearchPluginOptions = {}, -): DocSearchPluginOptions { - return { - ...options, - locales: getLocaleConfig({ - app, - default: DOCSEARCH_LOCALES, - config: locales, - }), - } -} diff --git a/theme/src/node/locales/de.ts b/theme/src/node/locales/de.ts index 1feead358..04408ec72 100644 --- a/theme/src/node/locales/de.ts +++ b/theme/src/node/locales/de.ts @@ -1,6 +1,4 @@ /** 德语 */ -import type { SearchLocaleOptions } from '@vuepress-plume/plugin-search' -import type { DocSearchLocaleOptions } from '@vuepress/plugin-docsearch' import type { PlumeThemeLocaleData, PresetLocale } from '../../shared/index.js' export const deLocale: PlumeThemeLocaleData = { @@ -66,61 +64,3 @@ export const dePresetLocale: PresetLocale = { 'CC-BY-ND-4.0': 'Namensnennung-Keine Bearbeitung 4.0 International', 'CC-BY-SA-4.0': 'Namensnennung-Weitergabe unter gleichen Bedingungen 4.0 International', } - -export const deDocsearchLocale: DocSearchLocaleOptions = { - placeholder: 'Dokumente durchsuchen', - translations: { - button: { - buttonText: 'Dokumente durchsuchen', - buttonAriaLabel: 'Dokumente durchsuchen', - }, - modal: { - searchBox: { - resetButtonTitle: 'Suchkriterien löschen', - resetButtonAriaLabel: 'Suchkriterien löschen', - cancelButtonText: 'Abbrechen', - cancelButtonAriaLabel: 'Abbrechen', - }, - startScreen: { - recentSearchesTitle: 'Letzte Suchen', - noRecentSearchesText: 'Keine letzten Suchen', - saveRecentSearchButtonTitle: 'Zu letzten Suchen hinzufügen', - removeRecentSearchButtonTitle: 'Aus letzten Suchen entfernen', - favoriteSearchesTitle: 'Favoriten', - removeFavoriteSearchButtonTitle: 'Aus Favoriten entfernen', - }, - errorScreen: { - titleText: 'Ergebnisse konnten nicht abgerufen werden', - helpText: 'Möglicherweise müssen Sie Ihre Internetverbindung überprüfen.', - }, - footer: { - selectText: 'Auswählen', - navigateText: 'Wechseln', - closeText: 'Schließen', - searchByText: 'Bereitgestellt von', - }, - noResultsScreen: { - noResultsText: 'Keine relevanten Ergebnisse gefunden', - suggestedQueryText: 'Sie können versuchen, nach', - reportMissingResultsText: 'Sie glauben, dass diese Suche Ergebnisse liefern sollte?', - reportMissingResultsLinkText: 'Klicken Sie hier, um Feedback zu geben', - }, - }, - }, -} - -export const deSearchLocale: Partial = { - placeholder: 'Dokumente durchsuchen', - resetButtonTitle: 'Suche zurücksetzen', - backButtonTitle: 'Schließen', - noResultsText: 'Keine Suchergebnisse:', - footer: { - selectText: 'Auswählen', - selectKeyAriaLabel: 'Eingabe', - navigateText: 'Wechseln', - navigateUpKeyAriaLabel: 'Nach oben', - navigateDownKeyAriaLabel: 'Nach unten', - closeText: 'Schließen', - closeKeyAriaLabel: 'Beenden', - }, -} diff --git a/theme/src/node/locales/en.ts b/theme/src/node/locales/en.ts index 664d772a4..be27f988b 100644 --- a/theme/src/node/locales/en.ts +++ b/theme/src/node/locales/en.ts @@ -1,4 +1,3 @@ -import type { SearchLocaleOptions } from '@vuepress-plume/plugin-search' import type { PlumeThemeLocaleData, PresetLocale } from '../../shared/index.js' export const enLocale: PlumeThemeLocaleData = { @@ -51,19 +50,3 @@ export const enPresetLocale: PresetLocale = { 'CC-BY-ND-4.0': 'Attribution-NoDerivatives 4.0 International', 'CC-BY-SA-4.0': 'Attribution-ShareAlike 4.0 International', } - -export const enSearchLocale: Partial = { - placeholder: 'Search', - resetButtonTitle: 'Reset search', - backButtonTitle: 'Close search', - noResultsText: 'No results for', - footer: { - selectText: 'to select', - selectKeyAriaLabel: 'enter', - navigateText: 'to navigate', - navigateUpKeyAriaLabel: 'up arrow', - navigateDownKeyAriaLabel: 'down arrow', - closeText: 'to close', - closeKeyAriaLabel: 'escape', - }, -} diff --git a/theme/src/node/locales/fr.ts b/theme/src/node/locales/fr.ts index f06c388d9..534ff0cbf 100644 --- a/theme/src/node/locales/fr.ts +++ b/theme/src/node/locales/fr.ts @@ -1,6 +1,4 @@ /** 法语 */ -import type { SearchLocaleOptions } from '@vuepress-plume/plugin-search' -import type { DocSearchLocaleOptions } from '@vuepress/plugin-docsearch' import type { PlumeThemeLocaleData, PresetLocale } from '../../shared/index.js' export const frLocale: PlumeThemeLocaleData = { @@ -65,61 +63,3 @@ export const frPresetLocale: PresetLocale = { 'CC-BY-ND-4.0': 'Attribution-Pas de Modification 4.0 International', 'CC-BY-SA-4.0': 'Attribution-Partage dans les Mêmes Conditions 4.0 International', } - -export const frDocsearchLocale: DocSearchLocaleOptions = { - placeholder: 'Rechercher dans la documentation', - translations: { - button: { - buttonText: 'Rechercher dans la documentation', - buttonAriaLabel: 'Rechercher dans la documentation', - }, - modal: { - searchBox: { - resetButtonTitle: 'Effacer les critères de recherche', - resetButtonAriaLabel: 'Effacer les critères de recherche', - cancelButtonText: 'Annuler', - cancelButtonAriaLabel: 'Annuler', - }, - startScreen: { - recentSearchesTitle: 'Recherches récentes', - noRecentSearchesText: 'Aucune recherche récente', - saveRecentSearchButtonTitle: 'Enregistrer dans les recherches récentes', - removeRecentSearchButtonTitle: 'Supprimer des recherches récentes', - favoriteSearchesTitle: 'Favoris', - removeFavoriteSearchButtonTitle: 'Supprimer des favoris', - }, - errorScreen: { - titleText: 'Impossible d\'obtenir les résultats', - helpText: 'Vous devriez vérifier votre connexion Internet', - }, - footer: { - selectText: 'sélectionner', - navigateText: 'naviguer', - closeText: 'fermer', - searchByText: 'Recherche par', - }, - noResultsScreen: { - noResultsText: 'Aucun résultat trouvé', - suggestedQueryText: 'Vous pouvez essayer de rechercher', - reportMissingResultsText: 'Pensez-vous que cette recherche devrait avoir des résultats ?', - reportMissingResultsLinkText: 'Cliquez pour signaler', - }, - }, - }, -} - -export const frSearchLocale: Partial = { - placeholder: 'Rechercher dans la documentation', - resetButtonTitle: 'Réinitialiser la recherche', - backButtonTitle: 'Fermer', - noResultsText: 'Aucun résultat trouvé :', - footer: { - selectText: 'sélectionner', - selectKeyAriaLabel: 'Entrée', - navigateText: 'naviguer', - navigateUpKeyAriaLabel: 'haut', - navigateDownKeyAriaLabel: 'bas', - closeText: 'fermer', - closeKeyAriaLabel: 'sortie', - }, -} diff --git a/theme/src/node/locales/index.ts b/theme/src/node/locales/index.ts index 6f5af6a4b..e09d255b2 100644 --- a/theme/src/node/locales/index.ts +++ b/theme/src/node/locales/index.ts @@ -3,52 +3,32 @@ * 除 /zh/ 、 /en/ 外,其它语言预设通过 AI 生成,不保证准确 * 如有错误,欢迎提 issue */ -import type { SearchLocaleOptions } from '@vuepress-plume/plugin-search' -import type { DocSearchLocaleOptions } from '@vuepress/plugin-docsearch' +import type { DefaultLocaleInfo } from '@vuepress/helper' import type { PlumeThemeLocaleData, PresetLocale } from '../../shared/index.js' -import { deDocsearchLocale, deLocale, dePresetLocale, deSearchLocale } from './de.js' -import { enLocale, enPresetLocale, enSearchLocale } from './en.js' -import { frDocsearchLocale, frLocale, frPresetLocale, frSearchLocale } from './fr.js' -import { jaDocsearchLocale, jaLocale, jaPresetLocale, jaSearchLocale } from './ja.js' -import { ruDocsearchLocale, ruLocale, ruPresetLocale, ruSearchLocale } from './ru.js' -import { zhTwDocsearchLocale, zhTwLocale, zhTwPresetLocale, zhTwSearchLocale } from './zh-tw.js' -import { zhDocsearchLocale, zhLocale, zhPresetLocale, zhSearchLocale } from './zh.js' +import { deLocale, dePresetLocale } from './de.js' +import { enLocale, enPresetLocale } from './en.js' +import { frLocale, frPresetLocale } from './fr.js' +import { jaLocale, jaPresetLocale } from './ja.js' +import { ruLocale, ruPresetLocale } from './ru.js' +import { zhTwLocale, zhTwPresetLocale } from './zh-tw.js' +import { zhLocale, zhPresetLocale } from './zh.js' -export const LOCALE_OPTIONS: Record = { - '/zh/': zhLocale, - '/en/': enLocale, - '/zh-tw/': zhTwLocale, - '/de/': deLocale, - '/fr/': frLocale, - '/ru/': ruLocale, - '/ja/': jaLocale, -} +export const LOCALE_OPTIONS: DefaultLocaleInfo = [ + [['en', 'en-US'], enLocale], + [['zh', 'zh-CN', 'zh-Hans', 'zh-Hant'], zhLocale], + [['zh-TW'], zhTwLocale], + [['de', 'de-DE'], deLocale], + [['fr', 'fr-FR'], frLocale], + [['ru', 'ru-RU'], ruLocale], + [['ja', 'ja-JP'], jaLocale], +] -export const PRESET_LOCALES: Record = { - '/zh/': zhPresetLocale, - '/en/': enPresetLocale, - '/zh-tw/': zhTwPresetLocale, - '/de/': dePresetLocale, - '/fr/': frPresetLocale, - '/ru/': ruPresetLocale, - '/ja/': jaPresetLocale, -} - -export const DOCSEARCH_LOCALES: Record = { - '/zh/': zhDocsearchLocale, - '/zh-tw/': zhTwDocsearchLocale, - '/de/': deDocsearchLocale, - '/fr/': frDocsearchLocale, - '/ru/': ruDocsearchLocale, - '/ja/': jaDocsearchLocale, -} - -export const SEARCH_LOCALES: Record> = { - '/zh/': zhSearchLocale, - '/en/': enSearchLocale, - '/zh-tw/': zhTwSearchLocale, - '/de/': deSearchLocale, - '/fr/': frSearchLocale, - '/ru/': ruSearchLocale, - '/ja/': jaSearchLocale, -} +export const PRESET_LOCALES: DefaultLocaleInfo = [ + [['en', 'en-US'], enPresetLocale], + [['zh', 'zh-CN', 'zh-Hans', 'zh-Hant'], zhPresetLocale], + [['zh-TW'], zhTwPresetLocale], + [['de', 'de-DE'], dePresetLocale], + [['fr', 'fr-FR'], frPresetLocale], + [['ru', 'ru-RU'], ruPresetLocale], + [['ja', 'ja-JP'], jaPresetLocale], +] diff --git a/theme/src/node/locales/ja.ts b/theme/src/node/locales/ja.ts index 883892c4d..5f7108eae 100644 --- a/theme/src/node/locales/ja.ts +++ b/theme/src/node/locales/ja.ts @@ -1,6 +1,4 @@ /** 日语 */ -import type { SearchLocaleOptions } from '@vuepress-plume/plugin-search' -import type { DocSearchLocaleOptions } from '@vuepress/plugin-docsearch' import type { PlumeThemeLocaleData, PresetLocale } from '../../shared/index.js' export const jaLocale: PlumeThemeLocaleData = { @@ -65,61 +63,3 @@ export const jaPresetLocale: PresetLocale = { 'CC-BY-ND-4.0': '表示-改変禁止 4.0 国際', 'CC-BY-SA-4.0': '表示-継承 4.0 国際', } - -export const jaDocsearchLocale: DocSearchLocaleOptions = { - 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: 'フィードバックを送信', - }, - }, - }, -} - -export const jaSearchLocale: Partial = { - placeholder: 'ドキュメントを検索', - resetButtonTitle: '検索をリセット', - backButtonTitle: '閉じる', - noResultsText: '検索結果がありません:', - footer: { - selectText: '選択', - selectKeyAriaLabel: '入力', - navigateText: '切り替え', - navigateUpKeyAriaLabel: '上へ', - navigateDownKeyAriaLabel: '下へ', - closeText: '閉じる', - closeKeyAriaLabel: '終了', - }, -} diff --git a/theme/src/node/locales/ru.ts b/theme/src/node/locales/ru.ts index ace08e487..e245ce573 100644 --- a/theme/src/node/locales/ru.ts +++ b/theme/src/node/locales/ru.ts @@ -1,6 +1,4 @@ /** 俄语 */ -import type { SearchLocaleOptions } from '@vuepress-plume/plugin-search' -import type { DocSearchLocaleOptions } from '@vuepress/plugin-docsearch' import type { PlumeThemeLocaleData, PresetLocale } from '../../shared/index.js' export const ruLocale: PlumeThemeLocaleData = { @@ -65,61 +63,3 @@ export const ruPresetLocale: PresetLocale = { 'CC-BY-ND-4.0': 'Атрибуция-Без производных 4.0 Международный', 'CC-BY-SA-4.0': 'Атрибуция-С сохранением условий 4.0 Международный', } - -export const ruDocsearchLocale: DocSearchLocaleOptions = { - 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: 'Нажмите, чтобы сообщить', - }, - }, - }, -} - -export const ruSearchLocale: Partial = { - placeholder: 'Поиск по документации', - resetButtonTitle: 'Сбросить поиск', - backButtonTitle: 'Закрыть', - noResultsText: 'Нет результатов поиска:', - footer: { - selectText: 'Выбрать', - selectKeyAriaLabel: 'Ввод', - navigateText: 'Переключить', - navigateUpKeyAriaLabel: 'Вверх', - navigateDownKeyAriaLabel: 'Вниз', - closeText: 'Закрыть', - closeKeyAriaLabel: 'Выход', - }, -} diff --git a/theme/src/node/locales/zh-tw.ts b/theme/src/node/locales/zh-tw.ts index a6a7193b2..fb68c0ffb 100644 --- a/theme/src/node/locales/zh-tw.ts +++ b/theme/src/node/locales/zh-tw.ts @@ -1,6 +1,4 @@ /** 繁体中文 */ -import type { SearchLocaleOptions } from '@vuepress-plume/plugin-search' -import type { DocSearchLocaleOptions } from '@vuepress/plugin-docsearch' import type { PlumeThemeLocaleData, PresetLocale } from '../../shared/index.js' export const zhTwLocale: PlumeThemeLocaleData = { @@ -65,61 +63,3 @@ export const zhTwPresetLocale: PresetLocale = { 'CC-BY-ND-4.0': '署名-禁止演繹 4.0 國際', 'CC-BY-SA-4.0': '署名-相同方式共享 4.0 國際', } - -export const zhTwDocsearchLocale: DocSearchLocaleOptions = { - 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: '點擊反饋', - }, - }, - }, -} - -export const zhTwSearchLocale: Partial = { - placeholder: '搜索文檔', - resetButtonTitle: '重置搜索', - backButtonTitle: '關閉', - noResultsText: '無搜索結果:', - footer: { - selectText: '選擇', - selectKeyAriaLabel: '輸入', - navigateText: '切換', - navigateUpKeyAriaLabel: '向上', - navigateDownKeyAriaLabel: '向下', - closeText: '關閉', - closeKeyAriaLabel: '退出', - }, -} diff --git a/theme/src/node/locales/zh.ts b/theme/src/node/locales/zh.ts index 7c1262129..bd56f4b72 100644 --- a/theme/src/node/locales/zh.ts +++ b/theme/src/node/locales/zh.ts @@ -1,5 +1,3 @@ -import type { SearchLocaleOptions } from '@vuepress-plume/plugin-search' -import type { DocSearchLocaleOptions } from '@vuepress/plugin-docsearch' import type { PlumeThemeLocaleData, PresetLocale } from '../../shared/index.js' export const zhLocale: PlumeThemeLocaleData = { @@ -64,61 +62,3 @@ export const zhPresetLocale: PresetLocale = { 'CC-BY-ND-4.0': '署名-禁止演绎 4.0 国际', 'CC-BY-SA-4.0': '署名-相同方式共享 4.0 国际', } - -export const zhDocsearchLocale: DocSearchLocaleOptions = { - 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: '点击反馈', - }, - }, - }, -} - -export const zhSearchLocale: Partial = { - placeholder: '搜索文档', - resetButtonTitle: '重置搜索', - backButtonTitle: '关闭', - noResultsText: '无搜索结果:', - footer: { - selectText: '选择', - selectKeyAriaLabel: '输入', - navigateText: '切换', - navigateUpKeyAriaLabel: '向上', - navigateDownKeyAriaLabel: '向下', - closeText: '关闭', - closeKeyAriaLabel: '退出', - }, -} diff --git a/theme/src/node/plugins/getPlugins.ts b/theme/src/node/plugins/getPlugins.ts index 7ff91185c..f0445a786 100644 --- a/theme/src/node/plugins/getPlugins.ts +++ b/theme/src/node/plugins/getPlugins.ts @@ -21,7 +21,6 @@ import { sitemapPlugin, type SitemapPluginOptions } from '@vuepress/plugin-sitem import { watermarkPlugin } from '@vuepress/plugin-watermark' import { mdEnhancePlugin } from 'vuepress-plugin-md-enhance' import { markdownPowerPlugin } from 'vuepress-plugin-md-power' -import { resolveDocsearchOptions, resolveSearchOptions } from '../config/index.js' export interface SetupPluginOptions { app: App @@ -95,13 +94,13 @@ export function getPlugins( if (pluginOptions.docsearch) { if (pluginOptions.docsearch.appId && pluginOptions.docsearch.apiKey) - plugins.push(docsearchPlugin(resolveDocsearchOptions(app, pluginOptions.docsearch))) + plugins.push(docsearchPlugin(pluginOptions.docsearch)) else console.error('docsearch plugin: appId and apiKey are both required') } else if (pluginOptions.search !== false) { - plugins.push(searchPlugin(resolveSearchOptions(app, pluginOptions.search))) + plugins.push(searchPlugin(pluginOptions.search || {})) } const shikiOption = pluginOptions.shiki