支持folder主界面多语言
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||
import { Plus, RefreshCw, X } from "lucide-react"
|
||||
import { useTranslations } from "next-intl"
|
||||
import { toast } from "sonner"
|
||||
import { useFolderContext } from "@/contexts/folder-context"
|
||||
import { useTabContext } from "@/contexts/tab-context"
|
||||
@@ -41,6 +42,7 @@ const ExistingConversationView = memo(function ExistingConversationView({
|
||||
isActive,
|
||||
reloadSignal,
|
||||
}: ExistingConversationViewProps) {
|
||||
const t = useTranslations("Folder.conversation")
|
||||
const { refreshConversations, folder } = useFolderContext()
|
||||
const contextKey = `conv-${agentType}-${conversationId}`
|
||||
|
||||
@@ -193,12 +195,12 @@ const ExistingConversationView = memo(function ExistingConversationView({
|
||||
pendingReloadState.current = null
|
||||
|
||||
if (detailError) {
|
||||
toast.error(`会话重新加载失败:${detailError}`)
|
||||
toast.error(t("reloadFailed", { message: detailError }))
|
||||
return
|
||||
}
|
||||
|
||||
toast.success("当前会话已重新加载")
|
||||
}, [detailLoading, detailError])
|
||||
toast.success(t("reloaded"))
|
||||
}, [detailLoading, detailError, t])
|
||||
|
||||
return (
|
||||
<ConversationShell
|
||||
@@ -237,6 +239,7 @@ const ExistingConversationView = memo(function ExistingConversationView({
|
||||
})
|
||||
|
||||
export function ConversationDetailPanel() {
|
||||
const t = useTranslations("Folder.conversation")
|
||||
const { folder, newConversation } = useFolderContext()
|
||||
const { tabs, activeTabId, openNewConversationTab, closeTab } =
|
||||
useTabContext()
|
||||
@@ -364,14 +367,14 @@ export function ConversationDetailPanel() {
|
||||
onSelect={handleReloadActiveConversation}
|
||||
>
|
||||
<RefreshCw className="h-4 w-4" />
|
||||
重新加载
|
||||
{t("reload")}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem
|
||||
disabled={!folder?.path}
|
||||
onSelect={handleNewConversation}
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
新建会话
|
||||
{t("newConversation")}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuSeparator />
|
||||
<ContextMenuItem
|
||||
@@ -379,7 +382,7 @@ export function ConversationDetailPanel() {
|
||||
onSelect={handleCloseActiveTab}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
关闭会话
|
||||
{t("closeConversation")}
|
||||
</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
import { useState, useEffect, useRef, useCallback } from "react"
|
||||
import { formatDistanceToNow } from "date-fns"
|
||||
import { enUS, zhCN, zhTW } from "date-fns/locale"
|
||||
import { useLocale, useTranslations } from "next-intl"
|
||||
import { useFolderContext } from "@/contexts/folder-context"
|
||||
import { useTabContext } from "@/contexts/tab-context"
|
||||
import { listFolderConversations } from "@/lib/tauri"
|
||||
@@ -31,6 +33,10 @@ export function SearchCommandDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
}: SearchCommandDialogProps) {
|
||||
const t = useTranslations("Folder.search")
|
||||
const locale = useLocale()
|
||||
const dateFnsLocale =
|
||||
locale === "zh-CN" ? zhCN : locale === "zh-TW" ? zhTW : enUS
|
||||
const { folderId, conversations } = useFolderContext()
|
||||
const { openTab } = useTabContext()
|
||||
|
||||
@@ -96,12 +102,12 @@ export function SearchCommandDialog({
|
||||
|
||||
return (
|
||||
<CommandDialog
|
||||
title="Search conversations"
|
||||
title={t("dialogTitle")}
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
>
|
||||
<CommandInput
|
||||
placeholder="Search conversations..."
|
||||
placeholder={t("placeholder")}
|
||||
value={query}
|
||||
onValueChange={setQuery}
|
||||
/>
|
||||
@@ -116,7 +122,7 @@ export function SearchCommandDialog({
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
)}
|
||||
>
|
||||
All
|
||||
{t("allAgents")}
|
||||
</button>
|
||||
{availableAgents.map((at) => (
|
||||
<button
|
||||
@@ -138,10 +144,10 @@ export function SearchCommandDialog({
|
||||
<CommandList className="min-h-96">
|
||||
<CommandEmpty>
|
||||
{searching
|
||||
? "Searching..."
|
||||
? t("searching")
|
||||
: !query.trim() && !agentFilter
|
||||
? "键入搜索以查询会话"
|
||||
: "No results found."}
|
||||
? t("typeToSearch")
|
||||
: t("noResults")}
|
||||
</CommandEmpty>
|
||||
{results.length > 0 && (
|
||||
<CommandGroup>
|
||||
@@ -159,7 +165,7 @@ export function SearchCommandDialog({
|
||||
)}
|
||||
/>
|
||||
<span className="flex-1 truncate">
|
||||
{conv.title || "Untitled conversation"}
|
||||
{conv.title || t("untitledConversation")}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground shrink-0">
|
||||
{AGENT_LABELS[conv.agent_type]}
|
||||
@@ -167,6 +173,7 @@ export function SearchCommandDialog({
|
||||
<span className="text-xs text-muted-foreground shrink-0">
|
||||
{formatDistanceToNow(new Date(conv.created_at), {
|
||||
addSuffix: true,
|
||||
locale: dateFnsLocale,
|
||||
})}
|
||||
</span>
|
||||
</CommandItem>
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
import { memo, useState, useCallback } from "react"
|
||||
import { formatDistanceToNow } from "date-fns"
|
||||
import { enUS, zhCN, zhTW } from "date-fns/locale"
|
||||
import { GitBranch, Pencil, Trash2, Circle, Download, Plus } from "lucide-react"
|
||||
import { useLocale, useTranslations } from "next-intl"
|
||||
import type { DbConversationSummary, ConversationStatus } from "@/lib/types"
|
||||
import { STATUS_COLORS, STATUS_LABELS } from "@/lib/types"
|
||||
import { STATUS_COLORS } from "@/lib/types"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { AgentIcon } from "@/components/agent-icon"
|
||||
import {
|
||||
@@ -69,12 +71,18 @@ export const SidebarConversationCard = memo(function SidebarConversationCard({
|
||||
onImport,
|
||||
importing,
|
||||
}: SidebarConversationCardProps) {
|
||||
const t = useTranslations("Folder.conversationCard")
|
||||
const tStatus = useTranslations("Folder.statusLabels")
|
||||
const locale = useLocale()
|
||||
const dateFnsLocale =
|
||||
locale === "zh-CN" ? zhCN : locale === "zh-TW" ? zhTW : enUS
|
||||
const [renameOpen, setRenameOpen] = useState(false)
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
const [renameValue, setRenameValue] = useState("")
|
||||
|
||||
const timeAgo = formatDistanceToNow(new Date(conversation.updated_at), {
|
||||
addSuffix: true,
|
||||
locale: dateFnsLocale,
|
||||
})
|
||||
|
||||
const handleClick = useCallback(() => {
|
||||
@@ -123,7 +131,7 @@ export const SidebarConversationCard = memo(function SidebarConversationCard({
|
||||
className="size-4 shrink-0"
|
||||
/>
|
||||
<span className="text-sm font-medium truncate">
|
||||
{conversation.title || "Untitled conversation"}
|
||||
{conversation.title || t("untitledConversation")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-3 mt-1 text-xs text-muted-foreground">
|
||||
@@ -142,20 +150,20 @@ export const SidebarConversationCard = memo(function SidebarConversationCard({
|
||||
<>
|
||||
<ContextMenuItem onSelect={onNewConversation}>
|
||||
<Plus className="h-4 w-4" />
|
||||
New Conversation
|
||||
{t("newConversation")}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuSeparator />
|
||||
</>
|
||||
)}
|
||||
<ContextMenuItem onSelect={handleRenameOpen}>
|
||||
<Pencil className="h-4 w-4" />
|
||||
Rename
|
||||
{t("rename")}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuSeparator />
|
||||
<ContextMenuSub>
|
||||
<ContextMenuSubTrigger>
|
||||
<Circle className="h-4 w-4" />
|
||||
Status
|
||||
{t("status")}
|
||||
</ContextMenuSubTrigger>
|
||||
<ContextMenuSubContent>
|
||||
{ALL_STATUSES.filter((s) => s !== conversation.status).map(
|
||||
@@ -170,7 +178,7 @@ export const SidebarConversationCard = memo(function SidebarConversationCard({
|
||||
STATUS_COLORS[s]
|
||||
)}
|
||||
/>
|
||||
{STATUS_LABELS[s]}
|
||||
{tStatus(s)}
|
||||
</ContextMenuItem>
|
||||
)
|
||||
)}
|
||||
@@ -182,14 +190,14 @@ export const SidebarConversationCard = memo(function SidebarConversationCard({
|
||||
onSelect={() => setDeleteOpen(true)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
Delete
|
||||
{t("delete")}
|
||||
</ContextMenuItem>
|
||||
{onImport && (
|
||||
<>
|
||||
<ContextMenuSeparator />
|
||||
<ContextMenuItem disabled={importing} onSelect={onImport}>
|
||||
<Download className="h-4 w-4" />
|
||||
{importing ? "Importing..." : "Import local sessions"}
|
||||
{importing ? t("importing") : t("importLocalSessions")}
|
||||
</ContextMenuItem>
|
||||
</>
|
||||
)}
|
||||
@@ -199,7 +207,7 @@ export const SidebarConversationCard = memo(function SidebarConversationCard({
|
||||
<Dialog open={renameOpen} onOpenChange={setRenameOpen}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Rename conversation</DialogTitle>
|
||||
<DialogTitle>{t("renameConversation")}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<Input
|
||||
value={renameValue}
|
||||
@@ -212,9 +220,9 @@ export const SidebarConversationCard = memo(function SidebarConversationCard({
|
||||
/>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setRenameOpen(false)}>
|
||||
Cancel
|
||||
{t("cancel")}
|
||||
</Button>
|
||||
<Button onClick={handleRenameConfirm}>Save</Button>
|
||||
<Button onClick={handleRenameConfirm}>{t("save")}</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
@@ -222,17 +230,17 @@ export const SidebarConversationCard = memo(function SidebarConversationCard({
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete conversation?</AlertDialogTitle>
|
||||
<AlertDialogTitle>{t("deleteConversationTitle")}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This will delete “
|
||||
{conversation.title || "Untitled conversation"}”. This
|
||||
action cannot be undone.
|
||||
{t("deleteConversationDescription", {
|
||||
title: conversation.title || t("untitledConversation"),
|
||||
})}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogCancel>{t("cancel")}</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleDeleteConfirm}>
|
||||
Delete
|
||||
{t("delete")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
useState,
|
||||
type Ref,
|
||||
} from "react"
|
||||
import { useTranslations } from "next-intl"
|
||||
import { toast } from "sonner"
|
||||
import { CheckCheck, ChevronRight, Download, Loader2, Plus } from "lucide-react"
|
||||
import { useFolderContext } from "@/contexts/folder-context"
|
||||
@@ -20,7 +21,7 @@ import {
|
||||
deleteConversation,
|
||||
} from "@/lib/tauri"
|
||||
import type { ConversationStatus, DbConversationSummary } from "@/lib/types"
|
||||
import { STATUS_ORDER, STATUS_LABELS, STATUS_COLORS } from "@/lib/types"
|
||||
import { STATUS_ORDER, STATUS_COLORS } from "@/lib/types"
|
||||
import { SidebarConversationCard } from "./sidebar-conversation-card"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
@@ -79,6 +80,9 @@ export function SidebarConversationList({
|
||||
}: {
|
||||
ref?: Ref<SidebarConversationListHandle>
|
||||
}) {
|
||||
const t = useTranslations("Folder.sidebar")
|
||||
const tStatus = useTranslations("Folder.statusLabels")
|
||||
const tCommon = useTranslations("Folder.common")
|
||||
const {
|
||||
folder,
|
||||
conversations,
|
||||
@@ -225,7 +229,7 @@ export function SidebarConversationList({
|
||||
if (importing) return
|
||||
setImporting(true)
|
||||
const taskId = `import-${folderId}-${Date.now()}`
|
||||
addTask(taskId, "Importing local sessions")
|
||||
addTask(taskId, t("importLocalSessions"))
|
||||
updateTask(taskId, { status: "running" })
|
||||
try {
|
||||
const result = await importLocalConversations(folderId)
|
||||
@@ -233,19 +237,22 @@ export function SidebarConversationList({
|
||||
refreshConversations()
|
||||
if (result.imported > 0) {
|
||||
toast.success(
|
||||
`Imported ${result.imported} session(s), skipped ${result.skipped}`
|
||||
t("toasts.importedSessions", {
|
||||
imported: result.imported,
|
||||
skipped: result.skipped,
|
||||
})
|
||||
)
|
||||
} else {
|
||||
toast.info(`No new sessions found (skipped ${result.skipped})`)
|
||||
toast.info(t("toasts.noNewSessionsFound", { skipped: result.skipped }))
|
||||
}
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : String(e)
|
||||
updateTask(taskId, { status: "failed", error: msg })
|
||||
toast.error(`Import failed: ${msg}`)
|
||||
toast.error(t("toasts.importFailed", { message: msg }))
|
||||
} finally {
|
||||
setImporting(false)
|
||||
}
|
||||
}, [importing, folderId, addTask, updateTask, refreshConversations])
|
||||
}, [importing, folderId, addTask, updateTask, refreshConversations, t])
|
||||
|
||||
const handleCompleteAllReview = useCallback(async () => {
|
||||
if (completingReview || reviewConversationCount === 0) return
|
||||
@@ -258,12 +265,12 @@ export function SidebarConversationList({
|
||||
)
|
||||
refreshConversations()
|
||||
toast.success(
|
||||
`Marked ${reviewConversationCount} review session(s) as completed`
|
||||
t("toasts.reviewCompleted", { count: reviewConversationCount })
|
||||
)
|
||||
setCompleteReviewOpen(false)
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : String(e)
|
||||
toast.error(`Failed to complete review sessions: ${msg}`)
|
||||
toast.error(t("toasts.completeReviewFailed", { message: msg }))
|
||||
} finally {
|
||||
setCompletingReview(false)
|
||||
}
|
||||
@@ -272,6 +279,7 @@ export function SidebarConversationList({
|
||||
reviewConversationCount,
|
||||
reviewConversations,
|
||||
refreshConversations,
|
||||
t,
|
||||
])
|
||||
|
||||
return (
|
||||
@@ -290,14 +298,16 @@ export function SidebarConversationList({
|
||||
</div>
|
||||
) : error ? (
|
||||
<div className="flex-1 flex items-center justify-center px-3">
|
||||
<p className="text-destructive text-xs">Error: {error}</p>
|
||||
<p className="text-destructive text-xs">
|
||||
{t("error", { message: error })}
|
||||
</p>
|
||||
</div>
|
||||
) : conversations.length === 0 ? (
|
||||
<ContextMenu>
|
||||
<ContextMenuTrigger asChild>
|
||||
<div className="flex-1 flex flex-col items-center justify-center px-3 gap-3">
|
||||
<p className="text-muted-foreground text-xs text-center">
|
||||
No conversations found.
|
||||
{t("noConversationsFound")}
|
||||
</p>
|
||||
<Button
|
||||
variant="outline"
|
||||
@@ -310,19 +320,19 @@ export function SidebarConversationList({
|
||||
) : (
|
||||
<Download className="h-3.5 w-3.5 mr-1.5" />
|
||||
)}
|
||||
{importing ? "Importing..." : "Import local sessions"}
|
||||
{importing ? t("importing") : t("importLocalSessions")}
|
||||
</Button>
|
||||
</div>
|
||||
</ContextMenuTrigger>
|
||||
<ContextMenuContent>
|
||||
<ContextMenuItem onSelect={handleNewConversation}>
|
||||
<Plus className="h-4 w-4" />
|
||||
New Conversation
|
||||
{t("newConversation")}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuSeparator />
|
||||
<ContextMenuItem disabled={importing} onSelect={handleImport}>
|
||||
<Download className="h-4 w-4" />
|
||||
{importing ? "Importing..." : "Import local sessions"}
|
||||
{importing ? t("importing") : t("importLocalSessions")}
|
||||
</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
@@ -356,7 +366,7 @@ export function SidebarConversationList({
|
||||
STATUS_COLORS[status]
|
||||
)}
|
||||
/>
|
||||
<span>{STATUS_LABELS[status]}</span>
|
||||
<span>{tStatus(status)}</span>
|
||||
<span className="ml-auto text-muted-foreground/60 tabular-nums">
|
||||
{items.length}
|
||||
</span>
|
||||
@@ -381,7 +391,7 @@ export function SidebarConversationList({
|
||||
onSelect={() => setCompleteReviewOpen(true)}
|
||||
>
|
||||
<CheckCheck className="h-4 w-4" />
|
||||
Complete all sessions
|
||||
{t("completeAllSessions")}
|
||||
</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
@@ -421,12 +431,12 @@ export function SidebarConversationList({
|
||||
<ContextMenuContent>
|
||||
<ContextMenuItem onSelect={handleNewConversation}>
|
||||
<Plus className="h-4 w-4" />
|
||||
New Conversation
|
||||
{t("newConversation")}
|
||||
</ContextMenuItem>
|
||||
<ContextMenuSeparator />
|
||||
<ContextMenuItem disabled={importing} onSelect={handleImport}>
|
||||
<Download className="h-4 w-4" />
|
||||
{importing ? "Importing..." : "Import local sessions"}
|
||||
{importing ? t("importing") : t("importLocalSessions")}
|
||||
</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
@@ -439,21 +449,22 @@ export function SidebarConversationList({
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Complete all review sessions?</AlertDialogTitle>
|
||||
<AlertDialogTitle>{t("completeAllReviewTitle")}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This will mark all {reviewConversationCount} session(s) in Review
|
||||
as completed.
|
||||
{t("completeAllReviewDescription", {
|
||||
count: reviewConversationCount,
|
||||
})}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={completingReview}>
|
||||
Cancel
|
||||
{tCommon("cancel")}
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
disabled={completingReview || reviewConversationCount === 0}
|
||||
onClick={handleCompleteAllReview}
|
||||
>
|
||||
{completingReview ? "Completing..." : "Confirm"}
|
||||
{completingReview ? t("completing") : tCommon("confirm")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
|
||||
Reference in New Issue
Block a user