diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 307b7771..5126562a 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -15,17 +15,17 @@ "login": "Sign In" }, "advert": { - "desc": "Server will expire in", - "desc2": "WeChat Sponsorship", - "next": "Short of this target by", - "next2": "Short of next target by", + "desc": "Server expire in", + "desc2": "Buy me a coffee", + "next": "Need to gold", + "next2": "Next target by", "day": "D", "year": "Y" }, "site_stats": { - "user": "Total Users", - "repo": "Projects", - "title": "About Us", + "user": "#Users", + "repo": "#Projects", + "title": "About", "desc": "HelloGitHub is a platform to discover and share interesting, beginner-friendly open source projects.\nWe aim to help everyone find joy in programming, easily solve technical challenges,\nexplore amazing open-source tools, and naturally embark on their open-source journey." }, "recommend": { @@ -45,5 +45,8 @@ "server_sponsor2": "", "cdn_sponsor": "Cloud service is sponsored by", "cdn_sponsor2": "" + }, + "collect": { + "title": "New" } } diff --git a/public/locales/en/home.json b/public/locales/en/home.json index 94c8447f..7dfe6233 100644 --- a/public/locales/en/home.json +++ b/public/locales/en/home.json @@ -11,11 +11,9 @@ }, "tag_side": { "title": "Hot Tags", - "manage": "Preference", - "all_tags_label": "All" + "manage": "Preference" }, "tag_modal": { - "default_tag": "All", "tips": "Tips: Click the tag on the left to 'Select', drag the selected tags on the right to 'Sort'", "selected": "Selected: ", "fetch_fail_msg": "Failed to fetch tags", @@ -23,6 +21,10 @@ "save": "Save", "save_success_msg": "Save successful!", "save_fail_msg": "Save failed!", - "max_tag_msg": "You can only select up to {{maxTotal}} tags!" + "max_tag_msg": "You can only select up to {{maxTotal}} tags!", + "编程语言": "Programming", + "技术栈": "Technology", + "应用类型": "Application", + "其它": "Other" } } diff --git a/public/locales/en/repository.json b/public/locales/en/repository.json index 7e731f95..778f7380 100644 --- a/public/locales/en/repository.json +++ b/public/locales/en/repository.json @@ -1,99 +1,99 @@ { - "nav": { - "title": "Project Details", - "desc": "Shared by", - "desc2": "" + "nav": { + "title": "Project Details", + "desc": "Shared by", + "desc2": "" + }, + "info": { + "claimed": "Claimed", + "unclaim": "Unclaimed", + "score_desc": "HelloGitHub Rating", + "score_user_desc": "{{count}} ratings", + "vite": "Visit", + "voted": "Liked", + "vote": "Like", + "opensource": "Open Source", + "discuss": "Discuss", + "share": "Share", + "collect": "Collect", + "copy_desc": "More details at:", + "copy_success": "Project information copied successfully, share it now!", + "copy_fail": "Copy failed" + }, + "url": { + "home": "Website", + "document": "Documentation", + "download": "Download", + "online": "Demo", + "source": "Source Code" + }, + "favorite": { + "default": "Default Favorites", + "cancel": "Unfavorite", + "success": "Added to Favorites", + "fail": "Failed to add to Favorites", + "title": "Select Favorites", + "desc": "You can find favorited projects in 'My Homepage'", + "save": "Save" + }, + "history": { + "past_day_desc": "Past {{days}} days", + "total_desc": "Received {{total}} stars ✨", + "fail_desc": "No star history data available" + }, + "more": { + "yes": "Yes", + "no": "No", + "null": "None", + "star": "Stars", + "chinese": "Chinese", + "language": "Main Language", + "activity": "Active", + "contributors": "Contributors", + "org": "Organization", + "version": "Latest Version", + "license": "License", + "expand": "More", + "collapse": "Collapse" + }, + "content": { + "desc_tab": "Description", + "code_tab": "Code", + "volume_label": "Included in:", + "volume": "Issue {{volume}}", + "tag_label": "Tags:" + }, + "comment": { + "title": "Comments", + "sort_hot": "Hot", + "sort_new": "Newest", + "total": "{{total}} selected comments", + "more_reply": "View all {{total}} replies", + "load_more": "Load more...", + "no_comment": "No selected comments yet", + "used": "Used", + "unused": "Not Used", + "score": "Rating:", + "reply": "Reply", + "cancel": "Cancel", + "item": { + "featured": "Featured", + "unfeatured": "Not Featured", + "vote": "Like", + "expand": "Expand", + "collapse": "Collapse", + "login": "Please log in first" }, - "info": { - "claimed": "Claimed", - "unclaim": "Unclaimed", - "score_desc": "HelloGitHub Rating", - "score_user_desc": "{{count}} ratings", - "vite": "Visit", - "voted": "Liked", - "vote": "Like", - "opensource": "Open Source", - "discuss": "Discuss", - "share": "Share", - "collect": "Collect", - "copy_desc": "More details at:", - "copy_success": "Project information copied successfully, share it now!", - "copy_fail": "Copy failed" - }, - "url": { - "home": "Website", - "document": "Documentation", - "download": "Download", - "online": "Demo", - "source": "Source Code" - }, - "favorite": { - "default": "Default Favorites", - "cancel": "Unfavorite", - "success": "Added to Favorites", - "fail": "Failed to add to Favorites", - "title": "Select Favorites", - "desc": "You can find favorited projects in 'My Homepage'", - "save": "Save" - }, - "history": { - "past_day_desc": "Past {{days}} days", - "total_desc": "Received {{total}} stars ✨", - "fail_desc": "No star history data available" - }, - "more": { - "yes": "Yes", - "no": "No", - "null": "None", - "star": "Stars", - "chinese": "Chinese", - "language": "Main Language", - "activity": "Active", - "contributors": "Contributors", - "org": "Organization", - "version": "Latest Version", - "license": "License", - "expand": "More", - "collapse": "Collapse" - }, - "content": { - "desc_tab": "Description", - "code_tab": "Code", - "volume_label": "Included in:", - "volume": "Issue {{volume}}", - "tag_label": "Tags:" - }, - "comment": { - "title": "Comments", - "sort_hot": "Hot", - "sort_new": "Newest", - "total": "{{total}} selected comments", - "more_reply": "View all {{total}} replies", - "load_more": "Load more...", - "no_comment": "No selected comments yet", - "used": "Used", - "unused": "Not Used", - "score": "Rating:", - "reply": "Reply", - "cancel": "Cancel", - "item": { - "featured": "Featured", - "unfeatured": "Not Featured", - "vote": "Like", - "expand": "Expand", - "collapse": "Collapse", - "login": "Please log in first" - }, - "submit": { - "reply_placeholder": "Replying to: {{nickname}}", - "placeholder": "Write your comment: share your experience, pros/cons, use cases, or any surprising aspects of this open-source project...", - "save": "Submit", - "success": "Posted successfully! Will be displayed after approval", - "fail": "Submission failed", - "err1": "Comment content cannot be empty", - "err2": "Comment content must be at least 5 characters", - "err3": "Comment content cannot exceed 500 characters", - "err4": "Please provide a rating" - } + "submit": { + "reply_placeholder": "Replying to: {{nickname}}", + "placeholder": "Write your comment: share your experience, pros/cons, use cases, or any surprising aspects of this open-source project...", + "save": "Submit", + "success": "Posted successfully! Will be displayed after approval", + "fail": "Submission failed", + "err1": "Comment content cannot be empty", + "err2": "Comment content must be at least 5 characters", + "err3": "Comment content cannot exceed 500 characters", + "err4": "Please provide a rating" } + } } diff --git a/public/locales/zh/common.json b/public/locales/zh/common.json index ac2b0a33..e4435d66 100644 --- a/public/locales/zh/common.json +++ b/public/locales/zh/common.json @@ -36,7 +36,7 @@ }, "footer": { "feedback": "问题反馈", - "business":"商务合作", + "business": "商务合作", "contact": "联系我们", "agreement": "用户协议", "source": "社区源码", @@ -45,5 +45,8 @@ "server_sponsor2": "提供", "cdn_sponsor": "专业的", "cdn_sponsor2": "提供云存储服务" + }, + "collect": { + "title": "新建收藏夹" } } diff --git a/public/locales/zh/home.json b/public/locales/zh/home.json index 50cc6534..1437e619 100644 --- a/public/locales/zh/home.json +++ b/public/locales/zh/home.json @@ -11,11 +11,9 @@ }, "tag_side": { "title": "热门标签", - "manage": "管理标签", - "all_tags_label": "综合" + "manage": "管理标签" }, "tag_modal": { - "default_tag": "综合", "tips": "操作提示:点击左侧标签为「选择」,拖拽右侧已选标签可「排序」", "selected": "已选:", "fetch_fail_msg": "获取标签失败", @@ -23,6 +21,10 @@ "save": "保存", "save_success_msg": "保存成功!", "save_fail_msg": "保存失败!", - "max_tag_msg": "最多只能选择 {{maxTotal}} 个标签!" + "max_tag_msg": "最多只能选择 {{maxTotal}} 个标签!", + "编程语言": "编程语言", + "技术栈": "技术栈", + "应用类型": "应用类型", + "其它": "其它" } } diff --git a/public/locales/zh/repository.json b/public/locales/zh/repository.json index 792e5dd1..aff3d37f 100644 --- a/public/locales/zh/repository.json +++ b/public/locales/zh/repository.json @@ -1,100 +1,99 @@ { - "nav": { - "title": "项目详情", - "desc": "由", - "desc2": "分享" + "nav": { + "title": "项目详情", + "desc": "由", + "desc2": "分享" + }, + "info": { + "claimed": "已认领", + "unclaim": "未认领", + "score_desc": "HelloGitHub 评分", + "score_user_desc": "{{count}} 人评分", + "vite": "访问", + "voted": "已赞", + "vote": "点赞", + "opensource": "开源", + "discuss": "讨论", + "share": "分享", + "collect": "收藏", + "copy_desc": "更多详情尽在:", + "copy_success": "项目信息已复制,快去分享吧!", + "copy_fail": "复制失败" + }, + "url": { + "home": "官网", + "document": "文档", + "download": "下载", + "online": "演示", + "source": "源码" + }, + "favorite": { + "default": "默认收藏夹", + "cancel": "取消收藏", + "success": "收藏成功", + "fail": "收藏失败", + "title": "选择收藏夹", + "desc": "收藏的项目在「我的主页」可以找到", + "save": "确定" + }, + "history": { + "past_day_desc": "过去 {{days}} 天", + "total_desc": "共收获 {{total}} 颗 Star ✨", + "fail_desc": "暂无 Star 历史数据" + }, + "more": { + "yes": "是", + "no": "否", + "null": "无", + "star": "星数", + "chinese": "中文", + "language": "主语言", + "activity": "活跃", + "contributors": "贡献者", + "org": "组织", + "version": "最新版本", + "license": "协议", + "expand": "更多", + "collapse": "收起" + }, + "content": { + "desc_tab": "介绍", + "code_tab": "代码", + "volume_label": "收录于:", + "volume": "第 {{volume}} 期", + "tag_label": "标签:" + }, + "comment": { + "title": "评论", + "sort_hot": "热门", + "sort_new": "最新", + "total": "{{total}} 条精选评论", + "more_reply": "查看全部 {{total}} 条回复", + "load_more": "加载更多...", + "no_comment": "暂无精选评论", + "used": "用过", + "unused": "没用过", + "score": "评分:", + "reply": "回复", + "cancel": "取消", + "item": { + "featured": "精选", + "unfeatured": "未精选", + "vote": "点赞", + "expand": "展开", + "collapse": "收起", + "login": "请先登录" }, - "info": { - "claimed": "已认领", - "unclaim": "未认领", - "socre_desc": "HelloGitHub 评分", - "socre_user_desc": "{{count}} 人评分", - "vite": "访问", - "voted": "已赞", - "vote": "点赞", - "opensource": "开源", - "discuss": "讨论", - "share": "分享", - "collect": "收藏", - "copy_desc": "更多详情尽在:", - "copy_success": "项目信息已复制,快去分享吧!", - "copy_fail": "复制失败" - }, - "url": { - "home": "官网", - "document": "文档", - "download": "下载", - "online": "演示", - "source": "源码" - }, - "favorite": { - "default": "默认收藏夹", - "cancel": "取消收藏", - "success": "收藏成功", - "fail": "收藏失败", - "title": "选择收藏夹", - "desc": "收藏的项目在「我的主页」可以找到", - "save": "确定" - }, - "history": { - "past_day_desc": "过去 {{days}} 天", - "total_desc": "共收获 {{total}} 颗 Star ✨", - "fail_desc": "暂无 Star 历史数据" - }, - "more": { - "yes": "是", - "no": "否", - "null": "无", - "star": "星数", - "chinese": "中文", - "language": "主语言", - "activity": "活跃", - "contributors": "贡献者", - "org": "组织", - "version": "最新版本", - "license": "协议", - "expand": "更多", - "collapse": "收起" - }, - "content": { - "desc_tab": "介绍", - "code_tab": "代码", - "volume_label": "收录于:", - "volume": "第 {{volume}} 期", - "tag_label": "标签:" - }, - "comment": { - "title": "评论", - "sort_hot": "热门", - "sort_new": "最新", - "total": "{{total}} 条精选评论", - "more_reply": "查看全部 {{total}} 条回复", - "load_more": "加载更多...", - "no_comment": "暂无精选评论", - "used": "用过", - "unused": "没用过", - "score": "评分:", - "reply": "回复", - "cancel": "取消", - "item": { - "featured": "精选", - "unfeatured": "未精选", - "vote": "点赞", - "expand": "展开", - "collapse": "收起", - "login": "请先登录" - }, - "submit": { - "reply_placeholder": "正在回复:{{nickname}}", - "placeholder": "写下你的评论:分享开源项目的使用体验、优点/吐槽、适用场景、惊艳之处...", - "save": "发表", - "success": "发布成功!通过审核后展示", - "fail": "提交失败", - "err1":"评论内容不能为空", - "err2":"评论内容不能少于 5 个字", - "err3":"评论内容不能超过 500 个字", - "err4":"请评分" - - } + "submit": { + "reply_placeholder": "正在回复:{{nickname}}", + "placeholder": "写下你的评论:分享开源项目的使用体验、优点/吐槽、适用场景、惊艳之处...", + "save": "发表", + "success": "发布成功!通过审核后展示", + "fail": "提交失败", + "err1": "评论内容不能为空", + "err2": "评论内容不能少于 5 个字", + "err3": "评论内容不能超过 500 个字", + "err4": "请评分" } -} \ No newline at end of file + } +} diff --git a/src/components/collection/AddCollection.tsx b/src/components/collection/AddCollection.tsx index b0be0aed..828b2c06 100644 --- a/src/components/collection/AddCollection.tsx +++ b/src/components/collection/AddCollection.tsx @@ -1,3 +1,4 @@ +import { useTranslation } from 'next-i18next'; import * as React from 'react'; import { AiOutlinePlus } from 'react-icons/ai'; @@ -223,6 +224,7 @@ export default function AddCollection({ className, onFinish, }: AddCollectionProps) { + const { t } = useTranslation('common'); const [openModal, setOpenModal] = React.useState(false); return ( @@ -234,12 +236,12 @@ export default function AddCollection({ }} className='inline-flex items-center justify-center gap-2 rounded-md border border-transparent py-1 px-0 text-sm font-medium text-blue-500 ring-offset-white transition-all hover:text-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2' > - 新建收藏夹 + {t('collect.title')} {/* 弹窗 */} setOpenModal(false)} diff --git a/src/components/dialog/TagModal.tsx b/src/components/dialog/TagModal.tsx index 643f4e91..03a06d34 100644 --- a/src/components/dialog/TagModal.tsx +++ b/src/components/dialog/TagModal.tsx @@ -17,23 +17,19 @@ import { getSelectTags, saveSelectTags } from '@/services/tag'; import BasicDialog from '../dialog/BasicDialog'; -import { maxTotal, PortalTag, PortalTagGroup, Tag } from '@/types/tag'; +import { maxTotal, PortalTag, PortalTagGroup } from '@/types/tag'; export function TagModal({ children, updateTags, t, + i18n_lang, }: { children: JSX.Element; updateTags: any; t: (key: string, total?: any) => string; + i18n_lang: string; }) { - const defaultTag: Tag = { - name: t('tag_modal.default_tag'), - tid: '', - icon_name: 'find', - }; - const [loading, setLoading] = useState(false); const [total, setTotal] = useState(0); const { isLogin, login } = useLoginContext(); @@ -54,7 +50,25 @@ export function TagModal({ } else { const res = await getSelectTags(); if (res.success) { - setPortalTagGroups(res.data); + const tagGroups = res.data.map((group) => { + const updatedTags = group.tags.map((tag) => { + // Replace the 'name' value with the 'name_en' value if available + if (i18n_lang == 'en' && tag.name_en !== null) { + return { + ...tag, + name: tag.name_en, + }; + } + return tag; + }); + + return { + ...group, + tags: updatedTags, + }; + }); + + setPortalTagGroups(tagGroups); setEffectedTidList(res.effected); setIsOpen(true); } else { @@ -90,14 +104,17 @@ export function TagModal({ const saveTags = async () => { if (effectedTidList.length <= maxTotal) { - const selectTags = []; - selectTags.unshift(defaultTag); + const defaultTag = + i18n_lang === 'en' + ? { name: 'All', tid: '', icon_name: 'find', name_en: 'All' } + : { name: '综合', tid: '', icon_name: 'find', name_en: 'All' }; + const selectTags = [defaultTag]; for (let i = 0; i < effectedTidList.length; i++) { const item = portalTagGroups .map((m) => m.tags) .flat() .find((f) => f.tid === effectedTidList[i]); - selectTags.push(item); + item && selectTags.push(item); } setLoading(true); const res = await saveSelectTags(effectedTidList); @@ -157,7 +174,7 @@ export function TagModal({ key={'group_' + index} className='text-lg font-medium text-gray-500 dark:text-gray-200' > - {group.group_name} + {t(`${group.group_name}`)} ,
{
- {t('info.socre_desc')} + {t('info.score_desc')}
{repo.score ? ( @@ -31,7 +31,7 @@ const Score = ({ t, repo }: RepositoryProps) => { className='h-1/2 cursor-pointer py-1 text-xs text-blue-500' onClick={jumpComment} > - {t('info.socre_user_desc', { count: repo.comment_total })} + {t('info.score_user_desc', { count: repo.comment_total })}
diff --git a/src/components/side/Ad.tsx b/src/components/side/Ad.tsx index 4577e5fe..19d95a95 100644 --- a/src/components/side/Ad.tsx +++ b/src/components/side/Ad.tsx @@ -6,10 +6,14 @@ import { redirectRecord } from '@/services/home'; import { AdvertItem } from '@/types/home'; +const ImageURL = + 'https://img.hellogithub.com/article/HwsoJXEiYdPhjLa_1720773908.png'; + interface Props { data: AdvertItem; className?: string; t: (key: string) => string; + i18n_lang?: string; } interface AdContentProps { @@ -34,7 +38,7 @@ const ImageAdContent = ({ data, handleClose }: ImageAdContentProps) => (
); -export default function Ad({ data, className, t }: Props) { +export default function Ad({ data, className, t, i18n_lang }: Props) { const [visible, setVisible] = useState(true); const handleClose: MouseEventHandler = (e) => { @@ -86,7 +90,11 @@ export default function Ad({ data, className, t }: Props) { const RewardAdContent = ({ data, t }: AdContentProps) => (
- ad + ad
{t('advert.desc2')} diff --git a/src/components/side/Side.tsx b/src/components/side/Side.tsx index e209a0f9..e0a96bed 100644 --- a/src/components/side/Side.tsx +++ b/src/components/side/Side.tsx @@ -15,7 +15,7 @@ import UserStatus from './UserStatus'; import { AdvertItems } from '@/types/home'; export const Side = ({ isHome }: { isHome: boolean }) => { - const { t } = useTranslation('common'); + const { t, i18n } = useTranslation('common'); const [displayAdOnly, setDisplayAdOnly] = useState(false); const containerRef = useRef(null); const { data, isValidating } = useSWRImmutable( @@ -46,14 +46,21 @@ export const Side = ({ isHome }: { isHome: boolean }) => {
- {!isValidating && } + {!isValidating && ( + + )} {isHome ? : }
{isHome &&
}
{adverts && ( - + )} ); diff --git a/src/components/side/SideAd.tsx b/src/components/side/SideAd.tsx index f91c97c7..89ba42a7 100644 --- a/src/components/side/SideAd.tsx +++ b/src/components/side/SideAd.tsx @@ -8,26 +8,32 @@ interface Props { data: AdvertItem[]; displayAdOnly?: boolean; t: (key: string) => string; + i18n_lang?: string; } -export const SideAd: NextPage = ({ data, t }) => { +export const SideAd: NextPage = ({ data, t, i18n_lang }) => { return (
{data.map((item: AdvertItem) => ( - + ))}
); }; -export const SideFixAd: NextPage = ({ data, displayAdOnly, t }) => { +export const SideFixAd: NextPage = ({ + data, + displayAdOnly, + t, + i18n_lang, +}) => { return ( ); diff --git a/src/components/side/TagList.tsx b/src/components/side/TagList.tsx index 43ab21b9..dbb71710 100644 --- a/src/components/side/TagList.tsx +++ b/src/components/side/TagList.tsx @@ -15,9 +15,10 @@ import { TagListSkeleton } from '../loading/skeleton'; import { Tag } from '@/types/tag'; export default function TagList() { - const { t } = useTranslation('home'); + const { t, i18n } = useTranslation('home'); const defaultTag: Tag = { - name: t('tag_side.all_tags_label'), + name: '综合', + name_en: 'All', tid: '', icon_name: 'find', }; @@ -30,9 +31,15 @@ export default function TagList() { const res = await getTags(); if (res.success) { res.data.unshift(defaultTag); + // 判断当前语言是否为英文,如果是英文则显示英文名称 + res.data.forEach((item) => { + if (i18n.language == 'en' && item.name_en !== null) { + item.name = item.name_en; + } + }); setTags(res.data); } - }, []); + }, [i18n.language]); useEffect(() => { if (!isMobile()) { @@ -77,7 +84,7 @@ export default function TagList() { ))} - +
{t('tag_side.manage')}
diff --git a/src/pages/repository/[rid]/index.tsx b/src/pages/repository/[rid]/index.tsx index 8dc40e68..679f0b16 100644 --- a/src/pages/repository/[rid]/index.tsx +++ b/src/pages/repository/[rid]/index.tsx @@ -1,16 +1,16 @@ import { GetServerSideProps, NextPage } from 'next'; +import { useTranslation } from 'next-i18next'; +import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import RepoDetailNavbar from '@/components/navbar/RepoNavbar'; import CommentContainer from '@/components/respository/CommentContainer'; import Info from '@/components/respository/Info'; import Tabs from '@/components/respository/Tabs'; import Seo from '@/components/Seo'; -import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import { getDetail } from '@/services/repository'; import { Repository } from '@/types/repository'; -import { useTranslation } from 'next-i18next'; interface Props { repo: Repository; diff --git a/src/types/tag.tsx b/src/types/tag.tsx index 88dd0d64..500ef615 100644 --- a/src/types/tag.tsx +++ b/src/types/tag.tsx @@ -24,6 +24,7 @@ export interface TagItems { export interface Tag { name: string; + name_en: string; tid: string; icon_name: string; } @@ -47,6 +48,7 @@ export interface TagType { export interface PortalTag { name: string; + name_en: string; tid: string; icon_name: string; }