mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 06:17:58 +00:00
refactor(i18n): address code review feedback on string legos, hardcoded locales, and fragile checks
This commit is contained in:
@@ -345,7 +345,9 @@ export const MessageCard: React.FC<MessageCardProps> = ({
|
||||
badgeColor = msg.isError
|
||||
? 'bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300'
|
||||
: 'bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-300'
|
||||
roleName = `${m.tool_result()} ${String(msg.toolName || m.unknown())}`
|
||||
roleName = m.tool_result_with_name({
|
||||
name: String(msg.toolName || m.unknown()),
|
||||
})
|
||||
} else if (msg.role === 'thought') {
|
||||
badgeColor =
|
||||
'bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-300'
|
||||
|
||||
@@ -604,7 +604,7 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
||||
{replyingTo && (
|
||||
<div className="flex items-center justify-between bg-muted p-2 px-3 rounded-lg border border-border">
|
||||
<div className="text-xs text-muted-foreground truncate mr-2">
|
||||
{m.reply_to()} {replyingTo.message}
|
||||
{m.reply_to_message({ message: replyingTo.message || '' })}
|
||||
</div>
|
||||
<button
|
||||
onClick={onCancelReply}
|
||||
|
||||
@@ -293,8 +293,11 @@ export function FileCard({
|
||||
className="h-auto p-0 text-sm text-foreground !bg-transparent"
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{displayItem.createdAt && formatTimeAgo(displayItem.createdAt)} {m.by()}{' '}
|
||||
{displayItem.creator?.name}
|
||||
{displayItem.createdAt &&
|
||||
m.created_by_at({
|
||||
time: formatTimeAgo(displayItem.createdAt),
|
||||
author: displayItem.creator?.name || m.unknown_user(),
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
<DropdownMenu modal={false}>
|
||||
|
||||
@@ -383,6 +383,7 @@ export function FileBrowserToolbar({
|
||||
open={isMembersDialogOpen}
|
||||
onOpenChange={handleOpenMembersDialog}
|
||||
title={m.project_members()}
|
||||
type="project"
|
||||
members={members || []}
|
||||
isOwner={me?.role === 'owner'}
|
||||
onInvite={handleInvite}
|
||||
|
||||
@@ -44,6 +44,7 @@ interface MembersDialogProps {
|
||||
currentUserId?: string
|
||||
availableMembersToAdd?: Member[]
|
||||
onAddMember?: (userId: string, role: 'editor' | 'reviewer') => Promise<void>
|
||||
type?: 'project' | 'team'
|
||||
}
|
||||
|
||||
export function MembersDialog({
|
||||
@@ -58,6 +59,7 @@ export function MembersDialog({
|
||||
currentUserId,
|
||||
availableMembersToAdd,
|
||||
onAddMember,
|
||||
type = 'team',
|
||||
}: MembersDialogProps) {
|
||||
const [inviteRole, setInviteRole] = useState<'editor' | 'reviewer'>('editor')
|
||||
const [inviteLink, setInviteLink] = useState<string | null>(null)
|
||||
@@ -256,10 +258,7 @@ export function MembersDialog({
|
||||
<AlertDialogDescription>
|
||||
{m.remove_member_confirmation({
|
||||
name: memberToRemove?.name || '',
|
||||
type:
|
||||
title.toLowerCase().includes('project') || title.includes('项目')
|
||||
? m.project()
|
||||
: m.team(),
|
||||
type: type === 'project' ? m.project() : m.team(),
|
||||
})}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
|
||||
@@ -3,12 +3,35 @@ import { formatTimeAgo } from '@/ui/lib/time'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { SpriteScrubber } from './sprite-scrubber'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
import { getLocale } from '@/ui/paraglide/runtime.js'
|
||||
import React from 'react'
|
||||
|
||||
interface NotificationCardProps {
|
||||
notification: NotificationInfo
|
||||
}
|
||||
|
||||
const renderNotification = (
|
||||
messageTemplate: string,
|
||||
placeholders: Record<string, React.ReactNode>,
|
||||
) => {
|
||||
const regex = new RegExp(
|
||||
`(${Object.keys(placeholders)
|
||||
.map((k) => `\\{${k}\\}`)
|
||||
.join('|')})`,
|
||||
'g',
|
||||
)
|
||||
return (
|
||||
<span>
|
||||
{messageTemplate.split(regex).map((part, index) => {
|
||||
const match = part.match(/^\{(.+)\}$/)
|
||||
if (match && placeholders[match[1]]) {
|
||||
return <React.Fragment key={index}>{placeholders[match[1]]}</React.Fragment>
|
||||
}
|
||||
return part
|
||||
})}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
export const NotificationCard = ({ notification }: NotificationCardProps) => {
|
||||
const { creator, createdAt, isRead, type, asset, project, team, user } = notification
|
||||
|
||||
@@ -19,90 +42,52 @@ export const NotificationCard = ({ notification }: NotificationCardProps) => {
|
||||
const teamName = team?.name || m.unknown_team()
|
||||
const targetUserName = user?.name || m.unknown_user()
|
||||
|
||||
const isZh = getLocale() === 'zh'
|
||||
const creatorEl = <span className="font-semibold">{creatorName}</span>
|
||||
const assetEl = <span className="font-semibold">{assetName}</span>
|
||||
const projectEl = <span className="font-semibold">{projectName}</span>
|
||||
const teamEl = <span className="font-semibold">{teamName}</span>
|
||||
const userEl = <span className="font-semibold">{targetUserName}</span>
|
||||
const placeholders = {
|
||||
creator: <span className="font-semibold">{creatorName}</span>,
|
||||
asset: <span className="font-semibold">{assetName}</span>,
|
||||
project: <span className="font-semibold">{projectName}</span>,
|
||||
team: <span className="font-semibold">{teamName}</span>,
|
||||
user: <span className="font-semibold">{targetUserName}</span>,
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case 'comment_created':
|
||||
return isZh ? (
|
||||
<span>
|
||||
{creatorEl} 评论了 {assetEl}
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
{creatorEl} commented on {assetEl}
|
||||
</span>
|
||||
return renderNotification(
|
||||
m.notification_commented_on({ creator: '{creator}', asset: '{asset}' }),
|
||||
placeholders,
|
||||
)
|
||||
case 'reply_created':
|
||||
return isZh ? (
|
||||
<span>
|
||||
{creatorEl} 回复了 {assetEl} 上的评论
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
{creatorEl} replied to a comment on {assetEl}
|
||||
</span>
|
||||
return renderNotification(
|
||||
m.notification_replied_to({ creator: '{creator}', asset: '{asset}' }),
|
||||
placeholders,
|
||||
)
|
||||
case 'mention':
|
||||
return isZh ? (
|
||||
<span>
|
||||
{creatorEl} 在 {assetEl} 中提及了你
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
{creatorEl} mentioned you in {assetEl}
|
||||
</span>
|
||||
return renderNotification(
|
||||
m.notification_mentioned_you({ creator: '{creator}', asset: '{asset}' }),
|
||||
placeholders,
|
||||
)
|
||||
case 'successful_file_uploaded':
|
||||
return isZh ? (
|
||||
<span>
|
||||
{creatorEl} 将 {assetEl} 上传到 {projectEl}
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
{creatorEl} uploaded {assetEl} to {projectEl}
|
||||
</span>
|
||||
return renderNotification(
|
||||
m.notification_uploaded({ creator: '{creator}', asset: '{asset}', project: '{project}' }),
|
||||
placeholders,
|
||||
)
|
||||
case 'metadata_field_updated_status':
|
||||
return isZh ? (
|
||||
<span>
|
||||
{creatorEl} 更新了 {assetEl} 的状态
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
{creatorEl} updated status of {assetEl}
|
||||
</span>
|
||||
return renderNotification(
|
||||
m.notification_status_updated({ creator: '{creator}', asset: '{asset}' }),
|
||||
placeholders,
|
||||
)
|
||||
case 'new_user_join_team':
|
||||
return isZh ? (
|
||||
<span>
|
||||
{userEl} 加入了 {teamEl}
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
{userEl} joined {teamEl}
|
||||
</span>
|
||||
return renderNotification(
|
||||
m.notification_joined_team({ user: '{user}', team: '{team}' }),
|
||||
placeholders,
|
||||
)
|
||||
case 'new_user_join_project':
|
||||
return isZh ? (
|
||||
<span>
|
||||
{userEl} 加入了 {projectEl}
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
{userEl} joined {projectEl}
|
||||
</span>
|
||||
return renderNotification(
|
||||
m.notification_joined_project({ user: '{user}', project: '{project}' }),
|
||||
placeholders,
|
||||
)
|
||||
default:
|
||||
return isZh ? (
|
||||
<span>来自 {creatorEl} 的新通知</span>
|
||||
) : (
|
||||
<span>New notification from {creatorEl}</span>
|
||||
)
|
||||
return renderNotification(m.notification_generic({ creator: '{creator}' }), placeholders)
|
||||
}
|
||||
})()
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import { format, parseISO, isToday, isYesterday } from 'date-fns'
|
||||
import { Progress } from '@/ui/components/ui/progress'
|
||||
import { formatTimeAgo } from '@/ui/lib/time'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
import { getLocale } from '@/ui/paraglide/runtime.js'
|
||||
|
||||
function formatDayHeader(dateString: string): string {
|
||||
const date = parseISO(dateString)
|
||||
@@ -23,7 +22,7 @@ function formatDayHeader(dateString: string): string {
|
||||
if (isYesterday(date)) {
|
||||
return m.yesterday()
|
||||
}
|
||||
return format(date, getLocale() === 'zh' ? 'yyyy年M月d日' : 'MMMM d, yyyy')
|
||||
return format(date, m.date_format_long())
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
|
||||
Reference in New Issue
Block a user