diff --git a/.changeset/slimy-vans-rush.md b/.changeset/slimy-vans-rush.md
new file mode 100644
index 00000000000..009d3a8cf0d
--- /dev/null
+++ b/.changeset/slimy-vans-rush.md
@@ -0,0 +1,5 @@
+---
+'nextra-theme-docs': patch
+---
+
+Update the `backToTop` option in the docs theme configuration to support i18n
diff --git a/.changeset/wild-windows-grow.md b/.changeset/wild-windows-grow.md
new file mode 100644
index 00000000000..b2a1bbe6216
--- /dev/null
+++ b/.changeset/wild-windows-grow.md
@@ -0,0 +1,5 @@
+---
+'nextra-theme-docs': minor
+---
+
+keep `loading`, `placeholder` and `themeSwitch.useOptions` default theme options only for `en` lang
diff --git a/docs/next-env.d.ts b/docs/next-env.d.ts
index 4f11a03dc6c..a4a7b3f5cfa 100644
--- a/docs/next-env.d.ts
+++ b/docs/next-env.d.ts
@@ -2,4 +2,4 @@
///
// NOTE: This file should not be edited
-// see https://nextjs.org/docs/basic-features/typescript for more information.
+// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
diff --git a/docs/pages/docs/docs-theme/theme-configuration.mdx b/docs/pages/docs/docs-theme/theme-configuration.mdx
index 0b7836a3f9a..43b3f777602 100644
--- a/docs/pages/docs/docs-theme/theme-configuration.mdx
+++ b/docs/pages/docs/docs-theme/theme-configuration.mdx
@@ -534,7 +534,11 @@ navigating between headings.
'React.ReactNode | React.FC',
'Title of the TOC sidebar. By default it’s “On This Page”.'
],
- ['toc.backToTop', 'boolean', 'Add `Scroll to top` link.']
+ [
+ 'toc.backToTop',
+ 'React.ReactNode | React.FC',
+ 'Text of `Scroll to top` button.'
+ ]
]}
/>
diff --git a/examples/swr-site/next-env.d.ts b/examples/swr-site/next-env.d.ts
index fd36f9494e2..725dd6f2451 100644
--- a/examples/swr-site/next-env.d.ts
+++ b/examples/swr-site/next-env.d.ts
@@ -3,4 +3,4 @@
///
// NOTE: This file should not be edited
-// see https://nextjs.org/docs/basic-features/typescript for more information.
+// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
diff --git a/examples/swr-site/theme.config.tsx b/examples/swr-site/theme.config.tsx
index 707c9ca5f3c..03913b5c014 100644
--- a/examples/swr-site/theme.config.tsx
+++ b/examples/swr-site/theme.config.tsx
@@ -190,6 +190,14 @@ const config: DocsThemeConfig = {
toggleButton: true
},
toc: {
+ backToTop: function BackToTop() {
+ const { locale } = useRouter()
+ return {
+ en: 'Scroll to top',
+ es: 'Desplazarse hacia arriba',
+ ru: 'Перейти наверх'
+ }[locale!]
+ },
extraContent: (
),
diff --git a/packages/nextra-theme-docs/src/components/back-to-top.tsx b/packages/nextra-theme-docs/src/components/back-to-top.tsx
index 58d45a87028..9dd517aefef 100644
--- a/packages/nextra-theme-docs/src/components/back-to-top.tsx
+++ b/packages/nextra-theme-docs/src/components/back-to-top.tsx
@@ -1,7 +1,7 @@
import cn from 'clsx'
import { Button } from 'nextra/components'
import { ArrowRightIcon } from 'nextra/icons'
-import type { ComponentProps, ReactElement } from 'react'
+import type { ComponentProps, ReactElement, ReactNode } from 'react'
const SCROLL_TO_OPTIONS = { top: 0, behavior: 'smooth' } as const
@@ -18,9 +18,11 @@ const scrollToTop: ComponentProps<'button'>['onClick'] = event => {
}
export function BackToTop({
+ children,
className,
hidden
}: {
+ children: ReactNode
className?: string
hidden: boolean
}): ReactElement {
@@ -38,7 +40,7 @@ export function BackToTop({
)
}
>
- Scroll to top
+ {children}
+
+ {renderComponent(themeConfig.toc.backToTop)}
+
)}
)}
diff --git a/packages/nextra-theme-docs/src/constants.tsx b/packages/nextra-theme-docs/src/constants.tsx
index cfa06ad061c..1ed498764f4 100644
--- a/packages/nextra-theme-docs/src/constants.tsx
+++ b/packages/nextra-theme-docs/src/constants.tsx
@@ -1,5 +1,5 @@
/* eslint sort-keys: error */
-import { useRouter } from 'next/router'
+import { useRouter } from 'nextra/hooks'
import { DiscordIcon, GitHubIcon } from 'nextra/icons'
import { isValidElement } from 'react'
import type { z } from 'zod'
@@ -20,20 +20,6 @@ export const DEFAULT_LOCALE = 'en-US'
export type DocsThemeConfig = z.infer
export type PartialDocsThemeConfig = z.infer
-const LOADING_LOCALES: Record = {
- 'en-US': 'Loading',
- fr: 'Сhargement',
- ru: 'Загрузка',
- 'zh-CN': '正在加载'
-}
-
-const PLACEHOLDER_LOCALES: Record = {
- 'en-US': 'Search documentation',
- fr: 'Rechercher documents',
- ru: 'Поиск документации',
- 'zh-CN': '搜索文档'
-}
-
export const DEFAULT_THEME: DocsThemeConfig = {
backgroundColor: {
dark: '17,17,17',
@@ -164,19 +150,8 @@ export const DEFAULT_THEME: DocsThemeConfig = {
),
error: 'Failed to load search index.',
- loading: function useLoading() {
- const { locale, defaultLocale = DEFAULT_LOCALE } = useRouter()
- const text =
- (locale && LOADING_LOCALES[locale]) || LOADING_LOCALES[defaultLocale]
- return <>{text}…>
- },
- placeholder: function usePlaceholder() {
- const { locale, defaultLocale = DEFAULT_LOCALE } = useRouter()
- const text =
- (locale && PLACEHOLDER_LOCALES[locale]) ||
- PLACEHOLDER_LOCALES[defaultLocale]
- return `${text}…`
- }
+ loading: 'Loading…',
+ placeholder: 'Search documentation…'
},
sidebar: {
defaultMenuCollapseLevel: 2,
@@ -184,17 +159,10 @@ export const DEFAULT_THEME: DocsThemeConfig = {
},
themeSwitch: {
component: ThemeSwitch,
- useOptions() {
- const { locale } = useRouter()
-
- if (locale === 'zh-CN') {
- return { dark: '深色主题', light: '浅色主题', system: '系统默认' }
- }
- return { dark: 'Dark', light: 'Light', system: 'System' }
- }
+ useOptions: { dark: 'Dark', light: 'Light', system: 'System' }
},
toc: {
- backToTop: true,
+ backToTop: 'Scroll to top',
component: TOC,
float: true,
title: 'On This Page'
diff --git a/packages/nextra-theme-docs/src/schemas.ts b/packages/nextra-theme-docs/src/schemas.ts
index 327cb698f3d..eccf8779a2f 100644
--- a/packages/nextra-theme-docs/src/schemas.ts
+++ b/packages/nextra-theme-docs/src/schemas.ts
@@ -126,7 +126,7 @@ export const themeSchema = /* @__PURE__ */ (() =>
)
}),
toc: z.strictObject({
- backToTop: z.boolean(),
+ backToTop: z.custom(...reactNode),
component: z.custom>(...reactNode),
extraContent: z.custom(...reactNode),
float: z.boolean(),