From 07c0e5e14566e97e810c0ff6ca1abc6b2bcc8568 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 19 Apr 2025 15:43:35 +0800 Subject: [PATCH] . --- .../sidebar/items/all/sidebar-create-item.tsx | 32 ++++++++++++++++--- public/locales/en/translation.json | 2 ++ public/locales/ja/translation.json | 2 ++ public/locales/zh/translation.json | 2 ++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/components/sidebar/items/all/sidebar-create-item.tsx b/components/sidebar/items/all/sidebar-create-item.tsx index 18d08ff..c9c90a4 100644 --- a/components/sidebar/items/all/sidebar-create-item.tsx +++ b/components/sidebar/items/all/sidebar-create-item.tsx @@ -29,6 +29,8 @@ import { ContentType } from "@/types" import { FC, useContext, useRef, useState } from "react" import { toast } from "sonner" +import { useTranslation } from 'react-i18next' + interface SidebarCreateItemProps { isOpen: boolean isTyping: boolean @@ -46,6 +48,9 @@ export const SidebarCreateItem: FC = ({ createState, isTyping }) => { + + const { t, i18n } = useTranslation() + const { selectedWorkspace, setChats, @@ -215,6 +220,20 @@ export const SidebarCreateItem: FC = ({ } } +// 判断是否需要首字母大写(且做 -1 截断) +const needsUpperCaseFirstLetter = (language: string) => { + const languagesRequiringUpperCase = ['en', 'de', 'fr', 'es', 'it']; + return languagesRequiringUpperCase.includes(language); +}; + +// 处理翻译后的 contentType 文本 +const getCapitalizedContentType = (translated: string, language: string) => { + if (needsUpperCaseFirstLetter(language)) { + return translated.charAt(0).toUpperCase() + translated.slice(1, -1); // ✅ 按你的要求保留 .slice(1, -1) + } + return translated; +}; + return ( = ({
- Create{" "} - {contentType.charAt(0).toUpperCase() + contentType.slice(1, -1)} + {/* Create{" "} + {contentType.charAt(0).toUpperCase() + contentType.slice(1, -1)} */} + + {t("side.sidebarCreateNew")}{" "} + {getCapitalizedContentType(t(`contentTypeLabel.${contentType}`), i18n.language)} + + @@ -240,11 +264,11 @@ export const SidebarCreateItem: FC = ({ variant="outline" onClick={() => onOpenChange(false)} > - Cancel + {t("side.cancel")}
diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 19f5481..b5e661d 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -151,6 +151,8 @@ "profileSettings": "Profile Settings", "deleteChatTitle": "Delete", "deleteChatConfirm": "Are you sure you want to delete this chat?", + "create": "Create", + "creating": "Creating...", "delete": "Delete" }, diff --git a/public/locales/ja/translation.json b/public/locales/ja/translation.json index 6003983..7740f49 100644 --- a/public/locales/ja/translation.json +++ b/public/locales/ja/translation.json @@ -150,6 +150,8 @@ "profileSettings": "プロフィール設定", "deleteChatTitle": "削除", "deleteChatConfirm": "このチャットを削除してもよろしいですか?", + "create": "作成", + "creating": "作成中...", "delete": "削除" }, diff --git a/public/locales/zh/translation.json b/public/locales/zh/translation.json index 4dd36b7..5cc74a9 100644 --- a/public/locales/zh/translation.json +++ b/public/locales/zh/translation.json @@ -150,6 +150,8 @@ "profileSettings": "个人资料设置", "deleteChatTitle": "删除", "deleteChatConfirm": "您确定要删除此聊天记录吗?", + "create": "创建", + "creating": "正在创建...", "delete": "删除" },