mirror of
https://github.com/dong-nz/cv.git
synced 2026-11-22 16:10:40 +07:00
support multi languages
This commit is contained in:
1 parent
ca8ff2f983
commit
72a832c781
24 files changed
+995
-175
No files matched your search
@@ -1,19 +1,13 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { Link, useLocation } from 'react-router'
|
||||
import { useTheme } from '@/hooks/useTheme'
|
||||
import { useLanguage } from '@/hooks/useLanguage'
|
||||
import { strings } from '@/i18n/strings'
|
||||
import { RollingTextLink } from '@/components/ui/RollingTextLink'
|
||||
|
||||
const navItems = [
|
||||
{ label: 'Home', path: '/' },
|
||||
{ label: 'About', path: '/about' },
|
||||
{ label: 'Experience', path: '/experience' },
|
||||
{ label: 'Projects', path: '/projects' },
|
||||
{ label: 'Engineering', path: '/engineering' },
|
||||
{ label: 'Contact', path: '/contact' },
|
||||
]
|
||||
|
||||
const navPaths = ['/', '/about', '/experience', '/projects', '/engineering', '/contact'] as const
|
||||
export function Navigation() {
|
||||
const { cycleTheme, resolvedTheme } = useTheme()
|
||||
const { lang, toggleLang } = useLanguage()
|
||||
const [mobileOpen, setMobileOpen] = useState(false)
|
||||
const location = useLocation()
|
||||
|
||||
@@ -43,16 +37,20 @@ export function Navigation() {
|
||||
</Link>
|
||||
|
||||
<ul className="nav-menu">
|
||||
{navItems.map((item) => (
|
||||
<li key={item.path}>
|
||||
<RollingTextLink
|
||||
to={item.path}
|
||||
className={item.path === location.pathname ? 'nav-link active' : 'nav-link'}
|
||||
>
|
||||
{item.label}
|
||||
</RollingTextLink>
|
||||
</li>
|
||||
))}
|
||||
{navPaths.map((path) => {
|
||||
const navKey = path === '/' ? 'home' : path.replace('/', '') as keyof typeof strings.nav
|
||||
const label = strings.nav[navKey][lang]
|
||||
return (
|
||||
<li key={path}>
|
||||
<RollingTextLink
|
||||
to={path}
|
||||
className={path === location.pathname ? 'nav-link active' : 'nav-link'}
|
||||
>
|
||||
{label}
|
||||
</RollingTextLink>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
|
||||
<div className="nav-actions">
|
||||
@@ -74,6 +72,14 @@ export function Navigation() {
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
className="lang-toggle"
|
||||
onClick={toggleLang}
|
||||
aria-label="Switch language"
|
||||
title={`Switch to ${lang === 'en' ? 'Tiếng Việt' : 'English'}`}
|
||||
>
|
||||
{lang === 'en' ? 'VI' : 'EN'}
|
||||
</button>
|
||||
<button
|
||||
className="mobile-menu-btn"
|
||||
onClick={() => setMobileOpen(!mobileOpen)}
|
||||
@@ -96,17 +102,21 @@ export function Navigation() {
|
||||
|
||||
<div className={`mobile-menu ${mobileOpen ? 'open' : ''}`} role="dialog" aria-label="Mobile navigation">
|
||||
<ul className="mobile-menu-list">
|
||||
{navItems.map((item) => (
|
||||
<li key={item.path}>
|
||||
<RollingTextLink
|
||||
to={item.path}
|
||||
className={item.path === location.pathname ? 'mobile-menu-link active' : 'mobile-menu-link'}
|
||||
onClick={() => setMobileOpen(false)}
|
||||
>
|
||||
{item.label}
|
||||
</RollingTextLink>
|
||||
</li>
|
||||
))}
|
||||
{navPaths.map((path) => {
|
||||
const navKey = path === '/' ? 'home' : path.replace('/', '') as keyof typeof strings.nav
|
||||
const label = strings.nav[navKey][lang]
|
||||
return (
|
||||
<li key={path}>
|
||||
<RollingTextLink
|
||||
to={path}
|
||||
className={path === location.pathname ? 'mobile-menu-link active' : 'mobile-menu-link'}
|
||||
onClick={() => setMobileOpen(false)}
|
||||
>
|
||||
{label}
|
||||
</RollingTextLink>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
</>
|
||||
|
||||
Reference in new issue
Block a user