mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 18:08:24 +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 {
|
||||
|
||||
@@ -813,5 +813,9 @@
|
||||
"yesterday_with_time": "Yesterday {time}",
|
||||
"n_items_singular": "{count} Item",
|
||||
"n_items_plural": "{count} Items",
|
||||
"fullscreen": "Fullscreen"
|
||||
"fullscreen": "Fullscreen",
|
||||
"created_by_at": "{time} by {author}",
|
||||
"date_format_long": "MMMM d, yyyy",
|
||||
"tool_result_with_name": "Tool Result: {name}",
|
||||
"reply_to_message": "reply to: {message}"
|
||||
}
|
||||
|
||||
@@ -813,5 +813,9 @@
|
||||
"yesterday_with_time": "昨天 {time}",
|
||||
"n_items_singular": "{count} 个项目",
|
||||
"n_items_plural": "{count} 个项目",
|
||||
"fullscreen": "全屏"
|
||||
"fullscreen": "全屏",
|
||||
"created_by_at": "{time} 由 {author} 创建",
|
||||
"date_format_long": "yyyy年M月d日",
|
||||
"tool_result_with_name": "工具结果:{name}",
|
||||
"reply_to_message": "回复:{message}"
|
||||
}
|
||||
|
||||
+4
@@ -761,4 +761,8 @@ export * from "./yesterday_with_time.js";
|
||||
export * from "./n_items_singular.js";
|
||||
export * from "./n_items_plural.js";
|
||||
export * from "./fullscreen.js";
|
||||
export * from "./created_by_at.js";
|
||||
export * from "./date_format_long.js";
|
||||
export * from "./tool_result_with_name.js";
|
||||
export * from "./reply_to_message.js";
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
|
||||
+5
-1
@@ -762,4 +762,8 @@ export * from './today_with_time.js'
|
||||
export * from './yesterday_with_time.js'
|
||||
export * from './n_items_singular.js'
|
||||
export * from './n_items_plural.js'
|
||||
export * from './fullscreen.js'
|
||||
export * from './fullscreen.js'
|
||||
export * from './created_by_at.js'
|
||||
export * from './date_format_long.js'
|
||||
export * from './tool_result_with_name.js'
|
||||
export * from './reply_to_message.js'
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "{time} by {author}" |
|
||||
*
|
||||
* @param {Created_By_AtInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const created_by_at: ((inputs: Created_By_AtInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Created_By_AtInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Created_By_AtInputs = {
|
||||
time: NonNullable<unknown>;
|
||||
author: NonNullable<unknown>;
|
||||
};
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{ time: NonNullable<unknown>, author: NonNullable<unknown> }} Created_By_AtInputs */
|
||||
|
||||
const en_created_by_at = /** @type {(inputs: Created_By_AtInputs) => LocalizedString} */ (i) => {
|
||||
return /** @type {LocalizedString} */ (`${i?.time} by ${i?.author}`)
|
||||
};
|
||||
|
||||
const zh_created_by_at = /** @type {(inputs: Created_By_AtInputs) => LocalizedString} */ (i) => {
|
||||
return /** @type {LocalizedString} */ (`${i?.time} 由 ${i?.author} 创建`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "{time} by {author}" |
|
||||
*
|
||||
* @param {Created_By_AtInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const created_by_at = /** @type {((inputs: Created_By_AtInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Created_By_AtInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_created_by_at(inputs)
|
||||
return zh_created_by_at(inputs)
|
||||
});
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "MMMM d, yyyy" |
|
||||
*
|
||||
* @param {Date_Format_LongInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const date_format_long: ((inputs?: Date_Format_LongInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Date_Format_LongInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Date_Format_LongInputs = {};
|
||||
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{}} Date_Format_LongInputs */
|
||||
|
||||
const en_date_format_long = /** @type {(inputs: Date_Format_LongInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`MMMM d, yyyy`)
|
||||
};
|
||||
|
||||
const zh_date_format_long = /** @type {(inputs: Date_Format_LongInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`yyyy年M月d日`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "MMMM d, yyyy" |
|
||||
*
|
||||
* @param {Date_Format_LongInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const date_format_long = /** @type {((inputs?: Date_Format_LongInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Date_Format_LongInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_date_format_long(inputs)
|
||||
return zh_date_format_long(inputs)
|
||||
});
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "reply to: {message}" |
|
||||
*
|
||||
* @param {Reply_To_MessageInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const reply_to_message: ((inputs: Reply_To_MessageInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Reply_To_MessageInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Reply_To_MessageInputs = {
|
||||
message: NonNullable<unknown>;
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{ message: NonNullable<unknown> }} Reply_To_MessageInputs */
|
||||
|
||||
const en_reply_to_message = /** @type {(inputs: Reply_To_MessageInputs) => LocalizedString} */ (i) => {
|
||||
return /** @type {LocalizedString} */ (`reply to: ${i?.message}`)
|
||||
};
|
||||
|
||||
const zh_reply_to_message = /** @type {(inputs: Reply_To_MessageInputs) => LocalizedString} */ (i) => {
|
||||
return /** @type {LocalizedString} */ (`回复:${i?.message}`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "reply to: {message}" |
|
||||
*
|
||||
* @param {Reply_To_MessageInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const reply_to_message = /** @type {((inputs: Reply_To_MessageInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Reply_To_MessageInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_reply_to_message(inputs)
|
||||
return zh_reply_to_message(inputs)
|
||||
});
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Tool Result: {name}" |
|
||||
*
|
||||
* @param {Tool_Result_With_NameInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const tool_result_with_name: ((inputs: Tool_Result_With_NameInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Tool_Result_With_NameInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Tool_Result_With_NameInputs = {
|
||||
name: NonNullable<unknown>;
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{ name: NonNullable<unknown> }} Tool_Result_With_NameInputs */
|
||||
|
||||
const en_tool_result_with_name = /** @type {(inputs: Tool_Result_With_NameInputs) => LocalizedString} */ (i) => {
|
||||
return /** @type {LocalizedString} */ (`Tool Result: ${i?.name}`)
|
||||
};
|
||||
|
||||
const zh_tool_result_with_name = /** @type {(inputs: Tool_Result_With_NameInputs) => LocalizedString} */ (i) => {
|
||||
return /** @type {LocalizedString} */ (`工具结果:${i?.name}`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Tool Result: {name}" |
|
||||
*
|
||||
* @param {Tool_Result_With_NameInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const tool_result_with_name = /** @type {((inputs: Tool_Result_With_NameInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Tool_Result_With_NameInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_tool_result_with_name(inputs)
|
||||
return zh_tool_result_with_name(inputs)
|
||||
});
|
||||
@@ -476,6 +476,7 @@ function TeamPage() {
|
||||
open={isMembersDialogOpen}
|
||||
onOpenChange={setIsMembersDialogOpen}
|
||||
title={m.team_members()}
|
||||
type="team"
|
||||
members={safeMembers}
|
||||
isOwner={me?.role === 'owner'}
|
||||
onInvite={handleInvite}
|
||||
|
||||
Reference in New Issue
Block a user