From ffe934864087a3721996fb424ab2a153e292feaf Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Wed, 17 Dec 2025 10:57:09 +0330 Subject: [PATCH] translate text checkout --- .../[id]/components/PaymentSection.tsx | 15 ++++++--- .../[id]/components/ShippingSection.tsx | 12 +++++-- src/locales/fa/orders.json | 31 +++++++++++++------ 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/app/[name]/(Dialogs)/order/checkout/[id]/components/PaymentSection.tsx b/src/app/[name]/(Dialogs)/order/checkout/[id]/components/PaymentSection.tsx index 1c6bb91..131b783 100644 --- a/src/app/[name]/(Dialogs)/order/checkout/[id]/components/PaymentSection.tsx +++ b/src/app/[name]/(Dialogs)/order/checkout/[id]/components/PaymentSection.tsx @@ -24,11 +24,18 @@ const getIconByMethod = (method: "CardOnDelivery" | "Cash" | "Online", _gateway: export const PaymentSection = ({ paymentType, onPaymentTypeChange }: PaymentSectionProps) => { - const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' }); + const { t: tOrderDetail } = useTranslation('parallels', { keyPrefix: 'OrderDetail' }); + const { t: tOrders } = useTranslation('orders'); const { data: paymentMethod } = useGetPaymentMethod(); const { mutate: setPaymentMethod } = useSetPaymentMethod(); const { setIsSelectedPayment } = useCheckoutStore(); + const getPaymentMethodTranslation = (method: string, fallbackTitle: string) => { + const translationKey = `paymentMethod.${method}`; + const translation = tOrders(translationKey); + return translation !== translationKey ? translation : fallbackTitle; + }; + const paymentOptions = useMemo(() => { if (!paymentMethod?.data) return []; @@ -37,15 +44,15 @@ export const PaymentSection = ({ paymentType, onPaymentTypeChange }: PaymentSect .sort((a, b) => a.order - b.order) .map(item => ({ id: item.id, - label: item.title, + label: getPaymentMethodTranslation(item.method, item.title), icon: getIconByMethod(item.method, item.gateway), })); - }, [paymentMethod]); + }, [paymentMethod, tOrders]); return (
-

{t("SectionPayment.Title")}

+

{tOrderDetail("SectionPayment.Title")}

{paymentOptions.map(({ id, label, icon: Icon }) => ( diff --git a/src/app/[name]/(Dialogs)/order/checkout/[id]/components/ShippingSection.tsx b/src/app/[name]/(Dialogs)/order/checkout/[id]/components/ShippingSection.tsx index 508e989..f4bca96 100644 --- a/src/app/[name]/(Dialogs)/order/checkout/[id]/components/ShippingSection.tsx +++ b/src/app/[name]/(Dialogs)/order/checkout/[id]/components/ShippingSection.tsx @@ -14,24 +14,30 @@ type ShippingSectionProps = { export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: ShippingSectionProps) => { - const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' }); + const { t: tOrderDetail } = useTranslation('parallels', { keyPrefix: 'OrderDetail' }); + const { t: tOrders } = useTranslation('orders'); const { data: shipmentMethod } = useGetShipmentMethod(); const { mutate: setDeliveryMethod } = useSetDeliveryMethod(); const { setIsSelectedShipment } = useCheckoutStore(); + const getDeliveryMethodTranslation = (method: string) => { + const translationKey = method === 'pickup' ? 'customerPickup' : method; + return tOrders(`deliveryMethod.${translationKey}`); + }; + const options = shipmentMethod?.data .filter((item: DeliveryMethod) => item.enabled) .sort((a: DeliveryMethod, b: DeliveryMethod) => a.order - b.order) .map((item: DeliveryMethod) => ({ id: item.id, - title: item.title, + title: getDeliveryMethodTranslation(item.method), icon: Box })) || []; return (
-

{t("SectionShipping.Title")}

+

{tOrderDetail("SectionShipping.Title")}