-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
feat(algolia-search): allow translating search modal #7666
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a3534d4
feat: add translations for modal search Algolia
forresst b177a48
zh
Josh-Cena 6ac9a3f
extract translations to a separate file and delete duplicate translat…
forresst a689bc4
Update packages/docusaurus-theme-search-algolia/src/theme/SearchBar/t…
Josh-Cena 8151ab4
Update theme-search-algolia.json
Josh-Cena 64a10bb
Update theme-search-algolia.json
Josh-Cena 0208ef1
refactor
Josh-Cena 62ddf74
Merge branch 'main' into translate-modal-algolia
forresst b79c730
fix translations ar and vi
forresst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import Translate, {translate} from '@docusaurus/Translate'; | |
import type { | ||
DocSearchModal as DocSearchModalType, | ||
DocSearchModalProps, | ||
DocSearchTranslations, | ||
} from '@docsearch/react'; | ||
import type { | ||
InternalDocSearchHit, | ||
|
@@ -221,6 +222,149 @@ function DocSearch({ | |
description: 'The ARIA label and placeholder for search button', | ||
}); | ||
|
||
const translatedModal: DocSearchTranslations = { | ||
modal: { | ||
searchBox: { | ||
resetButtonTitle: translate({ | ||
id: 'theme.SearchModal.searchBox.resetButtonTitle', | ||
message: 'Clear the query', | ||
description: 'The label for search box reset button', | ||
}), | ||
resetButtonAriaLabel: translate({ | ||
id: 'theme.SearchModal.searchBox.resetButtonAriaLabel', | ||
message: 'Clear the query', | ||
description: 'The ARIA label for search box reset button', | ||
}), | ||
cancelButtonText: translate({ | ||
id: 'theme.SearchModal.searchBox.cancelButtonText', | ||
message: 'Cancel', | ||
description: 'The label for search box cancel button', | ||
}), | ||
cancelButtonAriaLabel: translate({ | ||
id: 'theme.SearchModal.searchBox.cancelButtonAriaLabel', | ||
message: 'Cancel', | ||
description: 'The ARIA label for search box cancel button', | ||
}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks repetitive to me. What are the odds that the user wants different translations for these labels? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. I'll change it to one |
||
}, | ||
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', | ||
}), | ||
}, | ||
}, | ||
}; | ||
|
||
return ( | ||
<> | ||
<Head> | ||
|
@@ -263,6 +407,7 @@ function DocSearch({ | |
})} | ||
{...props} | ||
searchParameters={searchParameters} | ||
translations={translatedModal} | ||
/>, | ||
searchContainer.current, | ||
)} | ||
|
24 changes: 24 additions & 0 deletions
24
packages/docusaurus-theme-translations/locales/ar/theme-search-algolia.json
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
24 changes: 24 additions & 0 deletions
24
packages/docusaurus-theme-translations/locales/bn/theme-search-algolia.json
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
24 changes: 24 additions & 0 deletions
24
packages/docusaurus-theme-translations/locales/cs/theme-search-algolia.json
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we extract all the translations to a separate file, or at least outside the component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree 👍 we'll want to reduce the size of this component, and probably later also use some of those translations on the search page (quite old/legacy, but we'll want to refactor/upgrade someday)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Josh-Cena @slorber Agree in principle. It makes sense. How should I implement this? I haven't found any examples in the current code that already do this. Unless I have misunderstood the request... 😜
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Um, it just means copying everything to another file like
src/theme/searchTranslations.ts
, and then importing it asimport translations from "@theme/searchTranslations"
...