Skip to content
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

docs: first version of chinese docs #1102

Merged
merged 6 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs_src/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ const nextConfig = {
experimental: {
scrollRestoration: true,
},
i18n: {
locales: ['en', 'zh'],
defaultLocale: 'en',
localeDetection: false,
},
async redirects() {
return [
{
source: '/documentation',
destination: '/documentation/en',
permanent: false,
},
]
},
}

export default withMDX(nextConfig)
72 changes: 72 additions & 0 deletions docs_src/src/components/documentation/LanguageSelector.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { useRouter } from 'next/router'
import { Menu } from '@headlessui/react'
import { motion } from 'framer-motion'

const languages = [
{ code: 'en', name: 'English' },
{ code: 'zh', name: '中文' },
]

function LanguageSelector() {
const router = useRouter()
const { pathname, asPath, query } = router
const currentLanguage = asPath.includes('/zh') ? 'zh' : 'en'

const changeLanguage = (locale) => {
const currentPath = asPath.split('?')[0]

if (currentPath === '/documentation' || currentPath === '/documentation/') {
router.push(`/documentation/${locale}`)
return
}

const newPath = currentPath.replace(
/\/documentation\/(en|zh)/,
`/documentation/${locale}`
)

router.push(newPath)
}

return (
<Menu as="div" className="relative">
<Menu.Button className="flex items-center gap-2 rounded-lg bg-zinc-800/40 px-3 py-2 text-sm text-white hover:bg-zinc-800 transition-colors duration-200">
{languages.find(l => l.code === currentLanguage)?.name}
<svg
width="8"
height="5"
className="ml-1 stroke-current"
fill="none"
viewBox="0 0 8 5"
>
<path d="M1 1L4 4L7 1" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
</svg>
</Menu.Button>
<Menu.Items as={motion.div}
initial={{ y: -10 }}
animate={{ y: 0 }}
exit={{ y: -10 }}
className="absolute left-0 mt-1 w-40 origin-top-left rounded-lg bg-[#27272A] ring-1 ring-zinc-700 shadow-xl z-50"
>
{languages.map((language) => (
<Menu.Item key={language.code}>
{({ active }) => (
<button
onClick={() => changeLanguage(language.code)}
className={`${
active ? 'bg-zinc-700/50' : ''
} ${
currentLanguage === language.code ? 'bg-orange-500/10 text-orange-500' : 'text-zinc-100'
} group flex w-full items-center gap-2 rounded-md px-3 py-2.5 text-sm transition-colors duration-200`}
>
{language.name}
</button>
)}
</Menu.Item>
))}
</Menu.Items>
</Menu>
)
}

export default LanguageSelector
Loading
Loading