📝Update breadcrumbs i18n
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Breadcrumbs } from '@/components/layout/Breadcrumbs'
|
||||
import { getPostBySlug } from '@/lib/markdown'
|
||||
import { getTranslations } from 'next-intl/server'
|
||||
|
||||
interface BreadcrumbItem {
|
||||
label: string
|
||||
@@ -7,28 +8,19 @@ interface BreadcrumbItem {
|
||||
current?: boolean
|
||||
}
|
||||
|
||||
function formatDirectoryName(name: string): string {
|
||||
const directoryNames: { [key: string]: string } = {
|
||||
tech: 'Tehnologie',
|
||||
design: 'Design',
|
||||
tutorial: 'Tutoriale',
|
||||
}
|
||||
|
||||
return directoryNames[name] || name.charAt(0).toUpperCase() + name.slice(1)
|
||||
}
|
||||
|
||||
export default async function BlogPostBreadcrumb({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ slug: string[] }>
|
||||
}) {
|
||||
const t = await getTranslations('Breadcrumbs')
|
||||
const { slug } = await params
|
||||
const slugPath = slug.join('/')
|
||||
const post = await getPostBySlug(slugPath)
|
||||
|
||||
const items: BreadcrumbItem[] = [
|
||||
{
|
||||
label: 'Blog',
|
||||
label: t('blog'),
|
||||
href: '/blog',
|
||||
},
|
||||
]
|
||||
@@ -36,8 +28,9 @@ export default async function BlogPostBreadcrumb({
|
||||
if (slug.length > 1) {
|
||||
for (let i = 0; i < slug.length - 1; i++) {
|
||||
const segmentPath = slug.slice(0, i + 1).join('/')
|
||||
const dirName = slug[i]
|
||||
items.push({
|
||||
label: formatDirectoryName(slug[i]),
|
||||
label: t(dirName) || dirName.charAt(0).toUpperCase() + dirName.slice(1),
|
||||
href: `/blog/${segmentPath}`,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
'use client'
|
||||
|
||||
import { Breadcrumbs } from '@/components/layout/Breadcrumbs'
|
||||
import { useTranslations } from 'next-intl'
|
||||
|
||||
export default function BlogBreadcrumb() {
|
||||
const t = useTranslations('Breadcrumbs')
|
||||
|
||||
return (
|
||||
<Breadcrumbs
|
||||
items={[
|
||||
{
|
||||
label: 'Blog',
|
||||
label: t('blog'),
|
||||
href: '/blog',
|
||||
current: true,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user