Skip to content

Commit

Permalink
Merge pull request #15 from Misaka-L/main
Browse files Browse the repository at this point in the history
feature: algolia localization
  • Loading branch information
gizmo-ds authored Mar 25, 2024
2 parents 9b73af0 + 7b4a42d commit 2cd82da
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 14 deletions.
31 changes: 30 additions & 1 deletion localization/algolia.en.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
{
"placeholder": "Search the VRChat docs"
"placeholder": "Search the VRChat docs",
"translations": {
"buttonText": "Search",
"buttonAriaLabel": "Search",
"resetButtonTitle": "Clear the query",
"resetButtonAriaLabel": "Clear the query",
"cancelButtonText": "Cancel",
"cancelButtonAriaLabel": "Cancel",
"searchInputLabel": "Search",
"recentSearchesTitle": "Recent",
"noRecentSearchesText": "No recent searches",
"saveRecentSearchButtonTitle": "Save this search",
"removeRecentSearchButtonTitle": "Remove this search from history",
"favoriteSearchesTitle": "Favorite",
"removeFavoriteSearchButtonTitle": "Remove this search from favorites",
"titleText": "Unable to fetch results",
"helpText": "You might want to check your network connection.",
"selectText": "to select",
"selectKeyAriaLabel": "Enter key",
"navigateText": "to navigate",
"navigateUpKeyAriaLabel": "Arrow up",
"navigateDownKeyAriaLabel": "Arrow down",
"closeText": "to close",
"closeKeyAriaLabel": "Escape key",
"searchByText": "Search by",
"noResultsText": "No results for",
"suggestedQueryText": "Try searching for",
"reportMissingResultsText": "Believe this query should return results?",
"reportMissingResultsLinkText": "Let us know."
}
}
12 changes: 1 addition & 11 deletions localization/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,6 @@
"Learn how to upgrade projects from Unity 2019 to Unity 2022.": "了解如何将项目从 Unity 2019 升级到 Unity 2022。",
"VRC Quick Launcher": "VRC 快速启动器",
"This tool helps you launch multiple profiles in the same VRChat instance, while also providing an interface to modify the debug options.": "该工具可帮助您在同一个 VRChat 实例中启动多个配置文件,同时还提供了一个修改调试选项的界面。",
"Search": "搜索",
"No recent searches": "最近没有搜索任何关键词",
"to select": "选择搜索结果",
"to navigate": "在不同搜索结果之间切换",
"to close": "关闭搜索窗口",
"Search the VRChat docs": "搜索 VRChat 文档",
"Search by": "搜索引擎提供商",
"Clear the query": "清除搜索关键词",
"No result for \"(.+)\"": "关键词 \"$1\" 无搜索结果",
"Try searching for:": "尝试搜索",
"You are using a ": "你正在使用 ",
" build of the Creator Companion, it is intended for testing purposes and can be unstable.": " 版本的创作者助手,该版本是为测试用途构建的并且可能会很不稳定。",
"Copy Live Settings and Data": "复制正式版的设置和数据",
Expand Down Expand Up @@ -368,4 +358,4 @@
"Hey you, you're cool": "嘿!你个酷盖!",
"Checking Package Availability": "检查包可用性",
"Packages are being added to the project": "正在向项目添加包"
}
}
71 changes: 69 additions & 2 deletions src/patch/algolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ const info = {
const is_str_set = (v: string | undefined) => v && v != ''
const replace = is_str_set(info.apiKey) && is_str_set(info.appId) && is_str_set(info.indexName)

interface Localization {
translations: DocSearchTranslations
placeholder: string
}

const fname = '__algolia_patch__'
let localization: Record<string, string> = {}
let localization: Localization | undefined

function func(e: any, t: any) {
if (!e) return t
if (!(t.apiKey && t.appId && t.appId && t.placeholder)) return t

t.placeholder = localization['placeholder']
t.placeholder = localization?.placeholder
t.translations = localization
if (replace) {
t.apiKey = info.apiKey
t.appId = info.appId
Expand All @@ -41,3 +47,64 @@ const config: Config = {
}

export default config

interface DocSearchTranslations
extends ButtonTranslations,
SearchBoxTranslations,
FooterTranslations,
ErrorScreenTranslations,
StartScreenTranslations,
NoResultsScreenTranslations {
placeholder?: string
}

// https://github.com/algolia/docsearch/blob/2df2e1392fa80e5cc9cafac3437685331b9f07ec/packages/docsearch-react/src/DocSearchButton.tsx#L6-L9
type ButtonTranslations = Partial<{
buttonText: string
buttonAriaLabel: string
}>

// https://github.com/algolia/docsearch/blob/2df2e1392fa80e5cc9cafac3437685331b9f07ec/packages/docsearch-react/src/SearchBox.tsx#L14-L20
type SearchBoxTranslations = Partial<{
resetButtonTitle: string
resetButtonAriaLabel: string
cancelButtonText: string
cancelButtonAriaLabel: string
searchInputLabel: string
}>

// https://github.com/algolia/docsearch/blob/2df2e1392fa80e5cc9cafac3437685331b9f07ec/packages/docsearch-react/src/Footer.tsx#L5-L14
type FooterTranslations = Partial<{
selectText: string
selectKeyAriaLabel: string
navigateText: string
navigateUpKeyAriaLabel: string
navigateDownKeyAriaLabel: string
closeText: string
closeKeyAriaLabel: string
searchByText: string
}>

// https://github.com/algolia/docsearch/blob/2df2e1392fa80e5cc9cafac3437685331b9f07ec/packages/docsearch-react/src/ErrorScreen.tsx#L5-L8
type ErrorScreenTranslations = Partial<{
titleText: string
helpText: string
}>

// https://github.com/algolia/docsearch/blob/2df2e1392fa80e5cc9cafac3437685331b9f07ec/packages/docsearch-react/src/StartScreen.tsx#L8-L15
type StartScreenTranslations = Partial<{
recentSearchesTitle: string
noRecentSearchesText: string
saveRecentSearchButtonTitle: string
removeRecentSearchButtonTitle: string
favoriteSearchesTitle: string
removeFavoriteSearchButtonTitle: string
}>

// https://github.com/algolia/docsearch/blob/2df2e1392fa80e5cc9cafac3437685331b9f07ec/packages/docsearch-react/src/NoResultsScreen.tsx#L7-L12
type NoResultsScreenTranslations = Partial<{
noResultsText: string
suggestedQueryText: string
reportMissingResultsText: string
reportMissingResultsLinkText: string
}>

0 comments on commit 2cd82da

Please sign in to comment.