fix: update Chinese translations and enhance blocks navigation

- Updated Chinese translations in zh.json to include spaces between words and components for improved readability.
- Enhanced BlocksNav component to correctly handle locale from URL parameters, ensuring accurate navigation across different locales.
- Commented out unused imports in blocks.ts for clarity and to prevent confusion.
This commit is contained in:
javayhu 2025-03-26 00:27:19 +08:00
parent 87bb54b7c5
commit 91b2bdb4ac
4 changed files with 44 additions and 20 deletions

View File

@ -220,49 +220,49 @@
"title": "内置组件",
"items": {
"hero": {
"title": "Hero组件"
"title": "Hero 组件"
},
"logoCloud": {
"title": "Logo Cloud组件"
"title": "Logo Cloud 组件"
},
"features": {
"title": "Features组件"
"title": "Features 组件"
},
"content": {
"title": "Content组件"
"title": "Content 组件"
},
"stats": {
"title": "Stats组件"
"title": "Stats 组件"
},
"team": {
"title": "Team组件"
"title": "Team 组件"
},
"testimonials": {
"title": "Testimonials组件"
"title": "Testimonials 组件"
},
"callToAction": {
"title": "Call to Action组件"
"title": "Call to Action 组件"
},
"footer": {
"title": "Footer组件"
"title": "Footer 组件"
},
"pricing": {
"title": "Pricing组件"
"title": "Pricing 组件"
},
"comparator": {
"title": "Comparator组件"
"title": "Comparator 组件"
},
"faqs": {
"title": "FAQs组件"
"title": "FAQs 组件"
},
"login": {
"title": "Login组件"
"title": "Login 组件"
},
"signup": {
"title": "Signup组件"
"title": "Signup 组件"
},
"contact": {
"title": "Contact组件"
"title": "Contact 组件"
}
}
}

View File

@ -2,6 +2,13 @@ import { categories } from '@/components/blocks/blocks';
import BlocksNav from '@/components/blocks/blocks-nav';
import { PropsWithChildren } from 'react';
/**
* TODO: bug to fix
*
* when in zh locale, click blocks nav will redirect to /zh/blocks/logo
* but the navbar is not updated with the new locale
*
*/
export default function CategoryLayout({ children }: PropsWithChildren) {
return (
<>

View File

@ -2,10 +2,25 @@
import { LocaleLink, useLocalePathname } from '@/i18n/navigation';
import { cn } from '@/lib/utils';
import { useLocale } from 'next-intl';
import { routing } from '@/i18n/routing';
import { useParams } from 'next/navigation';
export default function BlocksNav({ categories }: { categories: string[] }) {
const pathname = useLocalePathname();
const params = useParams();
// Get locale from URL params, which should be more reliable than useLocale in this case
const urlLocale = params.locale as string;
// Fallback to useLocale if params.locale is not available
const defaultLocale = useLocale();
const locale = urlLocale || defaultLocale;
console.log("pathname", pathname);
console.log("locale from params", urlLocale);
console.log("locale from hook", defaultLocale);
return (
<div className="mt-4 dark:border-border/50 relative z-20 border-t">
<div className="mx-auto max-w-7xl">
@ -13,7 +28,9 @@ export default function BlocksNav({ categories }: { categories: string[] }) {
<ul className="relative -mb-px flex h-12 snap-x snap-proximity scroll-px-6 items-center gap-6 overflow-x-auto overflow-y-hidden px-6 lg:scroll-px-2 lg:gap-5">
{categories.map((category) => {
const href = `/blocks/${category}`;
const isActive = pathname.startsWith(href);
// Check if the current pathname ends with our href or contains it as a path segment
// This works with locale prefixes since useLocalePathname already returns the path without the locale prefix
const isActive = pathname === href || pathname.startsWith(`${href}/`);
return (
<li
@ -25,7 +42,7 @@ export default function BlocksNav({ categories }: { categories: string[] }) {
>
<LocaleLink
href={href}
prefetch={true}
locale={locale}
className={cn(
isActive && 'text-foreground!',
'hover:bg-muted dark:text-muted-foreground hover:text-foreground flex h-7 w-fit items-center text-nowrap rounded-full px-2 text-sm text-zinc-700 lg:-mx-2 lg:px-3'

View File

@ -1,5 +1,5 @@
import fs from 'fs';
import path from 'path';
// import fs from 'fs';
// import path from 'path';
export interface Block {
slug: string;