Skip to content

Commit

Permalink
feat(algolia-search): allow translating search modal (#7666)
Browse files Browse the repository at this point in the history
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
  • Loading branch information
2 people authored and slorber committed Jul 14, 2022
1 parent b018feb commit f7c79c0
Show file tree
Hide file tree
Showing 27 changed files with 759 additions and 11 deletions.
Expand Up @@ -33,3 +33,10 @@ declare module '@theme/SearchPage' {
declare module '@theme/SearchBar' {
export default function SearchBar(): JSX.Element;
}

declare module '@theme/SearchTranslations' {
import type {DocSearchTranslations} from '@docsearch/react';

const translations: DocSearchTranslations & {placeholder: string};
export default translations;
}
Expand Up @@ -16,7 +16,8 @@ import {isRegexpStringMatch} from '@docusaurus/theme-common';
import {useSearchPage} from '@docusaurus/theme-common/internal';
import {DocSearchButton, useDocSearchKeyboardEvents} from '@docsearch/react';
import {useAlgoliaContextualFacetFilters} from '@docusaurus/theme-search-algolia/client';
import Translate, {translate} from '@docusaurus/Translate';
import Translate from '@docusaurus/Translate';
import translations from '@theme/SearchTranslations';

import type {
DocSearchModal as DocSearchModalType,
Expand Down Expand Up @@ -216,12 +217,6 @@ function DocSearch({
searchButtonRef,
});

const translatedSearchLabel = translate({
id: 'theme.SearchBar.label',
message: 'Search',
description: 'The ARIA label and placeholder for search button',
});

return (
<>
<Head>
Expand All @@ -241,10 +236,7 @@ function DocSearch({
onMouseOver={importDocSearchModalIfNeeded}
onClick={onOpen}
ref={searchButtonRef}
translations={{
buttonText: translatedSearchLabel,
buttonAriaLabel: translatedSearchLabel,
}}
translations={translations.button}
/>

{isOpen &&
Expand All @@ -264,6 +256,8 @@ function DocSearch({
})}
{...props}
searchParameters={searchParameters}
placeholder={translations.placeholder}
translations={translations.modal}
/>,
searchContainer.current,
)}
Expand Down
@@ -0,0 +1,172 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import {translate} from '@docusaurus/Translate';

import type {DocSearchTranslations} from '@docsearch/react';

const translations: DocSearchTranslations & {placeholder: string} = {
button: {
buttonText: translate({
id: 'theme.SearchBar.label',
message: 'Search',
description: 'The ARIA label and placeholder for search button',
}),
buttonAriaLabel: translate({
id: 'theme.SearchBar.label',
message: 'Search',
description: 'The ARIA label and placeholder for search button',
}),
},
modal: {
searchBox: {
resetButtonTitle: translate({
id: 'theme.SearchModal.searchBox.resetButtonTitle',
message: 'Clear the query',
description: 'The label and ARIA label for search box reset button',
}),
resetButtonAriaLabel: translate({
id: 'theme.SearchModal.searchBox.resetButtonTitle',
message: 'Clear the query',
description: 'The label and ARIA label for search box reset button',
}),
cancelButtonText: translate({
id: 'theme.SearchModal.searchBox.cancelButtonText',
message: 'Cancel',
description: 'The label and ARIA label for search box cancel button',
}),
cancelButtonAriaLabel: translate({
id: 'theme.SearchModal.searchBox.cancelButtonText',
message: 'Cancel',
description: 'The label and ARIA label for search box cancel button',
}),
},
startScreen: {
recentSearchesTitle: translate({
id: 'theme.SearchModal.startScreen.recentSearchesTitle',
message: 'Recent',
description: 'The title for recent searches',
}),
noRecentSearchesText: translate({
id: 'theme.SearchModal.startScreen.noRecentSearchesText',
message: 'No recent searches',
description: 'The text when no recent searches',
}),
saveRecentSearchButtonTitle: translate({
id: 'theme.SearchModal.startScreen.saveRecentSearchButtonTitle',
message: 'Save this search',
description: 'The label for save recent search button',
}),
removeRecentSearchButtonTitle: translate({
id: 'theme.SearchModal.startScreen.removeRecentSearchButtonTitle',
message: 'Remove this search from history',
description: 'The label for remove recent search button',
}),
favoriteSearchesTitle: translate({
id: 'theme.SearchModal.startScreen.favoriteSearchesTitle',
message: 'Favorite',
description: 'The title for favorite searches',
}),
removeFavoriteSearchButtonTitle: translate({
id: 'theme.SearchModal.startScreen.removeFavoriteSearchButtonTitle',
message: 'Remove this search from favorites',
description: 'The label for remove favorite search button',
}),
},
errorScreen: {
titleText: translate({
id: 'theme.SearchModal.errorScreen.titleText',
message: 'Unable to fetch results',
description: 'The title for error screen of search modal',
}),
helpText: translate({
id: 'theme.SearchModal.errorScreen.helpText',
message: 'You might want to check your network connection.',
description: 'The help text for error screen of search modal',
}),
},
footer: {
selectText: translate({
id: 'theme.SearchModal.footer.selectText',
message: 'to select',
description: 'The explanatory text of the action for the enter key',
}),
selectKeyAriaLabel: translate({
id: 'theme.SearchModal.footer.selectKeyAriaLabel',
message: 'Enter key',
description:
'The ARIA label for the Enter key button that makes the selection',
}),
navigateText: translate({
id: 'theme.SearchModal.footer.navigateText',
message: 'to navigate',
description:
'The explanatory text of the action for the Arrow up and Arrow down key',
}),
navigateUpKeyAriaLabel: translate({
id: 'theme.SearchModal.footer.navigateUpKeyAriaLabel',
message: 'Arrow up',
description:
'The ARIA label for the Arrow up key button that makes the navigation',
}),
navigateDownKeyAriaLabel: translate({
id: 'theme.SearchModal.footer.navigateDownKeyAriaLabel',
message: 'Arrow down',
description:
'The ARIA label for the Arrow down key button that makes the navigation',
}),
closeText: translate({
id: 'theme.SearchModal.footer.closeText',
message: 'to close',
description: 'The explanatory text of the action for Escape key',
}),
closeKeyAriaLabel: translate({
id: 'theme.SearchModal.footer.closeKeyAriaLabel',
message: 'Escape key',
description:
'The ARIA label for the Escape key button that close the modal',
}),
searchByText: translate({
id: 'theme.SearchModal.footer.searchByText',
message: 'Search by',
description: 'The text explain that the search is making by Algolia',
}),
},
noResultsScreen: {
noResultsText: translate({
id: 'theme.SearchModal.noResultsScreen.noResultsText',
message: 'No results for',
description:
'The text explains that there are no results for the following search',
}),
suggestedQueryText: translate({
id: 'theme.SearchModal.noResultsScreen.suggestedQueryText',
message: 'Try searching for',
description:
'The text for the suggested query when no results are found for the following search',
}),
reportMissingResultsText: translate({
id: 'theme.SearchModal.noResultsScreen.reportMissingResultsText',
message: 'Believe this query should return results?',
description:
'The text for the question where the user thinks there are missing results',
}),
reportMissingResultsLinkText: translate({
id: 'theme.SearchModal.noResultsScreen.reportMissingResultsLinkText',
message: 'Let us know.',
description: 'The text for the link to report missing results',
}),
},
},
placeholder: translate({
id: 'theme.SearchModal.placeholder',
message: 'Search docs',
description: 'The placeholder of the input of the DocSearch pop-up modal',
}),
};

export default translations;
@@ -1,6 +1,29 @@
{
"theme.SearchBar.label": "بحث",
"theme.SearchBar.seeAll": "مشاهدة جميع {count} نتائج",
"theme.SearchModal.errorScreen.helpText": "You might want to check your network connection.",
"theme.SearchModal.errorScreen.titleText": "Unable to fetch results",
"theme.SearchModal.footer.closeKeyAriaLabel": "Escape key",
"theme.SearchModal.footer.closeText": "to close",
"theme.SearchModal.footer.navigateDownKeyAriaLabel": "Arrow down",
"theme.SearchModal.footer.navigateText": "to navigate",
"theme.SearchModal.footer.navigateUpKeyAriaLabel": "Arrow up",
"theme.SearchModal.footer.searchByText": "Search by",
"theme.SearchModal.footer.selectKeyAriaLabel": "Enter key",
"theme.SearchModal.footer.selectText": "to select",
"theme.SearchModal.noResultsScreen.noResultsText": "No results for",
"theme.SearchModal.noResultsScreen.reportMissingResultsLinkText": "Let us know.",
"theme.SearchModal.noResultsScreen.reportMissingResultsText": "Believe this query should return results?",
"theme.SearchModal.noResultsScreen.suggestedQueryText": "Try searching for",
"theme.SearchModal.placeholder": "Search docs",
"theme.SearchModal.searchBox.cancelButtonText": "Cancel",
"theme.SearchModal.searchBox.resetButtonTitle": "Clear the query",
"theme.SearchModal.startScreen.favoriteSearchesTitle": "Favorite",
"theme.SearchModal.startScreen.noRecentSearchesText": "No recent searches",
"theme.SearchModal.startScreen.recentSearchesTitle": "Recent",
"theme.SearchModal.startScreen.removeFavoriteSearchButtonTitle": "Remove this search from favorites",
"theme.SearchModal.startScreen.removeRecentSearchButtonTitle": "Remove this search from history",
"theme.SearchModal.startScreen.saveRecentSearchButtonTitle": "Save this search",
"theme.SearchPage.algoliaLabel": "البحث بواسطه Algolia",
"theme.SearchPage.documentsFound.plurals": "تم العثور على مستند واحد|تم العثور على {count} مستندات",
"theme.SearchPage.emptyResultsTitle": "ابحث في الوثائق",
Expand Down
Expand Up @@ -2,6 +2,52 @@
"theme.SearchBar.label": "Search",
"theme.SearchBar.label___DESCRIPTION": "The ARIA label and placeholder for search button",
"theme.SearchBar.seeAll": "See all {count} results",
"theme.SearchModal.errorScreen.helpText": "You might want to check your network connection.",
"theme.SearchModal.errorScreen.helpText___DESCRIPTION": "The help text for error screen of search modal",
"theme.SearchModal.errorScreen.titleText": "Unable to fetch results",
"theme.SearchModal.errorScreen.titleText___DESCRIPTION": "The title for error screen of search modal",
"theme.SearchModal.footer.closeKeyAriaLabel": "Escape key",
"theme.SearchModal.footer.closeKeyAriaLabel___DESCRIPTION": "The ARIA label for the Escape key button that close the modal",
"theme.SearchModal.footer.closeText": "to close",
"theme.SearchModal.footer.closeText___DESCRIPTION": "The explanatory text of the action for Escape key",
"theme.SearchModal.footer.navigateDownKeyAriaLabel": "Arrow down",
"theme.SearchModal.footer.navigateDownKeyAriaLabel___DESCRIPTION": "The ARIA label for the Arrow down key button that makes the navigation",
"theme.SearchModal.footer.navigateText": "to navigate",
"theme.SearchModal.footer.navigateText___DESCRIPTION": "The explanatory text of the action for the Arrow up and Arrow down key",
"theme.SearchModal.footer.navigateUpKeyAriaLabel": "Arrow up",
"theme.SearchModal.footer.navigateUpKeyAriaLabel___DESCRIPTION": "The ARIA label for the Arrow up key button that makes the navigation",
"theme.SearchModal.footer.searchByText": "Search by",
"theme.SearchModal.footer.searchByText___DESCRIPTION": "The text explain that the search is making by Algolia",
"theme.SearchModal.footer.selectKeyAriaLabel": "Enter key",
"theme.SearchModal.footer.selectKeyAriaLabel___DESCRIPTION": "The ARIA label for the Enter key button that makes the selection",
"theme.SearchModal.footer.selectText": "to select",
"theme.SearchModal.footer.selectText___DESCRIPTION": "The explanatory text of the action for the enter key",
"theme.SearchModal.noResultsScreen.noResultsText": "No results for",
"theme.SearchModal.noResultsScreen.noResultsText___DESCRIPTION": "The text explains that there are no results for the following search",
"theme.SearchModal.noResultsScreen.reportMissingResultsLinkText": "Let us know.",
"theme.SearchModal.noResultsScreen.reportMissingResultsLinkText___DESCRIPTION": "The text for the link to report missing results",
"theme.SearchModal.noResultsScreen.reportMissingResultsText": "Believe this query should return results?",
"theme.SearchModal.noResultsScreen.reportMissingResultsText___DESCRIPTION": "The text for the question where the user thinks there are missing results",
"theme.SearchModal.noResultsScreen.suggestedQueryText": "Try searching for",
"theme.SearchModal.noResultsScreen.suggestedQueryText___DESCRIPTION": "The text for the suggested query when no results are found for the following search",
"theme.SearchModal.placeholder": "Search docs",
"theme.SearchModal.placeholder___DESCRIPTION": "The placeholder of the input of the DocSearch pop-up modal",
"theme.SearchModal.searchBox.cancelButtonText": "Cancel",
"theme.SearchModal.searchBox.cancelButtonText___DESCRIPTION": "The label and ARIA label for search box cancel button",
"theme.SearchModal.searchBox.resetButtonTitle": "Clear the query",
"theme.SearchModal.searchBox.resetButtonTitle___DESCRIPTION": "The label and ARIA label for search box reset button",
"theme.SearchModal.startScreen.favoriteSearchesTitle": "Favorite",
"theme.SearchModal.startScreen.favoriteSearchesTitle___DESCRIPTION": "The title for favorite searches",
"theme.SearchModal.startScreen.noRecentSearchesText": "No recent searches",
"theme.SearchModal.startScreen.noRecentSearchesText___DESCRIPTION": "The text when no recent searches",
"theme.SearchModal.startScreen.recentSearchesTitle": "Recent",
"theme.SearchModal.startScreen.recentSearchesTitle___DESCRIPTION": "The title for recent searches",
"theme.SearchModal.startScreen.removeFavoriteSearchButtonTitle": "Remove this search from favorites",
"theme.SearchModal.startScreen.removeFavoriteSearchButtonTitle___DESCRIPTION": "The label for remove favorite search button",
"theme.SearchModal.startScreen.removeRecentSearchButtonTitle": "Remove this search from history",
"theme.SearchModal.startScreen.removeRecentSearchButtonTitle___DESCRIPTION": "The label for remove recent search button",
"theme.SearchModal.startScreen.saveRecentSearchButtonTitle": "Save this search",
"theme.SearchModal.startScreen.saveRecentSearchButtonTitle___DESCRIPTION": "The label for save recent search button",
"theme.SearchPage.algoliaLabel": "Search by Algolia",
"theme.SearchPage.algoliaLabel___DESCRIPTION": "The ARIA label for Algolia mention",
"theme.SearchPage.documentsFound.plurals": "One document found|{count} documents found",
Expand Down
@@ -1,6 +1,29 @@
{
"theme.SearchBar.label": "সার্চ",
"theme.SearchBar.seeAll": "See all {count} results",
"theme.SearchModal.errorScreen.helpText": "You might want to check your network connection.",
"theme.SearchModal.errorScreen.titleText": "Unable to fetch results",
"theme.SearchModal.footer.closeKeyAriaLabel": "Escape key",
"theme.SearchModal.footer.closeText": "to close",
"theme.SearchModal.footer.navigateDownKeyAriaLabel": "Arrow down",
"theme.SearchModal.footer.navigateText": "to navigate",
"theme.SearchModal.footer.navigateUpKeyAriaLabel": "Arrow up",
"theme.SearchModal.footer.searchByText": "Search by",
"theme.SearchModal.footer.selectKeyAriaLabel": "Enter key",
"theme.SearchModal.footer.selectText": "to select",
"theme.SearchModal.noResultsScreen.noResultsText": "No results for",
"theme.SearchModal.noResultsScreen.reportMissingResultsLinkText": "Let us know.",
"theme.SearchModal.noResultsScreen.reportMissingResultsText": "Believe this query should return results?",
"theme.SearchModal.noResultsScreen.suggestedQueryText": "Try searching for",
"theme.SearchModal.placeholder": "Search docs",
"theme.SearchModal.searchBox.cancelButtonText": "Cancel",
"theme.SearchModal.searchBox.resetButtonTitle": "Clear the query",
"theme.SearchModal.startScreen.favoriteSearchesTitle": "Favorite",
"theme.SearchModal.startScreen.noRecentSearchesText": "No recent searches",
"theme.SearchModal.startScreen.recentSearchesTitle": "Recent",
"theme.SearchModal.startScreen.removeFavoriteSearchButtonTitle": "Remove this search from favorites",
"theme.SearchModal.startScreen.removeRecentSearchButtonTitle": "Remove this search from history",
"theme.SearchModal.startScreen.saveRecentSearchButtonTitle": "Save this search",
"theme.SearchPage.algoliaLabel": "আলগোলিয়া দ্বারা অনুসন্ধান করুন",
"theme.SearchPage.documentsFound.plurals": "একটি ডকুমেন্ট পাওয়া গেছে|{count} ডকুমেন্টস পাওয়া গেছে",
"theme.SearchPage.emptyResultsTitle": "ডকুমেন্টেশন অনুসন্ধান করুন",
Expand Down
@@ -1,6 +1,29 @@
{
"theme.SearchBar.label": "Hledat",
"theme.SearchBar.seeAll": "See all {count} results",
"theme.SearchModal.errorScreen.helpText": "You might want to check your network connection.",
"theme.SearchModal.errorScreen.titleText": "Unable to fetch results",
"theme.SearchModal.footer.closeKeyAriaLabel": "Escape key",
"theme.SearchModal.footer.closeText": "to close",
"theme.SearchModal.footer.navigateDownKeyAriaLabel": "Arrow down",
"theme.SearchModal.footer.navigateText": "to navigate",
"theme.SearchModal.footer.navigateUpKeyAriaLabel": "Arrow up",
"theme.SearchModal.footer.searchByText": "Search by",
"theme.SearchModal.footer.selectKeyAriaLabel": "Enter key",
"theme.SearchModal.footer.selectText": "to select",
"theme.SearchModal.noResultsScreen.noResultsText": "No results for",
"theme.SearchModal.noResultsScreen.reportMissingResultsLinkText": "Let us know.",
"theme.SearchModal.noResultsScreen.reportMissingResultsText": "Believe this query should return results?",
"theme.SearchModal.noResultsScreen.suggestedQueryText": "Try searching for",
"theme.SearchModal.placeholder": "Search docs",
"theme.SearchModal.searchBox.cancelButtonText": "Cancel",
"theme.SearchModal.searchBox.resetButtonTitle": "Clear the query",
"theme.SearchModal.startScreen.favoriteSearchesTitle": "Favorite",
"theme.SearchModal.startScreen.noRecentSearchesText": "No recent searches",
"theme.SearchModal.startScreen.recentSearchesTitle": "Recent",
"theme.SearchModal.startScreen.removeFavoriteSearchButtonTitle": "Remove this search from favorites",
"theme.SearchModal.startScreen.removeRecentSearchButtonTitle": "Remove this search from history",
"theme.SearchModal.startScreen.saveRecentSearchButtonTitle": "Save this search",
"theme.SearchPage.algoliaLabel": "Vyhledávání od Algolia",
"theme.SearchPage.documentsFound.plurals": "Jeden dokument nalezen|{count} dokumenty nalezeny|{count} dokumentů nalezeno",
"theme.SearchPage.emptyResultsTitle": "Prohledat dokumentaci",
Expand Down

0 comments on commit f7c79c0

Please sign in to comment.