-
-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: first version of chinese docs (#1102)
* 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
Showing
45 changed files
with
517 additions
and
43 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
72 changes: 72 additions & 0 deletions
72
docs_src/src/components/documentation/LanguageSelector.jsx
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,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 |
Oops, something went wrong.