接口提示信息国际化

This commit is contained in:
whyour
2026-06-11 02:19:04 +08:00
parent 946731ac8d
commit 05f8fd3805
17 changed files with 206 additions and 26 deletions
+2 -1
View File
@@ -28,6 +28,7 @@ import dayjs from 'dayjs';
import pickBy from 'lodash/pickBy';
import omit from 'lodash/omit';
import { writeFileWithLock } from '../shared/utils';
import { t } from '../shared/i18n';
import { ScheduleType } from '../interface/schedule';
import { logStreamManager } from '../shared/logStreamManager';
@@ -550,7 +551,7 @@ export default class CronService {
where: { id: instanceId, status: InstanceStatus.running },
});
if (!instance) {
return { code: 400, message: '实例不存在或已停止' };
return { code: 400, message: t('实例不存在或已停止') };
}
if (instance.pid) {
try {
+28 -7
View File
@@ -37,6 +37,7 @@ import ScheduleService, { TaskCallbacks } from './schedule';
import SockService from './sock';
import os from 'os';
import dayjs from 'dayjs';
import { t, setLang } from '../shared/i18n';
import { updateLinuxMirrorFile } from '../config/util';
@Service()
@@ -87,7 +88,7 @@ export default class SystemService {
});
return { code: 200, data: { ...result, code } };
} else {
return { code: 400, message: '通知发送失败,请检查参数' };
return { code: 400, message: t('通知发送失败,请检查参数') };
}
}
@@ -381,9 +382,9 @@ export default class SystemService {
notificationInfo,
);
if (isSuccess) {
return { code: 200, message: '通知发送成功' };
return { code: 200, message: t('通知发送成功') };
} else {
return { code: 400, message: '通知发送失败,请检查系统设置/通知配置' };
return { code: 400, message: t('通知发送失败,请检查系统设置/通知配置') };
}
}
@@ -401,7 +402,7 @@ export default class SystemService {
public async stop({ command, pid }: { command: string; pid: number }) {
if (!pid && !command) {
return { code: 400, message: '参数错误' };
return { code: 400, message: t('参数错误') };
}
if (pid) {
@@ -417,7 +418,7 @@ export default class SystemService {
await killTask(_pid);
return { code: 200 };
} else {
return { code: 400, message: '任务未找到' };
return { code: 400, message: t('任务未找到') };
}
}
@@ -512,10 +513,30 @@ export default class SystemService {
if (success) {
return { code: 200, data: info };
} else {
return { code: 400, message: '设置时区失败' };
return { code: 400, message: t('设置时区失败') };
}
}
public async updateLanguage(info: SystemModelInfo) {
const oDoc = await this.getSystemConfig();
const lang = info.lang || 'zh';
await this.updateAuthDb({
...oDoc,
info: { ...oDoc.info, lang },
});
// Write to standalone lang_env.sh, sourced by shell scripts
try {
await fs.promises.writeFile(
config.langEnvFile,
`export QL_LANG='${lang}'\n`,
);
} catch (error) {
this.logger.error(`Failed to write lang_env.sh: ${error}`);
}
setLang(lang);
return { code: 200, data: { lang } };
}
public async updateGlobalSshKey(info: SystemModelInfo) {
const oDoc = await this.getSystemConfig();
const result = await this.updateAuthDb({
@@ -539,7 +560,7 @@ export default class SystemService {
public async cleanDependence(type: 'node' | 'python3') {
if (!type || !['node', 'python3'].includes(type)) {
return { code: 400, message: '参数错误' };
return { code: 400, message: t('参数错误') };
}
try {
const finalPath = path.join(config.dependenceCachePath, type);
+7 -6
View File
@@ -25,6 +25,7 @@ import uniq from 'lodash/uniq';
import pickBy from 'lodash/pickBy';
import isNil from 'lodash/isNil';
import { shareStore } from '../shared/store';
import { t } from '../shared/i18n';
@Service()
export default class UserService {
@@ -258,17 +259,17 @@ export default class UserService {
password: string;
}) {
if (password === 'admin') {
return { code: 400, message: '密码不能设置为admin' };
return { code: 400, message: t('密码不能设置为admin') };
}
const authInfo = await this.getAuthInfo();
await this.updateAuthInfo(authInfo, { username, password });
return { code: 200, message: '更新成功' };
return { code: 200, message: t('更新成功') };
}
public async updateAvatar(avatar: string) {
const authInfo = await this.getAuthInfo();
await this.updateAuthInfo(authInfo, { avatar });
return { code: 200, data: avatar, message: '更新成功' };
return { code: 200, data: avatar, message: t('更新成功') };
}
public async initTwoFactor() {
@@ -302,7 +303,7 @@ export default class UserService {
const authInfo = await this.getAuthInfo();
const { isTwoFactorChecking, twoFactorSecret } = authInfo;
if (!isTwoFactorChecking) {
return { code: 450, message: '未知错误' };
return { code: 450, message: t('未知错误') };
}
const isValid = authenticator.verify({
token: code,
@@ -326,7 +327,7 @@ export default class UserService {
lastaddr: address,
platform: req.platform,
});
return { code: 430, message: '验证失败' };
return { code: 430, message: t('验证失败') };
}
}
@@ -398,7 +399,7 @@ export default class UserService {
});
return { code: 200, data: { ...result, code } };
} else {
return { code: 400, message: '通知发送失败,请检查参数' };
return { code: 400, message: t('通知发送失败,请检查参数') };
}
}