更新国际化文案

This commit is contained in:
whyour 2026-06-11 23:18:45 +08:00
parent 05f8fd3805
commit 6796068523
10 changed files with 26 additions and 13 deletions

View File

@ -83,10 +83,10 @@ export default (app: Router) => {
!path.startsWith(config.configPath) &&
!path.startsWith(config.scriptPath)
) {
return res.send({ code: 403, message: '文件路径无效' });
return res.send({ code: 403, message: t('文件路径无效') });
}
await writeFileWithLock(path, content);
res.send({ code: 200, message: '保存成功' });
res.send({ code: 200, message: t('保存成功') });
} catch (e) {
return next(e);
}

View File

@ -6,6 +6,7 @@ import config from '../config';
import SystemService from '../services/system';
import { celebrate, Joi } from 'celebrate';
import UserService from '../services/user';
import { t } from '../shared/i18n';
import {
getUniqPath,
handleLogPath,
@ -401,7 +402,7 @@ export default (app: Router) => {
try {
const userService = Container.get(UserService);
await userService.resetAuthInfo(req.body);
res.send({ code: 200, message: '更新成功' });
res.send({ code: 200, message: t('更新成功') });
} catch (e) {
return next(e);
}

View File

@ -8,6 +8,7 @@ import path from 'path';
import { v4 as uuidV4 } from 'uuid';
import rateLimit from 'express-rate-limit';
import config from '../config';
import { t } from '../shared/i18n';
import { isDemoEnv, getToken } from '../config/util';
const route = Router();
@ -76,11 +77,11 @@ export default (app: Router) => {
async (req: Request, res: Response, next: NextFunction) => {
try {
if (isDemoEnv()) {
return res.send({ code: 450, message: '未知错误' });
return res.send({ code: 450, message: t('未知错误') });
}
const userService = Container.get(UserService);
await userService.updateUsernameAndPassword(req.body);
res.send({ code: 200, message: '更新成功' });
res.send({ code: 200, message: t('更新成功') });
} catch (e) {
return next(e);
}
@ -229,7 +230,7 @@ export default (app: Router) => {
try {
const userService = Container.get(UserService);
await userService.updateUsernameAndPassword(req.body);
res.send({ code: 200, message: '更新成功' });
res.send({ code: 200, message: t('更新成功') });
} catch (e) {
return next(e);
}

View File

@ -11,6 +11,7 @@ import { serveEnv } from '../config/serverEnv';
import { IKeyvStore, shareStore } from '../shared/store';
import { isValidToken } from '../shared/auth';
import path from 'path';
import { t } from '../shared/i18n';
export default ({ app }: { app: Application }) => {
// Security: Enable strict routing to prevent case-insensitive path bypass
@ -143,7 +144,7 @@ export default ({ app }: { app: Application }) => {
}
if (isInitialized) {
return res.send({ code: 450, message: '未知错误' });
return res.send({ code: 450, message: t('未知错误') });
} else {
return next();
}

View File

@ -2,6 +2,7 @@ import { Service, Inject } from 'typedi';
import path, { join } from 'path';
import config from '../config';
import { getFileContentByName } from '../config/util';
import { t } from '../shared/i18n';
import { Response } from 'express';
import { request } from 'undici';
@ -23,7 +24,7 @@ export default class ConfigService {
) ||
!filePath
) {
return res.send({ code: 403, message: '文件无法访问' });
return res.send({ code: 403, message: t('文件无法访问') });
}
if (filePath.startsWith('sample/')) {

View File

@ -577,7 +577,7 @@ export default class CronService {
{ where: { id: instance.cron_id } },
);
}
return { code: 200, message: '实例已停止' };
return { code: 200, message: t('实例已停止') };
}
private async runSingle(cronId: number): Promise<number | void> {

View File

@ -3,6 +3,7 @@ import nodemailer from 'nodemailer';
import { Inject, Service } from 'typedi';
import { parseBody, parseHeaders } from '../config/util';
import { NotificationInfo } from '../data/notify';
import { t } from '../shared/i18n';
import UserService from './user';
import { httpClient } from '../config/http';
import { ProxyAgent } from 'undici';
@ -727,7 +728,7 @@ export default class NotificationService {
// topic_ids 和 uids 至少要有一个
if (!topicIds.length && !uids.length) {
throw new Error('wxPusher 服务的 TopicIds 和 Uids 至少配置一个才行');
throw new Error(t('wxPusher 服务的 TopicIds 和 Uids 至少配置一个才行'));
}
const url = `https://wxpusher.zjiecode.com/api/send/message`;
@ -823,7 +824,7 @@ export default class NotificationService {
} = this.params;
if (!webhookUrl?.includes('$title') && !webhookBody?.includes('$title')) {
throw new Error('Url 或者 Body 中必须包含 $title');
throw new Error(t('Url 或者 Body 中必须包含 $title'));
}
const headers = parseHeaders(webhookHeaders);

View File

@ -5,6 +5,7 @@ import { App, AppModel } from '../data/open';
import { v4 as uuidV4 } from 'uuid';
import sequelize, { Op } from 'sequelize';
import { shareStore } from '../shared/store';
import { t } from '../shared/i18n';
@Service()
export default class OpenService {
@ -151,7 +152,7 @@ export default class OpenService {
},
};
} else {
return { code: 400, message: 'client_id 或 client_seret 有误' };
return { code: 400, message: t('client_id 或 client_seret 有误') };
}
}

View File

@ -24,6 +24,7 @@ import path, { join } from 'path';
import ScheduleService, { TaskCallbacks } from './schedule';
import { SimpleIntervalSchedule } from 'toad-scheduler';
import SockService from './sock';
import { t } from '../shared/i18n';
import SshKeyService from './sshKey';
import dayjs from 'dayjs';
import { LOG_END_SYMBOL } from '../config/const';
@ -192,7 +193,7 @@ export default class SubscriptionService {
this.sockService.sendMessage({
type: 'runSubscriptionEnd',
message: '订阅执行完成',
message: t('订阅执行完成'),
references: [doc.id as number],
});
},

View File

@ -74,6 +74,12 @@ const messages: Record<string, Record<string, string>> = {
'用户名不能为admin': 'Username cannot be admin',
'不能删除自己': 'Cannot delete yourself',
'不能禁用自己': 'Cannot disable yourself',
'文件路径无效': 'Invalid file path',
'保存成功': 'Saved successfully',
'client_id 或 client_seret 有误': 'Invalid client_id or client_secret',
'订阅执行完成': 'Subscription completed',
'wxPusher 服务的 TopicIds 和 Uids 至少配置一个才行': 'wxPusher requires at least one of TopicIds or Uids',
'Url 或者 Body 中必须包含 $title': 'Url or Body must contain $title',
},
};