filteredPosts page internationalization added

This commit is contained in:
parsa aghaei 2024-10-21 11:37:38 +03:30
parent c3f7fc5d2b
commit c11764a4c0
6 changed files with 61 additions and 12 deletions

View File

@ -44,7 +44,7 @@ export default async function Header() {
<Button <Button
color={"purple"} color={"purple"}
text={dict.blog.header.button} text={dict.blog.header.button}
className="!px-4 !py-1 sm:flex sm:!px-5 sm:!py-2" className="!px-4 !py-1 sm:flex sm:!px-5 sm:!py-2 capitalize"
/> />
<BurgerButton /> <BurgerButton />
</div> </div>

View File

@ -1,6 +1,7 @@
// components/Pagination.tsx // components/Pagination.tsx
"use client"; "use client";
import { Dictionary } from "@/app/types/types";
import Link from "next/link"; import Link from "next/link";
import { useSearchParams } from "next/navigation"; import { useSearchParams } from "next/navigation";
import React from "react"; import React from "react";
@ -14,9 +15,10 @@ interface Meta {
interface PaginationProps { interface PaginationProps {
meta: Meta; meta: Meta;
baseUrl: string; // اضافه کردن prop برای base URL baseUrl: string; // اضافه کردن prop برای base URL
dict: Dictionary;
} }
const Pagination: React.FC<PaginationProps> = ({ meta, baseUrl }) => { const Pagination: React.FC<PaginationProps> = ({ meta, baseUrl, dict }) => {
const { current_page, last_page, total } = meta; const { current_page, last_page, total } = meta;
const searchParams = useSearchParams(); const searchParams = useSearchParams();
@ -100,7 +102,7 @@ const Pagination: React.FC<PaginationProps> = ({ meta, baseUrl }) => {
className="rounded-full border bg-[#EAEAEA] px-3 py-1 text-blog-text-default hover:bg-[#d6d6d6]" className="rounded-full border bg-[#EAEAEA] px-3 py-1 text-blog-text-default hover:bg-[#d6d6d6]"
aria-label="First Page" aria-label="First Page"
> >
First {dict.blog.pagination.first}
</Link> </Link>
)} )}
@ -133,7 +135,7 @@ const Pagination: React.FC<PaginationProps> = ({ meta, baseUrl }) => {
className="rounded-full border bg-[#EAEAEA] px-3 py-1 text-blog-text-default hover:bg-[#d6d6d6]" className="rounded-full border bg-[#EAEAEA] px-3 py-1 text-blog-text-default hover:bg-[#d6d6d6]"
aria-label="Last Page" aria-label="Last Page"
> >
Last {dict.blog.pagination.last}
</Link> </Link>
)} )}
</div> </div>

View File

