Files
gsfdc/demo-dify/dify/web/service/chinese-system-message.ts
T
wuzilongandCursor c2cb845a32 feat(dify): 把本地控制台的中文与去外链改动入库
这些界面改动和专家服务草稿停在工作区,没有随上一笔主分支提交进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-23 09:44:09 +08:00

293 lines
22 KiB
TypeScript

import Cookies from 'js-cookie'
import { getI18n } from 'react-i18next'
import { LOCALE_COOKIE_NAME } from '@/config'
const ZH_MESSAGES: Record<string, string> = {
'The specified filename does not exist.': '指定的文件名不存在。',
'Error uploading remote file.': '上传远程文件失败。',
'The remote file URL is invalid.': '远程文件地址无效。',
'The remote file URL is not allowed.': '不允许使用该远程文件地址。',
'The remote file could not be found.': '找不到该远程文件。',
'The remote file cannot be accessed without authorization.': '访问该远程文件需要授权。',
'The remote file is temporarily unavailable.': '远程文件暂时无法访问。',
'The remote file server returned an invalid response.': '远程文件服务器返回了无效响应。',
'File size exceeded. {message}': '文件超出大小限制。',
'File type not allowed.': '不允许上传该类型的文件。',
'The file extension is blocked for security reasons.': '出于安全原因,已禁止该文件扩展名。',
'Only one file is allowed.': '只能上传一个文件。',
'Please upload your file.': '请上传文件。',
'The conversation was not found for this user and app.': '找不到该用户在此应用中的对话。',
'The conversation cursor is not in the current list. Refresh the list and try again.': '当前列表中没有这条对话位置。请刷新列表后再试。',
'The conversation variable was not found for this conversation.': '找不到该对话中的变量。',
'The new value does not match the conversation variable\'s type.': '新的值与对话变量的类型不一致。',
'The conversation has no message from which to generate a name.': '这条对话还没有可用于生成名称的消息。',
'A rating is required when there is no existing feedback to remove.': '没有可取消的反馈时,需要先给出评分。',
'Authentication is required.': '请先登录。',
'You don\'t have the permission to access the requested resource.': '你没有访问该内容的权限。',
'The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.': '服务器处理这次请求时出错,暂时无法完成。请稍后重试。',
'Server Error': '服务器出错,请稍后重试。',
'Failed to fetch': '无法连接服务器,请检查网络后重试。',
'TypeError: Failed to fetch': '无法连接服务器,请检查网络后重试。',
'Network Error': '无法连接服务器,请检查网络后重试。',
'NetworkError when attempting to fetch resource.': '无法连接服务器,请检查网络后重试。',
'Load failed': '加载失败,请稍后重试。',
'App unavailable, please check your app configurations.': '应用暂不可用,请检查应用配置。',
'Agent has not been published. Please publish the Agent before using the web app.': '智能体尚未发布。请先发布后再使用网页应用。',
'Please check if your Completion app mode matches the right API route.': '请确认文本生成应用的模式与接口路径一致。',
'Please check if your app mode matches the right API route.': '请确认应用模式与接口路径一致。',
'Please check if your Workflow app mode matches the right API route.': '请确认工作流应用的模式与接口路径一致。',
'The conversation has ended. Please start a new conversation.': '这条对话已结束,请开始新的对话。',
'No valid model provider credentials found. Please go to Settings -> Model Provider to complete your provider credentials.': '没有可用的模型供应商凭证。请前往「设置 → 模型供应商」填写凭证。',
'Your quota for Dify Hosted OpenAI has been exhausted. Please go to Settings -> Model Provider to complete your own provider credentials.': '托管 OpenAI 的可用额度已用完。请前往「设置 → 模型供应商」填写自己的供应商凭证。',
'Dify Hosted OpenAI trial currently not support the GPT-4 model.': '托管 OpenAI 试用暂不支持 GPT-4 模型。',
'Completion request failed.': '文本生成请求失败。',
'The \'More like this\' feature is disabled. Please refresh your page.': '「类似内容」功能未开启。请刷新页面。',
'The \'Suggested Questions After Answer\' feature is disabled. Please refresh your page.': '「回答后推荐问题」功能未开启。请刷新页面。',
'Please upload your audio.': '请上传音频。',
'Audio size exceeded. {message}': '音频超出大小限制。',
'Audio type not allowed.': '不允许上传该类型的音频。',
'Provider not support speech to text.': '该供应商不支持语音转文字。',
'Speech to text is disabled.': '语音转文字未开启。',
'Web app authentication required.': '使用网页应用需要先登录。',
'You do not have permission to access this web app.': '你没有访问该网页应用的权限。',
'App not found.': '找不到该应用。',
'Web app access service is unavailable.': '网页应用访问服务暂不可用。',
'Rate Limit Error': '请求过于频繁。',
'Too many form requests. Please try again later.': '表单提交过于频繁,请稍后再试。',
'This feature requires a paid plan.': '此功能需要付费方案。',
'Dify has been successfully installed. Please refresh the page or return to the dashboard homepage.': '系统已安装完成。请刷新页面或返回首页。',
'Dify has not been initialized and installed yet. Please proceed with the initialization and installation process first.': '系统尚未初始化安装。请先完成初始化。',
'Init validation has not been completed yet. Please proceed with the init validation process first.': '初始化校验尚未完成。请先完成校验。',
'Init validation failed. Please check the password and try again.': '初始化校验失败。请核对密码后再试。',
'Account not link tenant.': '账号尚未加入工作区。',
'Auth Token is invalid or account already activated, please check again.': '验证令牌无效,或账号已激活,请再检查一次。',
'Workspace not found, please contact system admin to invite you to join in a workspace.': '找不到工作区。请联系管理员邀请你加入。',
'Unable to add member because the maximum workspace\'s member limit was exceeded': '已达到工作区成员上限,无法继续添加。',
'Unable to create workspace because the maximum workspace limit was exceeded': '已达到工作区数量上限,无法继续创建。',
'Unable to create account because the licensed seats limit was exceeded': '已达到授权席位上限,无法继续创建账号。',
'Account is banned.': '该账号已被停用。',
'Account not found.': '找不到该账号。',
'The password does not satisfy the account password policy.': '密码不符合账号密码规则。',
'Too many emails have been sent from this IP address recently. Please try again later.': '该 IP 近期发送的邮件过多,请稍后再试。',
'Unauthorized and force logout.': '登录已失效,请重新登录。',
'This email account has been deleted within the past 30 days and is temporarily unavailable for new account registration.': '该邮箱在过去 30 天内注销过,暂时不能用于注册新账号。',
'This email domain has been suspended.': '该邮箱域名已被停用。',
'Rate limit exceeded': '请求过于频繁。',
'We couldn\'t verify your education status.': '无法核验教育身份。',
'We couldn\'t activate your education discount.': '无法开通教育优惠。',
'The API key limit has been reached.': '已达到 API 密钥数量上限。',
'annotation_ids are required if the parameter is provided.': '传入该参数时必须提供标注编号。',
'Trigger not found.': '找不到该触发器。',
'Webhook trigger not found for this node.': '找不到该节点的 Webhook 触发器。',
'Your quota for Dify Hosted Model Provider has been exhausted. Please go to Settings -> Model Provider to complete your own provider credentials.': '托管模型供应商的可用额度已用完。请前往「设置 → 模型供应商」填写自己的供应商凭证。',
'Provider does not support text to speech.': '该供应商不支持文字转语音。',
'Draft workflow need to be initialized.': '需要先初始化草稿工作流。',
'Workflow graph might have been modified, please refresh and resubmit.': '工作流可能已被修改,请刷新后再提交。',
'Tracing configuration not found.': '找不到追踪配置。',
'A tracing configuration already exists for this provider.': '该供应商已有追踪配置。',
'The tracing provider is not supported.': '不支持该追踪供应商。',
'The tracing provider is not available in this deployment.': '当前部署不提供该追踪供应商。',
'The tracing configuration is invalid.': '追踪配置无效。',
'The tracing configuration could not be verified.': '无法校验追踪配置。',
'The tracing configuration could not be processed.': '无法处理追踪配置。',
'Need to add ids.': '需要添加编号。',
'No active sandbox binding.': '没有正在使用的沙箱绑定。',
'Sandbox inspector is unavailable.': '沙箱检查器暂不可用。',
'Sandbox file download is unavailable.': '沙箱文件暂时无法下载。',
'Agent backend is unreachable.': '无法连接智能体后端。',
'no agent is bound for this app/node': '该应用或节点尚未绑定智能体。',
'Tracing configuration changed. Refresh and try again.': '追踪配置已变化。请刷新后再试。',
'The data-source API-key authentication provider is not supported.': '不支持该数据源的 API 密钥认证。',
'The data-source API-key authentication credentials are invalid.': '数据源的 API 密钥凭证无效。',
'The data-source provider rejected the API-key authentication credentials.': '数据源供应商拒绝了该 API 密钥凭证。',
'The data-source API-key authentication provider is temporarily unavailable.': '数据源的 API 密钥认证暂时不可用。',
'The email address is not valid.': '邮箱地址无效。',
'This invitation was sent to another account. Please sign in with the invited account.': '该邀请发给了另一个账号。请使用受邀账号登录。',
'The passwords do not match.': '两次输入的密码不一致。',
'The token is invalid or has expired.': '令牌无效或已过期。',
'Email code is invalid or expired.': '邮箱验证码无效或已过期。',
'Email code verification is temporarily unavailable. Please try again later.': '邮箱验证码暂时无法校验,请稍后再试。',
'The email or password is mismatched.': '邮箱或密码不正确。',
'Invalid email or password.': '邮箱或密码不正确。',
'Too many incorrect password attempts. Please try again later.': '密码错误次数过多,请稍后再试。',
'Turnstile verification failed. Please try again.': '人机验证失败,请重试。',
'Turnstile verification is temporarily unavailable. Please try again later.': '人机验证暂时不可用,请稍后再试。',
'Too many failed password reset attempts. Please try again in 24 hours.': '重置密码失败次数过多,请 24 小时后再试。',
'Too many failed email register attempts. Please try again in 24 hours.': '邮箱注册失败次数过多,请 24 小时后再试。',
'Too many failed email change attempts. Please try again in 24 hours.': '更换邮箱失败次数过多,请 24 小时后再试。',
'A user with this email already exists.': '该邮箱已被注册。',
'An account with an equivalent email address already exists.': '已有使用相同邮箱的账号。',
'Too many failed owner transfer attempts. Please try again in 24 hours.': '转让所有者失败次数过多,请 24 小时后再试。',
'You are not the owner of the workspace.': '你不是该工作区的所有者。',
'You cannot transfer ownership to yourself.': '不能把所有权转让给自己。',
'The member is not in the workspace.': '该成员不在此工作区中。',
'The current workspace has been archived.': '当前工作区已归档。',
'New password and repeat password does not match.': '新密码与确认密码不一致。',
'Current password is incorrect.': '当前密码不正确。',
'Invalid invitation code.': '邀请码无效。',
'Invitation code is required.': '请填写邀请码。',
'The account has been initialized. Please refresh the page.': '账号已完成初始化。请刷新页面。',
'The account has not been initialized yet. Please proceed with the initialization process first.': '账号尚未初始化。请先完成初始化。',
'Invalid account deletion code.': '账号注销验证码无效。',
'Invalid role.': '角色无效。',
'Centrally managed IM bindings cannot be edited from a workspace.': '集中管理的即时通讯绑定不能在工作区里修改。',
'Workspace IM overrides require centrally managed bindings.': '工作区覆盖即时通讯设置前,需要先有集中管理的绑定。',
'Plugin operation failed.': '插件操作失败。',
'Invalid skill request.': '技能请求无效。',
'filename is required': '请填写文件名。',
'Cannot operate on yourself.': '不能对自己执行该操作。',
'Member not found.': '找不到该成员。',
'Role already assigned.': '该角色已经分配。',
'Invalid network access group request.': '网络访问组请求无效。',
'Network access groups are not available for this workspace.': '此工作区不提供网络访问组。',
'Network access group was not found.': '找不到该网络访问组。',
'The network access resource changed. Refresh it and try again.': '网络访问设置已变化。请刷新后再试。',
'An IP policy with this name already exists.': '已有同名的 IP 策略。',
'This IP policy is still used by one or more apps.': '仍有应用在使用该 IP 策略。',
'Your workspace role does not allow this network access operation.': '你的工作区角色不能执行该网络访问操作。',
'Network access control is not supported for this app mode.': '该应用模式不支持网络访问控制。',
'Some access points are not supported for this app.': '此应用不支持其中部分访问入口。',
'A Channel is already configured for this kind.': '该类型已经配置了渠道。',
'Channel not found.': '找不到该渠道。',
'The Channel configuration was updated.': '渠道配置已更新。',
'Explicit IM Channel replacement is required.': '需要明确替换即时通讯渠道。',
'The dataset is still being initialized or indexing. Please wait a moment.': '知识库仍在初始化或建立索引,请稍候。',
'One or more selected upgrade models are unavailable.': '所选的一个或多个升级模型不可用。',
'The archived document is not editable.': '已归档的文档不能编辑。',
'The dataset name already exists. Please modify your dataset name.': '知识库名称已存在,请修改名称。',
'Invalid action.': '操作无效。',
'Dataset access denied.': '没有访问该知识库的权限。',
'The document has been processed. Please refresh the page or go to the document details.': '文档已处理完成。请刷新页面或查看文档详情。',
'The document is being processed and cannot be edited.': '文档正在处理,暂时不能编辑。',
'The metadata content is incorrect. Please check and verify.': '元数据内容不正确,请核对后再试。',
'{message}': '请求没有完成。',
'Pipeline not found.': '找不到该流水线。',
'Agent config version not found.': '找不到该智能体配置版本。',
'The app was not found in this workspace.': '在此工作区中找不到该应用。',
'The app is not available in this app library.': '应用库中没有该应用。',
'The app list cursor is invalid. Refresh the list and try again.': '应用列表位置无效。请刷新列表后再试。',
'The app access service is unavailable. Try again later.': '应用访问服务暂不可用,请稍后再试。',
'The conversation was not found for this account and app.': '找不到该账号在此应用中的对话。',
'A name is required when automatic naming is disabled.': '关闭自动命名后,需要填写名称。',
'The message was not found for this account and app.': '找不到该账号在此应用中的消息。',
'The message cursor is not in this conversation. Refresh the list and try again.': '这条对话中没有该消息位置。请刷新列表后再试。',
'Not Completion App': '这不是文本生成应用。',
'App mode is invalid.': '应用模式无效。',
'Only support workflow app.': '仅支持工作流应用。',
'Function Suggested questions after answer disabled.': '回答后推荐问题功能未开启。',
'App access denied.': '没有访问该应用的权限。',
'Recommended app not found.': '找不到推荐应用。',
'The app preview site is unavailable.': '应用预览站暂不可用。',
'The app preview owner is unavailable.': '应用预览所有者暂不可用。',
'the app is not allowed to be trial.': '该应用不能试用。',
'The user has exceeded the trial app limit.': '已超过可试用的应用数量。',
'Trial app feature is not enabled.': '试用应用功能未开启。',
'Agent Knowledge Base was not found.': '找不到智能体知识库。',
'Agent Knowledge Base resource was not found.': '找不到智能体知识库中的资源。',
'Agent Knowledge Base operation is not available.': '智能体知识库操作暂不可用。',
'Agent Knowledge Base is unavailable.': '智能体知识库暂不可用。',
'Agent Knowledge Base request timed out.': '智能体知识库请求超时。',
'Agent Knowledge Base request is invalid.': '智能体知识库请求无效。',
'Agent Knowledge Base operation is not allowed.': '不允许执行该智能体知识库操作。',
'Agent Knowledge Base operation conflicts with the current resource state.': '智能体知识库操作与当前资源状态冲突。',
'Agent Knowledge Base request is too large.': '智能体知识库请求过大。',
'Agent Knowledge Base request was rejected.': '智能体知识库请求被拒绝。',
'Agent Knowledge Base request rate limit exceeded.': '智能体知识库请求过于频繁。',
'Rate limit exceeded for downloading compliance report.': '下载合规报告过于频繁。',
'The compliance document was not found.': '找不到该合规文档。',
'Your current plan does not allow downloading this compliance document.': '当前方案不能下载该合规文档。',
'A previous request is still being processed. Please try again shortly.': '上一条请求仍在处理,请稍后再试。',
'We couldn\'t complete this request. Please try again. If the problem persists, contact support.': '这次请求没有完成。请重试;如果仍然失败,请联系管理员。',
'This operation is temporarily unavailable. Please try again later.': '该操作暂时不可用,请稍后再试。',
'Subscription builder not initialized': '订阅配置尚未初始化。',
'Please fill in all required credentials': '请填写所有必填凭证。',
'Subscription builder not found': '找不到订阅配置。',
'SSO protocol is not supported.': '不支持该单点登录协议。',
'Verifying email failed': '邮箱验证失败。',
'Web Audio API is not supported in this browser': '当前浏览器不支持网页音频。',
'Audio element not found': '找不到音频。',
'Missing plugin metadata for GitHub update': '缺少用于 GitHub 更新的插件信息。',
'Invalid email format': '邮箱格式不正确。',
'tag name is empty': '标签名称不能为空。',
}
const ZH_PATTERNS: Array<{ pattern: RegExp, translate: (match: RegExpMatchArray) => string }> = [
{
pattern: /^File size exceeded\. ?(.*)$/,
translate: match => match[1] ? `文件超出大小限制。${match[1]}` : '文件超出大小限制。',
},
{
pattern: /^Audio size exceeded\. ?(.*)$/,
translate: match => match[1] ? `音频超出大小限制。${match[1]}` : '音频超出大小限制。',
},
{
pattern: /^Knowledge indexing estimate failed: ?(.*)$/,
translate: match => `知识库索引估算失败:${match[1]}`,
},
{
pattern: /^Create child chunk index failed: ?(.*)$/,
translate: match => `创建子分段索引失败:${match[1]}`,
},
{
pattern: /^Delete child chunk index failed: ?(.*)$/,
translate: match => `删除子分段索引失败:${match[1]}`,
},
{
pattern: /^Too many password reset emails have been sent\. Please try again in (.+) minutes\.?$/,
translate: match => `重置密码邮件发送过于频繁,请在 ${match[1]} 分钟后再试。`,
},
{
pattern: /^Too many email register emails have been sent\. Please try again in (.+) minutes\.?$/,
translate: match => `注册邮件发送过于频繁,请在 ${match[1]} 分钟后再试。`,
},
{
pattern: /^Too many email change emails have been sent\. Please try again in (.+) minutes\.?$/,
translate: match => `更换邮箱邮件发送过于频繁,请在 ${match[1]} 分钟后再试。`,
},
{
pattern: /^Too many owner transfer emails have been sent\. Please try again in (.+) minutes\.?$/,
translate: match => `转让所有者邮件发送过于频繁,请在 ${match[1]} 分钟后再试。`,
},
{
pattern: /^Too many login emails have been sent\. Please try again in (.+) minutes\.?$/,
translate: match => `登录邮件发送过于频繁,请在 ${match[1]} 分钟后再试。`,
},
{
pattern: /^Too many account deletion emails have been sent\. Please try again in (.+) minutes\.?$/,
translate: match => `注销账号邮件发送过于频繁,请在 ${match[1]} 分钟后再试。`,
},
]
function readLocale(): string {
try {
const language = getI18n()?.language
if (language)
return language
}
catch {
// i18next is not ready during the first paint.
}
if (typeof document === 'undefined')
return ''
return Cookies.get(LOCALE_COOKIE_NAME) ?? ''
}
export function isChineseLocale(locale?: string) {
return (locale ?? readLocale()).toLowerCase().startsWith('zh')
}
export function localizeSystemMessage(message: string, locale?: string) {
if (!isChineseLocale(locale))
return message
const normalized = message.replace(/\s+/g, ' ').trim()
const exact = ZH_MESSAGES[normalized]
if (exact)
return exact
for (const { pattern, translate } of ZH_PATTERNS) {
const match = pattern.exec(normalized)
if (match)
return translate(match)
}
return message
}