diff --git a/src/components/AlgoViz.tsx b/src/components/AlgoViz.tsx index 4f73293..ee887d5 100644 --- a/src/components/AlgoViz.tsx +++ b/src/components/AlgoViz.tsx @@ -5,6 +5,8 @@ import { getAlgorithmDescription, getAlgorithmMetaTitle, getAlgorithmMetaDescription, + defaultLocale, + locales, } from '@i18n/translations' import { algorithms, categories } from '@lib/algorithms' import { usePlayback } from '@hooks/usePlayback' @@ -26,13 +28,16 @@ const COLLAPSE_THRESHOLD = 100 const MOBILE_BREAKPOINT = 768 function getAlgorithmUrl(locale: string, algoId: string): string { - return locale === 'es' ? `/es/${algoId}` : `/${algoId}` + return locale === defaultLocale ? `/${algoId}` : `/${locale}/${algoId}` } function getAlgorithmIdFromPath(pathname: string): string | null { const cleaned = pathname.replace(/\/$/, '') - if (cleaned === '' || cleaned === '/es') return null - if (cleaned.startsWith('/es/')) return cleaned.slice(4) + if (cleaned === '') return null + for (const locale of locales) { + if (cleaned === `/${locale}`) return null + if (cleaned.startsWith(`/${locale}/`)) return cleaned.slice(locale.length + 2) + } return cleaned.slice(1) } @@ -249,7 +254,7 @@ export default function AlgoViz({ locale = 'en', initialAlgorithmId }: AlgoVizPr style={{ width: sidebar.isDragging ? sidebar.width : sidebar.collapsed ? 0 : SIDEBAR_MAX, }} - aria-label={locale === 'es' ? 'Categorías de algoritmos' : 'Algorithm categories'} + aria-label={t.sidebarAriaLabel} aria-hidden={sidebar.collapsed} inert={sidebar.collapsed || undefined} > @@ -314,19 +319,19 @@ export default function AlgoViz({ locale = 'en', initialAlgorithmId }: AlgoVizPr className={`fixed top-0 left-0 bottom-0 w-[280px] bg-black z-50 border-r border-white/8 transition-transform duration-300 ease-in-out ${ mobileSidebarOpen ? 'translate-x-0' : '-translate-x-full' }`} - aria-label={locale === 'es' ? 'Categorías de algoritmos' : 'Algorithm categories'} + aria-label={t.sidebarAriaLabel} aria-hidden={!mobileSidebarOpen} inert={!mobileSidebarOpen || undefined} >
- {locale === 'es' ? 'Algoritmos' : 'Algorithms'} + {t.mobileMenuTitle} ) : sidebarCollapsed ? ( @@ -129,7 +140,10 @@ export default function Header({ )} {selectedAlgorithm && ( -