Skip to content

Commit

Permalink
docs: first version of chinese docs (#1102)
Browse files Browse the repository at this point in the history
* docs: first version of chinese docs

* fix minor ui bug

* fix folder structure

* add more docs

* add more translation

* add more translation
  • Loading branch information
sansyrox authored Jan 12, 2025
1 parent 46d6521 commit c623930
Show file tree
Hide file tree
Showing 45 changed files with 517 additions and 43 deletions.
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

0 comments on commit c623930

Please sign in to comment.