@ -8,6 +8,8 @@ import Link from "next/link";
import NoDataFounded from "../../components/no-data-founded/noDataFounded"; import NoDataFounded from "../../components/no-data-founded/noDataFounded";
import Pagination from "../../components/pagination/pagination"; import Pagination from "../../components/pagination/pagination";
import { Metadata } from "next"; import { Metadata } from "next";
import { getDictionary } from "@/app/lib/functions/dictionaries";
import { getDefaultLocale } from "@/app/lib/functions/utils";
export const metadata: Metadata = { export const metadata: Metadata = {
title: "", title: "",
@ -15,7 +17,9 @@ export const metadata: Metadata = {
openGraph: { openGraph: {
title: "", title: "",
description: "", description: "",
images: [`${process.env.NEXT_PUBLIC_FRONT_URL}/og-image?text=filtered posts`], images: [
`${process.env.NEXT_PUBLIC_FRONT_URL}/og-image?text=filtered posts`,
],
}, },
}; };
@ -25,6 +29,8 @@ export default async function FilteredPosts({
}: FilteredPostsPagepropsType) { }: FilteredPostsPagepropsType) {
let filteredPostApiUrl: string; let filteredPostApiUrl: string;
const dict = await getDictionary(getDefaultLocale());
switch (params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase()) { switch (params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase()) {
case "new": case "new":
filteredPostApiUrl = "/posts?sort_field=published_at&sort_direction=desc"; filteredPostApiUrl = "/posts?sort_field=published_at&sort_direction=desc";
@ -95,14 +101,19 @@ export default async function FilteredPosts({
<div className="my-10 flex w-full max-w-[1280px] flex-wrap justify-center"> <div className="my-10 flex w-full max-w-[1280px] flex-wrap justify-center">
<div className="flex w-full max-w-[90%] flex-col gap-5"> <div className="flex w-full max-w-[90%] flex-col gap-5">
<h1 className="text-[36px] font-[700] capitalize text-blog-text-default"> <h1 className="text-[36px] font-[700] capitalize text-blog-text-default">
{params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase()} {params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase() === "new"
? dict.blog.filteredPostsPage.newTitle
: params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase() ===
"popular"
? dict.blog.filteredPostsPage.popularTitle
: ""}
</h1> </h1>
<p className="text-[18px] font-[600] text-blog-text-default"> <p className="text-[18px] font-[600] text-blog-text-default">
{params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase() === "new" {params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase() === "new"
? "Explore the latest posts on our blog. Stay updated with fresh content, insightful articles, and the most recent discussions in your areas of interest." ? dict.blog.filteredPostsPage.newDescription
: params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase() === : params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase() ===
"popular" "popular"
? "Discover the most popular posts with the highest views. These articles have resonated with our audience and are trending across various topics." ? dict.blog.filteredPostsPage.popularDescription
: ""} : ""}
</p> </p>
</div> </div>
@ -113,7 +124,7 @@ export default async function FilteredPosts({
href={"/blog"} href={"/blog"}
className="text-[12px] font-[400] capitalize text-blog-text-passive hover:underline" className="text-[12px] font-[400] capitalize text-blog-text-passive hover:underline"
> >
Home {dict.blog.header.Home}
</Link> </Link>
<span className="mt-[-2px] -rotate-45 scale-[3] select-none text-[12px] font-[400] text-blog-text-passive"> <span className="mt-[-2px] -rotate-45 scale-[3] select-none text-[12px] font-[400] text-blog-text-passive">
- -
@ -121,7 +132,12 @@ export default async function FilteredPosts({
</li> </li>
<li className="flex items-center gap-2"> <li className="flex items-center gap-2">
<p className="relative text-[12px] font-[600] capitalize text-blog-text-default"> <p className="relative text-[12px] font-[600] capitalize text-blog-text-default">
{params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase()} {params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase() === "new"
? dict.blog.filteredPostsPage.newTitle
: params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase() ===
"popular"
? dict.blog.filteredPostsPage.popularTitle
: ""}
<span className="absolute -end-6 -top-2 flex h-5 w-5 items-center justify-center rounded-full bg-blog-red"> <span className="absolute -end-6 -top-2 flex h-5 w-5 items-center justify-center rounded-full bg-blog-red">
{FilteredPostsData.meta.total} {FilteredPostsData.meta.total}
@ -148,7 +164,7 @@ export default async function FilteredPosts({
<div className="flex w-full flex-wrap gap-2"> <div className="flex w-full flex-wrap gap-2">
<div className="flex gap-2"> <div className="flex gap-2">
<p className="text-[14px] font-[600] text-blog-text-passive md:text-[16px]"> <p className="text-[14px] font-[600] text-blog-text-passive md:text-[16px]">
BY {dict.blog.homePage.by}
</p> </p>
<Link <Link
href={"/"} href={"/"}
@ -159,7 +175,7 @@ export default async function FilteredPosts({
</div> </div>
<div className="whit flex gap-2"> <div className="whit flex gap-2">
<p className="text-[16px] font-[600] text-blog-text-passive"> <p className="text-[16px] font-[600] text-blog-text-passive">
IN {dict.blog.homePage.in}
</p> </p>
<Link <Link
href={`/blog/categories/${post.category.slug}`} href={`/blog/categories/${post.category.slug}`}
@ -189,6 +205,7 @@ export default async function FilteredPosts({
<Pagination <Pagination
meta={FilteredPostsData.meta} meta={FilteredPostsData.meta}
baseUrl={`/blog/filtered-posts/${params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase()}`} baseUrl={`/blog/filtered-posts/${params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase()}`}
dict={dict}
/> />
)} )}
</div> </div>

View File

@ -61,6 +61,12 @@
"by": "BY", "by": "BY",
"in": "IN" "in": "IN"
}, },
"filteredPostsPage": {
"newTitle": "new",
"popularTitle": "popular",
"newDescription": "Explore the latest posts on our blog. Stay updated with fresh content, insightful articles, and the most recent discussions in your areas of interest.",
"popularDescription": "Discover the most popular posts with the highest views. These articles have resonated with our audience and are trending across various topics."
},
"header": { "header": {
"Home": "Home", "Home": "Home",
"New": "New", "New": "New",
@ -72,6 +78,10 @@
"Name": "parsa aghayi", "Name": "parsa aghayi",
"Year": "© 2024", "Year": "© 2024",
"CopyRight": "All Rights Reserved , Inc." "CopyRight": "All Rights Reserved , Inc."
},
"pagination": {
"first": "first",
"last": "last"
} }
} }
} }

View File

@ -61,6 +61,12 @@
"by": "نوشته‌شده توسط", "by": "نوشته‌شده توسط",
"in": "در دسته" "in": "در دسته"
}, },
"filteredPostsPage": {
"newTitle": "جدیدترین‌ها",
"popularTitle": "محبوب‌ترین‌ها",
"newDescription": "آخرین پست های وبلاگ ما را کاوش کنید. با مطالب جدید، مقالات روشنگر و جدیدترین بحث ها در زمینه های مورد علاقه خود به روز باشید.",
"popularDescription": "محبوب ترین پست ها را با بیشترین بازدید کشف کنید. این مقالات با مخاطبان ما طنین انداز شده اند و در موضوعات مختلف در حال ترند هستند."
},
"header": { "header": {
"Home": "خانه", "Home": "خانه",
"New": "جدیدترین‌ها", "New": "جدیدترین‌ها",
@ -72,6 +78,10 @@
"Name": "پارسا آقایی", "Name": "پارسا آقایی",
"Year": "© ۱۴۰۳", "Year": "© ۱۴۰۳",
"CopyRight": "تمامی حقوق محفوظ برای" "CopyRight": "تمامی حقوق محفوظ برای"
},
"pagination": {
"first": "اولین",
"last": "آخرین"
} }
} }
} }

View File

@ -181,6 +181,12 @@ export type Dictionary = {
by: string; by: string;
in: string; in: string;
}; };
filteredPostsPage: {
newTitle: string;
popularTitle: string;
newDescription: string;
popularDescription: string;
};
header: { header: {
Home: string; Home: string;
New: string; New: string;
@ -193,6 +199,10 @@ export type Dictionary = {
Year: string; Year: string;
CopyRight: string; CopyRight: string;
}; };
pagination: {
first: string;
last: string;
};
}; };
}; };