From 5e91dd3cfd26412c395b76d08612440cb8427bec Mon Sep 17 00:00:00 2001 From: ChingCdesu Date: Tue, 4 Feb 2025 23:29:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=89=A9=E4=BD=99?= =?UTF-8?q?=E6=97=B6=E9=95=BF=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- messages/en.json | 3 ++- messages/zh.json | 1 + src/app/[locale]/show-key/page.tsx | 12 ++++++++++-- src/i18n/routing.ts | 2 ++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/messages/en.json b/messages/en.json index b46d060..2377a4b 100644 --- a/messages/en.json +++ b/messages/en.json @@ -18,7 +18,8 @@ "yourKey": "Your CDKey", "invalidOrderId": "Order does not exist", "orderExpired": "CDKey has expired", - "expireAt": "Valid for {time}", + "expireAt": "Valid until {time}", + "timeLeft": "{relativeTime} remain", "goBack": "Go Back", "msg": { "Order not found": "Order does not exist" diff --git a/messages/zh.json b/messages/zh.json index b50bb2b..17ed68f 100644 --- a/messages/zh.json +++ b/messages/zh.json @@ -19,6 +19,7 @@ "invalidOrderId": "订单不存在哦", "orderExpired": "CDKey已过期", "expireAt": "在 {time} 内可用", + "timeLeft": "剩余 {relativeTime}", "goBack": "返回", "msg": { "Order not found": "订单不存在哦" diff --git a/src/app/[locale]/show-key/page.tsx b/src/app/[locale]/show-key/page.tsx index ef59995..2674e8a 100644 --- a/src/app/[locale]/show-key/page.tsx +++ b/src/app/[locale]/show-key/page.tsx @@ -1,5 +1,5 @@ import { BackgroundLines } from "@/components/BackgroundLines" -import { getTranslations, getFormatter } from "next-intl/server" +import { getTranslations, getFormatter, getLocale } from "next-intl/server" import moment from "moment" import CopyButton from "@/components/CopyButton" @@ -11,6 +11,7 @@ type Props = { export default async function ShowKey({ searchParams }: Props) { const t = await getTranslations('ShowKey') + const locale = await getLocale() const format = await getFormatter() const { order_id } = await searchParams const response = await fetch(`https://mirrorc.top/api/billing/order/afdian?order_id=${order_id}`) @@ -27,6 +28,10 @@ export default async function ShowKey({ searchParams }: Props) { minute: 'numeric', }) : null + moment.locale(locale) + + const relativeTime = isSuccessful ? moment.duration(moment(data.expired_at).diff(moment())).humanize() : null + return isSuccessful && !isExpired ? (
@@ -39,7 +44,10 @@ export default async function ShowKey({ searchParams }: Props) {

{t('yourKey')}: 

-

{t('expireAt', { time })}

+

+ {t('expireAt', { time })} + ({t('timeLeft', { relativeTime })}) +

diff --git a/src/i18n/routing.ts b/src/i18n/routing.ts index cbd14f8..fa2419e 100644 --- a/src/i18n/routing.ts +++ b/src/i18n/routing.ts @@ -1,6 +1,8 @@ import { defineRouting } from 'next-intl/routing'; import { createNavigation } from 'next-intl/navigation'; +import 'moment/locale/zh-cn' + export const routing = defineRouting({ // A list of all locales that are supported locales: ['en', 'zh'],