Feat: add preset language option

This commit is contained in:
unitwk 2022-11-04 11:43:08 +08:00
parent 141130a29f
commit ac08cae7d6
4 changed files with 21 additions and 14 deletions

1
.gitignore vendored
View File

@ -99,3 +99,4 @@ Note.txt
# IntelliJ IDEA project files
/.idea/*
language

View File

@ -1,8 +1,13 @@
// Copyright (C) 2022 MCSManager <mcsmanager-dev@outlook.com>
import http from "http";
import fs from "fs-extra";
import { $t, i18next } from "./i18n";
import { getVersion, initVersionManager } from "./service/version";
import { globalConfiguration } from "./entity/config";
import { Server, Socket } from "socket.io";
import { LOCAL_PRESET_LANG_PATH } from "./const";
import logger from "./service/log";
initVersionManager();
const VERSION = getVersion();
@ -18,25 +23,22 @@ __ / / / __ / _ \\_ __ __ \\ __ \\_ __ \\
_ /_/ // /_/ // __/ / / / / / /_/ / / / /
/_____/ \\__,_/ \\___//_/ /_/ /_/\\____//_/ /_/
+ Copyright 2022 MCSManager Dev <mcsmanager-dev@outlook.com>
+ Copyright 2022 MCSManager Dev <https://github.com/mcsmanager>
+ Version ${VERSION}
`);
import http from "http";
import { Server, Socket } from "socket.io";
import logger from "./service/log";
// Initialize the global configuration service
globalConfiguration.load();
const config = globalConfiguration.config;
// If language is not configured, get the system language
const lang = config.language || "en_us";
logger.info(`LANGUAGE: ${lang}`);
i18next.changeLanguage(lang);
// set language
if (fs.existsSync(LOCAL_PRESET_LANG_PATH)) {
i18next.changeLanguage(fs.readFileSync(LOCAL_PRESET_LANG_PATH, "utf-8"));
} else {
const lang = config.language || "en_us";
logger.info(`LANGUAGE: ${lang}`);
i18next.changeLanguage(lang);
}
logger.info($t("app.welcome"));
import * as router from "./service/router";
@ -55,7 +57,7 @@ const koaApp = koa.initKoa();
// Listen for Koa errors
koaApp.on("error", (error) => {
// Block all Koa framework level events
// Block all Koa framework error
// When Koa is attacked by a short connection flood, it is easy for error messages to swipe the screen, which may indirectly affect the operation of some applications
});

View File

@ -9,5 +9,6 @@ const PTY_PATH = path.normalize(path.join(process.cwd(), "lib", ptyName));
const FILENAME_BLACKLIST = ["\\", "/", ".", "'", '"', "?", "*", "<", ">"];
const LOCAL_PRESET_LANG_PATH = path.normalize(path.join(process.cwd(), "language"));
export { FILENAME_BLACKLIST, PTY_PATH };
export { FILENAME_BLACKLIST, PTY_PATH, LOCAL_PRESET_LANG_PATH };

View File

@ -10,6 +10,8 @@ import { getVersion } from "../service/version";
import { globalConfiguration } from "../entity/config";
import i18next from "i18next";
import logger from "../service/log";
import fs from "fs-extra";
import { LOCAL_PRESET_LANG_PATH } from "../const";
// Get the basic information of the daemon system
routerApp.on("info/overview", async (ctx) => {
@ -41,6 +43,7 @@ routerApp.on("info/setting", async (ctx, data) => {
try {
logger.warn("Language change:", language);
i18next.changeLanguage(language);
fs.remove(LOCAL_PRESET_LANG_PATH, () => {});
globalConfiguration.config.language = language;
globalConfiguration.store();
protocol.response(ctx, true);