diff --git a/src/components/Layout/TopNav/TopNav.tsx b/src/components/Layout/TopNav/TopNav.tsx index 37c2768a667..dc090511ff7 100644 --- a/src/components/Layout/TopNav/TopNav.tsx +++ b/src/components/Layout/TopNav/TopNav.tsx @@ -169,6 +169,12 @@ export default function TopNav({ const [isScrolled, setIsScrolled] = useState(false); const scrollParentRef = useRef(null); const {asPath} = useRouter(); + const translationsHref = + section === 'learn' || section === 'reference' + ? `/community/translations?from=${encodeURIComponent( + asPath.split(/[?#]/)[0] + )}` + : '/community/translations'; // HACK. Fix up the data structures instead. if ((routeTree as any).routes.length === 1) { @@ -378,7 +384,7 @@ export default function TopNav({
{languageIcon} diff --git a/src/components/MDX/MDXComponents.tsx b/src/components/MDX/MDXComponents.tsx index 5dc177a04cd..ac34f24d252 100644 --- a/src/components/MDX/MDXComponents.tsx +++ b/src/components/MDX/MDXComponents.tsx @@ -12,6 +12,7 @@ import {Children, useContext, useMemo} from 'react'; import * as React from 'react'; import cn from 'classnames'; +import {useRouter} from 'next/router'; import type {HTMLAttributes} from 'react'; import CodeBlock from './CodeBlock'; @@ -469,6 +470,9 @@ function InlineTocItem({items}: {items: Array}) { type TranslationProgress = 'complete' | 'in-progress'; function LanguageList({progress}: {progress: TranslationProgress}) { + const from = useRouter().query.from; + const pathname = + typeof from === 'string' && /^\/(?!\/)[^\\?#]*$/.test(from) ? from : ''; const allLanguages = React.useContext(LanguagesContext) ?? []; const languages = allLanguages .filter( @@ -484,7 +488,10 @@ function LanguageList({progress}: {progress: TranslationProgress}) { {languages.map(({code, name, enName}) => { return (
  • - + {enName} ({name}) {' '} —{' '}