-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support i18n for search context labels
- Loading branch information
1 parent
0be2e80
commit 83b05a2
Showing
9 changed files
with
166 additions
and
85 deletions.
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
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
36 changes: 36 additions & 0 deletions
36
docusaurus-search-local/src/client/utils/normalizeContextByPath.ts
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
interface DetailedItem { | ||
label: string | Record<string, string>; | ||
path: string; | ||
} | ||
|
||
interface NormalizedItem { | ||
path: string; | ||
label: string; | ||
} | ||
|
||
export function normalizeContextByPath( | ||
context: string | DetailedItem, | ||
currentLocale: string | ||
): NormalizedItem { | ||
if (typeof context === "string") { | ||
return { | ||
label: context, | ||
path: context, | ||
}; | ||
} else { | ||
const { label, path } = context; | ||
if (typeof label === "string") { | ||
return { label, path }; | ||
} | ||
if (Object.prototype.hasOwnProperty.call(label, currentLocale)) { | ||
return { | ||
label: label[currentLocale], | ||
path, | ||
}; | ||
} | ||
return { | ||
label: path, | ||
path, | ||
}; | ||
} | ||
} |
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
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