mirror of
https://github.com/MCSManager/MCSManager.git
synced 2025-02-23 16:09:37 +08:00
Feat: Add i18 text
This commit is contained in:
parent
f3246d727d
commit
27965435b5
@ -1,7 +1,7 @@
|
||||
import i18next from "i18next";
|
||||
|
||||
const zh_cn = require("./language/zh_cn.json");
|
||||
const en_us = require("./language/en_us.json");
|
||||
import zh_cn from "./language/zh_cn";
|
||||
import en_us from "./language/en_us";
|
||||
|
||||
i18next.init({
|
||||
lng: "zh_cn",
|
||||
@ -16,9 +16,7 @@ i18next.init({
|
||||
}
|
||||
});
|
||||
|
||||
console.log(i18next.t("common.title"));
|
||||
console.log(i18next.t("common.title2"));
|
||||
|
||||
// alias
|
||||
const $t = i18next.t;
|
||||
|
||||
export { $t, i18next };
|
||||
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"common": {
|
||||
"title": "Title",
|
||||
"title2":"T2"
|
||||
}
|
||||
}
|
6
src/app/i18n/language/en_us.ts
Normal file
6
src/app/i18n/language/en_us.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export default {
|
||||
common: {
|
||||
title: "Title",
|
||||
title2: "T2"
|
||||
}
|
||||
};
|
@ -1,12 +0,0 @@
|
||||
{
|
||||
"common": {
|
||||
"title": "标题"
|
||||
},
|
||||
"app":{
|
||||
"panelStarted":"控制面板端已启动",
|
||||
"reference":"项目参考: https://github.com/mcsmanager",
|
||||
"host":"访问地址: http://localhost:{{port}}",
|
||||
"portTip":"软件公网访问需开放端口 {{port}} 与守护进程端口",
|
||||
"exitTip":"关闭此程序请使用 Ctrl+C 快捷键"
|
||||
}
|
||||
}
|
29
src/app/i18n/language/zh_cn.ts
Normal file
29
src/app/i18n/language/zh_cn.ts
Normal file
@ -0,0 +1,29 @@
|
||||
export default {
|
||||
common: {
|
||||
title: "标题"
|
||||
},
|
||||
// 模块名或者文件名
|
||||
// src\app.ts
|
||||
app: {
|
||||
panelStarted: "控制面板端已启动",
|
||||
reference: "项目参考: https://github.com/mcsmanager",
|
||||
host: "访问地址: http://localhost:{{port}}",
|
||||
portTip: "软件公网访问需开放端口 {{port}} 与守护进程端口",
|
||||
exitTip: "关闭此程序请使用 Ctrl+C 快捷键"
|
||||
},
|
||||
// src\app\middleware\permission.ts
|
||||
permission: {
|
||||
forbidden: "权限不足",
|
||||
forbiddenTokenError: "令牌(Token)验证失败,拒绝访问",
|
||||
xmlhttprequestError: "无法找到请求头 x-requested-with: xmlhttprequest",
|
||||
apiError: "密钥不正确"
|
||||
},
|
||||
// src\app\service\system_remote_service.ts
|
||||
systemRemoteService: {
|
||||
nodeCount: "已配置节点数: {{n}}",
|
||||
loadDaemonTitle: "正在尝试读取本地守护进程 {{localKeyFilePath}}",
|
||||
autoCheckDaemon: "检测到本地守护进程,正在自动获取密钥和端口...",
|
||||
error:
|
||||
"无法自动获取本地守护进程配置文件,请前往面板手动连接守护进程,前往 https://docs.mcsmanager.com/ 了解更多。"
|
||||
}
|
||||
};
|
@ -23,26 +23,27 @@ import Koa from "koa";
|
||||
import GlobalVariable from "../common/global_variable";
|
||||
import userSystem from "../service/system_user";
|
||||
import { getUuidByApiKey, ILLEGAL_ACCESS_KEY, isAjax } from "../service/passport_service";
|
||||
import { $t } from "../i18n";
|
||||
|
||||
// Failed callback
|
||||
function verificationFailed(ctx: Koa.ParameterizedContext) {
|
||||
ctx.status = 403;
|
||||
ctx.body = "[Forbidden] 权限不足";
|
||||
ctx.body = `[Forbidden] ${$t("permission.forbidden")}`;
|
||||
}
|
||||
|
||||
function tokenError(ctx: Koa.ParameterizedContext) {
|
||||
ctx.status = 403;
|
||||
ctx.body = "[Forbidden] 令牌(Token)验证失败,拒绝访问";
|
||||
ctx.body = `[Forbidden] ${$t("permission.forbiddenTokenError")}`;
|
||||
}
|
||||
|
||||
function ajaxError(ctx: Koa.ParameterizedContext) {
|
||||
ctx.status = 403;
|
||||
ctx.body = "[Forbidden] 无法找到请求头 x-requested-with: xmlhttprequest";
|
||||
ctx.body = `[Forbidden] ${$t("permission.xmlhttprequestError")}`;
|
||||
}
|
||||
|
||||
function apiError(ctx: Koa.ParameterizedContext) {
|
||||
ctx.status = 403;
|
||||
ctx.body = "[Forbidden] API 密钥不正确";
|
||||
ctx.body = `[Forbidden] ${$t("permission.apiError")}`;
|
||||
}
|
||||
|
||||
// 基本用户权限中间件
|
||||
|
@ -26,6 +26,7 @@ import { UniversalRemoteSubsystem } from "./base/urs";
|
||||
import StorageSubsystem from "../common/system_storage";
|
||||
import fs from "fs-extra";
|
||||
import path from "path";
|
||||
import { $t } from "../i18n";
|
||||
|
||||
// 远程服务管理子系统(RemoteServiceSubsystem)这个子系统将是最重要的系统之一
|
||||
// 主要功能是在所有地方存储远程服务
|
||||
@ -51,8 +52,7 @@ class RemoteServiceSubsystem extends UniversalRemoteSubsystem<RemoteService> {
|
||||
this.initConnectLocalhost("");
|
||||
}
|
||||
|
||||
logger.info(`远程服务子系统初始化完毕`);
|
||||
logger.info(`总计配置节点数: ${this.services.size}`);
|
||||
logger.info($t("systemRemoteService.nodeCount", { n: this.services.size }));
|
||||
|
||||
// 注册定期连接状态检查
|
||||
setInterval(() => this.connectionStatusCheckTask(), 1000 * 60);
|
||||
@ -111,23 +111,20 @@ class RemoteServiceSubsystem extends UniversalRemoteSubsystem<RemoteService> {
|
||||
const localKeyFilePath = path.normalize(
|
||||
path.join(process.cwd(), "../daemon/data/Config/global.json")
|
||||
);
|
||||
logger.info(`正在尝试读取本地守护进程: ${localKeyFilePath}`);
|
||||
logger.info($t("systemRemoteService.loadDaemonTitle", { localKeyFilePath }));
|
||||
if (fs.existsSync(localKeyFilePath)) {
|
||||
logger.info("检测到本地守护进程,正在自动获取密钥和端口...");
|
||||
logger.info($t("systemRemoteService.autoCheckDaemon"));
|
||||
const localDaemonConfig = JSON.parse(
|
||||
fs.readFileSync(localKeyFilePath, { encoding: "utf-8" })
|
||||
);
|
||||
const localKey = localDaemonConfig.key;
|
||||
const localPort = localDaemonConfig.port;
|
||||
logger.info("正在自动连接本地守护进程...");
|
||||
return this.registerRemoteService({ apiKey: localKey, port: localPort, ip });
|
||||
} else if (key) {
|
||||
const port = 24444;
|
||||
logger.info("无法自动获取本地守护进程配置文件,已发起连接但可能未经证实...");
|
||||
return this.registerRemoteService({ apiKey: key, port, ip });
|
||||
}
|
||||
logger.warn("无法自动获取本地守护进程配置文件,请前往面板手动连接守护进程");
|
||||
logger.warn("前往 https://docs.mcsmanager.com/ 了解更多。");
|
||||
logger.warn($t("systemRemoteService.error"));
|
||||
|
||||
// 5秒后判断是否已经连上守护进程,直到有一个守护进程连上
|
||||
setTimeout(() => {
|
||||
@ -150,7 +147,7 @@ class RemoteServiceSubsystem extends UniversalRemoteSubsystem<RemoteService> {
|
||||
this.services?.forEach((v) => {
|
||||
if (v && v.available === false) {
|
||||
logger.warn(
|
||||
`检测到守护进程 ${v.config.remarks} ${v.config.ip}:${v.config.port} 状态异常,正在重置并连接`
|
||||
`Daemon exception detected: ${v.config.remarks} ${v.config.ip}:${v.config.port}, reconnecting...`
|
||||
);
|
||||
return v.connect();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user