Skip to content

Let's use AI to Earn!

feat(热点): 热点事件、侧边栏、标签组件国际化处理

gaoSir0e2a48bd63a3
diff --git a/@types/resources.d.ts b/@types/resources.d.ts
index a8fb59d4..fb3dfa3e 100644
--- a/@types/resources.d.ts
+++ b/@types/resources.d.ts
@@ -730,7 +730,15 @@ interface Resources {
"daily": "按日",
"sortRule": "排序规则",
"sortRuleDesc": "统计当日点赞量前500名的作品推荐",
- "dataDescription": "数据说明"
+ "dataDescription": "数据说明",
+ "expand": "展开",
+ "collapse": "收起",
+ "hotValue": "热度值",
+ "hotTrend": "热度趋势",
+ "shortDrama": "短剧",
+ "cultureTourism": "文旅",
+ "contentOverseas": "内容出海",
+ "hot": "热点"
},
"income": {
"title": "我的收入",
diff --git a/src/app/[lng]/hotContent/components/HotContentLabel/index.tsx b/src/app/[lng]/hotContent/components/HotContentLabel/index.tsx
index 9f1270cb..fae79270 100644
--- a/src/app/[lng]/hotContent/components/HotContentLabel/index.tsx
+++ b/src/app/[lng]/hotContent/components/HotContentLabel/index.tsx
@@ -8,6 +8,7 @@ import {
CSSProperties,
} from "react";
import styles from "./hotContentLabel.module.scss";
+import { useTransClient } from "@/app/i18n/client";
export interface IHotContentLabelRef {}
@@ -30,6 +31,7 @@ const HotContentLabel = memo(
const [showToggle, setShowToggle] = useState(false);
const [collapsedHeight, setCollapsedHeight] = useState(0);
const [fullHeight, setFullHeight] = useState(0);
+ const { t } = useTransClient("hot-content");
useLayoutEffect(() => {
const ul = listRef.current;
@@ -83,7 +85,7 @@ const HotContentLabel = memo(
setExpanded((v) => !v);
}}
>
- {expanded ? "收起" : "展开"}
+ {expanded ? t("collapse") : t("expand")}
</a>
)}
</div>
diff --git a/src/app/[lng]/hotContent/components/HotContentSidebar/index.tsx b/src/app/[lng]/hotContent/components/HotContentSidebar/index.tsx
index f7ae1aeb..5f4f70e3 100644
--- a/src/app/[lng]/hotContent/components/HotContentSidebar/index.tsx
+++ b/src/app/[lng]/hotContent/components/HotContentSidebar/index.tsx
@@ -11,6 +11,7 @@ import HotTitleSvg from "../../svgs/hotTitle.svg";
import { HotType } from "@/app/[lng]/hotContent/hotContent.enum";
import { useShallow } from "zustand/react/shallow";
import { useHotContent } from "@/app/[lng]/hotContent/useHotContent";
+import { useTransClient } from "@/app/i18n/client";
type MenuItem = GetProp<MenuProps, "items">[number];
@@ -44,13 +45,14 @@ const HotContentSidebar = memo(
changeHotContentPlatform: state.changeHotContentPlatform,
})),
);
+ const { t } = useTransClient("hot-content");
const items = useMemo(() => {
const items: MenuItem[] = [
{
key: HotType.hotContent,
icon: <Icon component={HotContentSvg} />,
- label: <b>热门内容</b>,
+ label: <b>{t("hotContent")}</b>,
children: hotContentPlatformList.map((platform) => ({
key: `${HotType.hotContent}_${platform.id}`,
label: platform.name,
@@ -65,12 +67,12 @@ const HotContentSidebar = memo(
{
key: HotType.hotEvent,
icon: <Icon component={HotEventSvg} />,
- label: <b>热点事件</b>,
+ label: <b>{t("hotEvents")}</b>,
},
{
key: HotType.hotFeatures,
icon: <Icon component={HotFeaturesSvg} />,
- label: <b>热门专题</b>,
+ label: <b>{t("hotTopics")}</b>,
children: [
{
key: "AIGC",
@@ -78,22 +80,22 @@ const HotContentSidebar = memo(
},
{
key: "短剧",
- label: "短剧",
+ label: t("shortDrama"),
},
{
key: "文旅",
- label: "文旅",
+ label: t("cultureTourism"),
},
{
key: "内容出海",
- label: "内容出海",
+ label: t("contentOverseas"),
},
],
},
{
key: HotType.hotTitle,
icon: <Icon component={HotTitleSvg} />,
- label: <b>爆款标题</b>,
+ label: <b>{t("viralTitles")}</b>,
children: hotTitlePlatformList.map((platform) => ({
key: `${HotType.hotTitle}_${platform.id}`,
label: platform.name,
@@ -107,7 +109,7 @@ const HotContentSidebar = memo(
},
];
return items;
- }, [hotContentPlatformList, hotTitlePlatformList]);
+ }, [hotContentPlatformList, hotTitlePlatformList, t]);
useEffect(() => {
init();
diff --git a/src/app/[lng]/hotContent/components/HotEvent/index.tsx b/src/app/[lng]/hotContent/components/HotEvent/index.tsx
index 7ef00adf..b482585d 100644
--- a/src/app/[lng]/hotContent/components/HotEvent/index.tsx
+++ b/src/app/[lng]/hotContent/components/HotEvent/index.tsx
@@ -23,6 +23,7 @@ import { describeNumber } from "@/utils";
import hotContentStyles from "../HotContent/hotContent.module.scss";
import drawHotEventEchartLine from "@/app/[lng]/hotContent/components/HotEvent/echart/drawHotEventEchartLine";
import Uparrow from "../../svgs/uparrow.svg";
+import { useTransClient } from "@/app/i18n/client"; // 新增
const material = [
{
@@ -84,6 +85,7 @@ const HotEvent = memo(
}[]
>([]);
const [loading, setLoading] = useState(false);
+ const { t } = useTransClient("hot-content"); // 新增
const getData = useCallback(async () => {
setLoading(true);
@@ -96,86 +98,98 @@ const HotEvent = memo(
getData();
}, []);
- const getColumns = useCallback((hotTopic: HotTopic[]) => {
- const columns: TableProps<HotTopic>["columns"] = [
- {
- title: "排名",
- width: 60,
- render: (text, data, ind) => (
- <div className={styles.ranking}>
- {ind <= 2 ? (
- <div
- className={hotContentStyles.rankingTopthree}
- style={{ width: "20px", height: "20px", lineHeight: "20px" }}
- >
- {ind + 1}
- </div>
- ) : (
- <p style={{ width: "20px", textAlign: "center" }}>{ind + 1}</p>
- )}
+ const getColumns = useCallback(
+ (hotTopic: HotTopic[]) => {
+ const columns: TableProps<HotTopic>["columns"] = [
+ {
+ title: t("rank"),
+ width: 60,
+ render: (text, data, ind) => (
+ <div className={styles.ranking}>
+ {ind <= 2 ? (
+ <div
+ className={hotContentStyles.rankingTopthree}
+ style={{
+ width: "20px",
+ height: "20px",
+ lineHeight: "20px",
+ }}
+ >
+ {ind + 1}
+ </div>
+ ) : (
+ <p style={{ width: "20px", textAlign: "center" }}>
+ {ind + 1}
+ </p>
+ )}
- {!data.rankChange ? null : data.rankChange > 0 ? (
- <p className="rankingTopthree-rise">
- <Icon component={Uparrow} />
- <span className="rankingTopthree-name">
- {data.rankChange}
- </span>
- </p>
- ) : (
- <p className="rankingTopthree-fall">
- <Icon component={Uparrow} />
- <span className="rankingTopthree-name">
- {Math.abs(data.rankChange)}
- </span>
- </p>
- )}
- </div>
- ),
- },
- {
- title: "热点事件",
- render: (text, record) => {
- return (
- <span
- className={styles.hotEventTitle}
- title={record.title}
- onClick={() => {
- if (!record.url) return;
- window.open(record.url, "_blank");
- }}
- >
- {record.title}
- </span>
- );
+ {!data.rankChange ? null : data.rankChange > 0 ? (
+ <p className="rankingTopthree-rise">
+ <Icon component={Uparrow} />
+ <span className="rankingTopthree-name">
+ {data.rankChange}
+ </span>
+ </p>
+ ) : (
+ <p className="rankingTopthree-fall">
+ <Icon component={Uparrow} />
+ <span className="rankingTopthree-name">
+ {Math.abs(data.rankChange)}
+ </span>
+ </p>
+ )}
+ </div>
+ ),
},
- },
- {
- width: 120,
- title: "热度值",
- align: "center",
- render: (text, record) => {
- return (
- <span style={{ fontFamily: "DIN" }}>
- {describeNumber(record.hotValue)}
- </span>
- );
+ {
+ title: t("hotEvents"),
+ render: (text, record) => {
+ return (
+ <span
+ className={styles.hotEventTitle}
+ title={record.title}
+ onClick={() => {
+ if (!record.url) return;
+ window.open(record.url, "_blank");
+ }}
+ >
+ {record.title}
+ </span>
+ );
+ },
+ },
+ {
+ width: 120,
+ title: t("hotValue"),
+ align: "center",
+ render: (text, record) => {
+ return (
+ <span style={{ fontFamily: "DIN" }}>
+ {describeNumber(record.hotValue)}
+ </span>
+ );
+ },
},
- },
- ...(hotTopic[0]?.hotValueHistory?.length >= 1
- ? [
- {
- width: 200,
- title: "热度趋势",
- render: (text: string, record: HotTopic) => (
- <HotTrendLine id={record._id} data={record.hotValueHistory} />
- ),
- },
- ]
- : []),
- ];
- return columns;
- }, []);
+ ...(hotTopic[0]?.hotValueHistory?.length >= 1
+ ? [
+ {
+ width: 200,
+ title: t("hotTrend"),
+ render: (text: string, record: HotTopic) => (
+ <HotTrendLine
+ id={record._id}
+ data={record.hotValueHistory}
+ />
+ ),
+ },
+ ]
+ : []),
+ ];
+ return columns;
+ },
+ [t],
+ );
return (
<Spin spinning={loading} style={{ minHeight: "60vh" }}>
@@ -187,7 +201,8 @@ const HotEvent = memo(
className="hotEvent-item-head"
style={{ background: material[i].back }}
>
- <Icon component={material[i].icon} /> {platform.name} · 热点
+ <Icon component={material[i].icon} /> {platform.name} ·{" "}
+ {t("hot")}
</div>
<div className={styles["hotEvent-item-content"]}>
<Table
diff --git a/src/app/i18n/locales/en/hot-content.json b/src/app/i18n/locales/en/hot-content.json
index 640f8e71..5f98c04c 100644
--- a/src/app/i18n/locales/en/hot-content.json
+++ b/src/app/i18n/locales/en/hot-content.json
@@ -42,5 +42,13 @@
"daily": "Daily",
"sortRule": "Sort Rule",
"sortRuleDesc": "Top 500 works by likes of the day are recommended",
- "dataDescription": "Data Description"
+ "dataDescription": "Data Description",
+ "expand": "Expand",
+ "collapse": "Collapse",
+ "hotValue": "Hot Value",
+ "hotTrend": "Hot Trend",
+ "shortDrama": "Short Drama",
+ "cultureTourism": "Culture & Tourism",
+ "contentOverseas": "Content Overseas",
+ "hot": "Hot"
}
diff --git a/src/app/i18n/locales/zh-CN/hot-content.json b/src/app/i18n/locales/zh-CN/hot-content.json
index 96981a6c..e909d709 100644
--- a/src/app/i18n/locales/zh-CN/hot-content.json
+++ b/src/app/i18n/locales/zh-CN/hot-content.json
@@ -42,5 +42,13 @@
"daily": "按日",
"sortRule": "排序规则",
"sortRuleDesc": "统计当日点赞量前500名的作品推荐",
- "dataDescription": "数据说明"
+ "dataDescription": "数据说明",
+ "expand": "展开",
+ "collapse": "收起",
+ "hotValue": "热度值",
+ "hotTrend": "热度趋势",
+ "shortDrama": "短剧",
+ "cultureTourism": "文旅",
+ "contentOverseas": "内容出海",
+ "hot": "热点"
}
diff --git a/src/app/layout/HomeHeader.tsx b/src/app/layout/HomeHeader.tsx
index aaa3b0c6..63bca92f 100644
--- a/src/app/layout/HomeHeader.tsx
+++ b/src/app/layout/HomeHeader.tsx
@@ -28,6 +28,7 @@ const HomeHeader = memo(
router.push(
`/${newLng}${location.pathname.replace(`/${userStore.lang}`, "")}`,
);
+ location.reload();
};
return (