From 77ed2d77e10ee4832dfce736e393d1210fb4522f Mon Sep 17 00:00:00 2001 From: kkumar-gcc Date: Mon, 22 Apr 2024 13:51:53 +0530 Subject: [PATCH 01/12] setup basic translations --- app/console/commands/cert_renew.go | 6 ++- app/console/commands/monitoring.go | 6 ++- app/console/commands/panel.go | 60 +++++++++++---------- app/console/commands/panel_task.go | 6 ++- config/app.go | 4 +- lang/en.json | 85 ++++++++++++++++++++++++++++++ lang/zh_CN.json | 85 ++++++++++++++++++++++++++++++ panel-example.conf | 1 + 8 files changed, 218 insertions(+), 35 deletions(-) create mode 100644 lang/en.json create mode 100644 lang/zh_CN.json diff --git a/app/console/commands/cert_renew.go b/app/console/commands/cert_renew.go index d9566c90..70806061 100644 --- a/app/console/commands/cert_renew.go +++ b/app/console/commands/cert_renew.go @@ -1,6 +1,7 @@ package commands import ( + "context" "crypto/x509" "encoding/pem" @@ -25,7 +26,8 @@ func (receiver *CertRenew) Signature() string { // Description The console command description. func (receiver *CertRenew) Description() string { - return "[面板] 证书续签" + ctx := context.Background() + return facades.Lang(ctx).Get("panel:cert-renew.description") } // Extend The console command extend. @@ -36,7 +38,7 @@ func (receiver *CertRenew) Extend() command.Extend { } // Handle Execute the console command. -func (receiver *CertRenew) Handle(ctx console.Context) error { +func (receiver *CertRenew) Handle(console.Context) error { if internal.Status != internal.StatusNormal { return nil } diff --git a/app/console/commands/monitoring.go b/app/console/commands/monitoring.go index 57a73974..869da0bf 100644 --- a/app/console/commands/monitoring.go +++ b/app/console/commands/monitoring.go @@ -1,6 +1,7 @@ package commands import ( + "context" "strconv" "github.com/gookit/color" @@ -27,7 +28,8 @@ func (receiver *Monitoring) Signature() string { // Description The console command description. func (receiver *Monitoring) Description() string { - return "[面板] 系统监控" + ctx := context.Background() + return facades.Lang(ctx).Get("panel:monitoring.description") } // Extend The console command extend. @@ -38,7 +40,7 @@ func (receiver *Monitoring) Extend() command.Extend { } // Handle Execute the console command. -func (receiver *Monitoring) Handle(ctx console.Context) error { +func (receiver *Monitoring) Handle(console.Context) error { if internal.Status != internal.StatusNormal { return nil } diff --git a/app/console/commands/panel.go b/app/console/commands/panel.go index 0b041406..f9c05b2a 100644 --- a/app/console/commands/panel.go +++ b/app/console/commands/panel.go @@ -1,6 +1,7 @@ package commands import ( + "context" "fmt" "os" "path/filepath" @@ -31,7 +32,8 @@ func (receiver *Panel) Signature() string { // Description The console command description. func (receiver *Panel) Description() string { - return "[面板] 命令行" + ctx := context.Background() + return facades.Lang(ctx).Get("panel.description") } // Extend The console command extend. @@ -50,6 +52,8 @@ func (receiver *Panel) Handle(ctx console.Context) error { arg4 := ctx.Argument(4) arg5 := ctx.Argument(5) + translate := facades.Lang(context.Background()) + switch action { case "init": var check models.User @@ -159,10 +163,10 @@ func (receiver *Panel) Handle(ctx console.Context) error { return nil } - color.Greenln("面板端口: " + port) + color.Greenln(translate.Get("panel.getPort.port") + ": " + port) case "getEntrance": - color.Greenln("面板入口: " + facades.Config().GetString("http.entrance")) + color.Greenln(translate.Get("panel.getEntrance.entrance") + ": " + facades.Config().GetString("http.entrance")) case "deleteEntrance": oldEntrance, err := tools.Exec(`cat /www/panel/panel.conf | grep APP_ENTRANCE | awk -F '=' '{print $2}' | tr -d '\n'`) @@ -687,31 +691,31 @@ func (receiver *Panel) Handle(ctx console.Context) error { color.Greenln("任务已提交") default: - color.Yellowln(facades.Config().GetString("panel.name") + "命令行工具 - " + facades.Config().GetString("panel.version")) - color.Greenln("请使用以下命令:") - color.Greenln("panel update 更新 / 修复面板到最新版本") - color.Greenln("panel getInfo 重新初始化面板账号信息") - color.Greenln("panel getPort 获取面板访问端口") - color.Greenln("panel getEntrance 获取面板访问入口") - color.Greenln("panel deleteEntrance 删除面板访问入口") - color.Greenln("panel cleanTask 清理面板运行中和等待中的任务[任务卡住时使用]") - color.Greenln("panel backup {website/mysql/postgresql} {name} {path} {save_copies} 备份网站 / MySQL数据库 / PostgreSQL数据库到指定目录并保留指定数量") - color.Greenln("panel cutoff {website_name} {save_copies} 切割网站日志并保留指定数量") - color.Greenln("panel installPlugin {slug} 安装插件") - color.Greenln("panel uninstallPlugin {slug} 卸载插件") - color.Greenln("panel updatePlugin {slug} 更新插件") - color.Greenln("panel addSite {name} {domain} {port} {path} {php} 添加网站[域名和端口用英文逗号分隔]") - color.Greenln("panel removeSite {name} 删除网站") - color.Redln("以下命令请在开发者指导下使用:") - color.Yellowln("panel init 初始化面板") - color.Yellowln("panel writePlugin {slug} {version} 写入插件安装状态") - color.Yellowln("panel deletePlugin {slug} 移除插件安装状态") - color.Yellowln("panel writeMysqlPassword {password} 写入MySQL root密码") - color.Yellowln("panel writeSite {name} {status} {path} {php} {ssl} 写入网站数据到面板") - color.Yellowln("panel deleteSite {name} 删除面板网站数据") - color.Yellowln("panel getSetting {name} 获取面板设置数据") - color.Yellowln("panel writeSetting {name} {value} 写入 / 更新面板设置数据") - color.Yellowln("panel deleteSetting {name} 删除面板设置数据") + color.Yellowln(facades.Config().GetString("panel.name") + " - " + translate.Get("panel.cmd_tool") + " - " + facades.Config().GetString("panel.version")) + color.Greenln(translate.Get("panel.use_commands") + ":") + color.Greenln("panel update " + translate.Get("panel.update.description")) + color.Greenln("panel getInfo " + translate.Get("panel.getInfo.description")) + color.Greenln("panel getPort " + translate.Get("panel.getPort.description")) + color.Greenln("panel getEntrance " + translate.Get("panel.getEntrance.description")) + color.Greenln("panel deleteEntrance " + translate.Get("panel.deleteEntrance.description")) + color.Greenln("panel cleanTask " + translate.Get("panel.cleanTask.description")) + color.Greenln("panel backup {website/mysql/postgresql} {name} {path} {save_copies} " + translate.Get("panel.backup.description")) + color.Greenln("panel cutoff {website_name} {save_copies} " + translate.Get("panel.cutoff.description")) + color.Greenln("panel installPlugin {slug} " + translate.Get("panel.installPlugin.description")) + color.Greenln("panel uninstallPlugin {slug} " + translate.Get("panel.uninstallPlugin.description")) + color.Greenln("panel updatePlugin {slug} " + translate.Get("panel.updatePlugin.description")) + color.Greenln("panel addSite {name} {domain} {port} {path} {php} " + translate.Get("panel.addSite.description")) + color.Greenln("panel removeSite {name} " + translate.Get("panel.removeSite.description")) + color.Redln(translate.Get("panel.developer_guidance") + ":") + color.Yellowln("panel init " + translate.Get("panel.init.description")) + color.Yellowln("panel writePlugin {slug} {version} " + translate.Get("panel.writePlugin.description")) + color.Yellowln("panel deletePlugin {slug} " + translate.Get("panel.deletePlugin.description")) + color.Yellowln("panel writeMysqlPassword {password} " + translate.Get("panel.writeMysqlPassword.description")) + color.Yellowln("panel writeSite {name} {status} {path} {php} {ssl} " + translate.Get("panel.writeSite.description")) + color.Yellowln("panel deleteSite {name} " + translate.Get("panel.deleteSite.description")) + color.Yellowln("panel getSetting {name} " + translate.Get("panel.getSetting.description")) + color.Yellowln("panel writeSetting {name} {value} " + translate.Get("panel.writeSetting.description")) + color.Yellowln("panel deleteSetting {name} " + translate.Get("panel.deleteSetting.description")) } return nil diff --git a/app/console/commands/panel_task.go b/app/console/commands/panel_task.go index d7fe2493..e07592ab 100644 --- a/app/console/commands/panel_task.go +++ b/app/console/commands/panel_task.go @@ -1,6 +1,8 @@ package commands import ( + "context" + "github.com/goravel/framework/contracts/console" "github.com/goravel/framework/contracts/console/command" "github.com/goravel/framework/facades" @@ -21,7 +23,7 @@ func (receiver *PanelTask) Signature() string { // Description The console command description. func (receiver *PanelTask) Description() string { - return "[面板] 每日任务" + return facades.Lang(context.Background()).Get("panel:task.description") } // Extend The console command extend. @@ -32,7 +34,7 @@ func (receiver *PanelTask) Extend() command.Extend { } // Handle Execute the console command. -func (receiver *PanelTask) Handle(ctx console.Context) error { +func (receiver *PanelTask) Handle(console.Context) error { internal.Status = internal.StatusMaintain // 优化数据库 diff --git a/config/app.go b/config/app.go index 2c9e0103..65588695 100644 --- a/config/app.go +++ b/config/app.go @@ -19,6 +19,7 @@ import ( "github.com/goravel/framework/schedule" "github.com/goravel/framework/support/carbon" "github.com/goravel/framework/testing" + "github.com/goravel/framework/translation" "github.com/goravel/framework/validation" "github.com/goravel/gin" @@ -60,7 +61,7 @@ func init() { // The application locale determines the default locale that will be used // by the translation service provider.You are free to set this value // to any of the locales which will be supported by the application. - "locale": "zh_CN", + "locale": config.Env("APP_LOCALE", "zh_CN"), // Application Fallback Locale // @@ -96,6 +97,7 @@ func init() { &crypt.ServiceProvider{}, &filesystem.ServiceProvider{}, &validation.ServiceProvider{}, + &translation.ServiceProvider{}, &testing.ServiceProvider{}, &providers.AppServiceProvider{}, &providers.AuthServiceProvider{}, diff --git a/lang/en.json b/lang/en.json new file mode 100644 index 00000000..42998091 --- /dev/null +++ b/lang/en.json @@ -0,0 +1,85 @@ +{ + "panel:cert-renew": { + "description": "[Panel] Certificate renewal" + }, + "panel:monitoring": { + "description": "[Panel] System Monitoring" + }, + "panel": { + "description": "[Panel] Command line", + "developer_guidance": "Please use the following commands under the guidance of the developer", + "use_commands": "Please use the following commands", + "cmd_tool": "command line tool", + "update": { + "description": "update/fix panel to latest version" + }, + "getInfo": { + "description": "reinitialize panel account information" + }, + "getPort": { + "description": "get the panel access port", + "port": "panel port" + }, + "getEntrance": { + "description": "get panel access", + "entrance": "entrance" + }, + "deleteEntrance": { + "description": "delete panel access" + }, + "cleanTask": { + "description": "clean up running and waiting tasks in the panel [used when tasks are stuck]" + }, + "backup": { + "description": "back up website/MySQL database/PostgreSQL database to the specified directory and retain the specified amount" + }, + "cutoff": { + "description": "cut website logs and keep specified amount" + }, + "installPlugin": { + "description": "install plugin" + }, + "uninstallPlugin": { + "description": "uninstall plugin" + }, + "updatePlugin": { + "description": "update plugin" + }, + "addSite": { + "description": "add website [domain name and port separated by commas]" + }, + "removeSite": { + "description": "remove website" + }, + "init": { + "description": "initialize the panel" + }, + "writePlugin": { + "description": "write plugin installation status" + }, + "deletePlugin": { + "description": "delete plugin installation status" + }, + "writeMysqlPassword": { + "description": "write MySQL root password" + }, + "writeSite": { + "description": "write website data to the panel" + }, + "deleteSite": { + "description": "delete panel website data" + }, + "getSetting": { + "description": "get panel setting data" + }, + "writeSetting": { + "description": "write/update panel setting data" + }, + "deleteSetting": { + "description": "delete panel setting data" + } + }, + "panel:task": { + "description": "[Panel] Daily tasks" + } +} \ No newline at end of file diff --git a/lang/zh_CN.json b/lang/zh_CN.json new file mode 100644 index 00000000..36d157f6 --- /dev/null +++ b/lang/zh_CN.json @@ -0,0 +1,85 @@ +{ + "panel:cert-renew": { + "description": "[面板] 证书续签" + }, + "panel:monitoring": { + "description": "[面板] 系统监控" + }, + "panel": { + "description": "[面板] 命令行", + "developer_guidance": "以下命令请在开发者指导下使用", + "use_commands": "请使用以下命令", + "cmd_tool": "命令行工具", + "update": { + "description": "更新 / 修复面板到最新版本" + }, + "getInfo": { + "description": "重新初始化面板账号信息" + }, + "getPort": { + "description": "获取面板访问端口", + "port": "面板端口" + }, + "getEntrance": { + "description": "获取面板访问入口", + "entrance": "面板入口" + }, + "deleteEntrance": { + "description": "删除面板访问入口" + }, + "cleanTask": { + "description": "清理面板运行中和等待中的任务[任务卡住时使用]" + }, + "backup": { + "description": "备份网站 / MySQL数据库 / PostgreSQL数据库到指定目录并保留指定数量" + }, + "cutoff": { + "description": "切割网站日志并保留指定数量" + }, + "installPlugin": { + "description": "安装插件" + }, + "uninstallPlugin": { + "description": "卸载插件" + }, + "updatePlugin": { + "description": "更新插件" + }, + "addSite": { + "description": "添加网站[域名和端口用英文逗号分隔]" + }, + "removeSite": { + "description": "删除网站" + }, + "init": { + "description": "初始化面板" + }, + "writePlugin": { + "description": "写入插件安装状态" + }, + "deletePlugin": { + "description": "移除插件安装状态" + }, + "writeMysqlPassword": { + "description": "写入MySQL root密码" + }, + "writeSite": { + "description": "写入网站数据到面板" + }, + "deleteSite": { + "description": "删除面板网站数据" + }, + "getSetting": { + "description": "获取面板设置数据" + }, + "writeSetting": { + "description": "写入 / 更新面板设置数据" + }, + "deleteSetting": { + "description": "删除面板设置数据" + } + }, + "panel:task": { + "description": "[面板] 每日任务" + } +} \ No newline at end of file diff --git a/panel-example.conf b/panel-example.conf index b2c70f69..160b253f 100644 --- a/panel-example.conf +++ b/panel-example.conf @@ -4,5 +4,6 @@ APP_DEBUG=false APP_PORT=8888 APP_ENTRANCE=/ APP_SSL=false +APP_LOCALE= JWT_SECRET= From c0310d916f2bf589dab1905a61799dfcd7539f5c Mon Sep 17 00:00:00 2001 From: kkumar-gcc Date: Mon, 22 Apr 2024 20:01:17 +0530 Subject: [PATCH 02/12] add `commands` prefix for command translation --- app/console/commands/cert_renew.go | 2 +- app/console/commands/monitoring.go | 2 +- app/console/commands/panel.go | 56 +++++----- app/console/commands/panel_task.go | 2 +- lang/en.json | 158 +++++++++++++++-------------- lang/zh_CN.json | 158 +++++++++++++++-------------- 6 files changed, 191 insertions(+), 187 deletions(-) diff --git a/app/console/commands/cert_renew.go b/app/console/commands/cert_renew.go index 70806061..845aa453 100644 --- a/app/console/commands/cert_renew.go +++ b/app/console/commands/cert_renew.go @@ -27,7 +27,7 @@ func (receiver *CertRenew) Signature() string { // Description The console command description. func (receiver *CertRenew) Description() string { ctx := context.Background() - return facades.Lang(ctx).Get("panel:cert-renew.description") + return facades.Lang(ctx).Get("commands.panel:cert-renew.description") } // Extend The console command extend. diff --git a/app/console/commands/monitoring.go b/app/console/commands/monitoring.go index 869da0bf..3eeb28e5 100644 --- a/app/console/commands/monitoring.go +++ b/app/console/commands/monitoring.go @@ -29,7 +29,7 @@ func (receiver *Monitoring) Signature() string { // Description The console command description. func (receiver *Monitoring) Description() string { ctx := context.Background() - return facades.Lang(ctx).Get("panel:monitoring.description") + return facades.Lang(ctx).Get("commands.panel:monitoring.description") } // Extend The console command extend. diff --git a/app/console/commands/panel.go b/app/console/commands/panel.go index f9c05b2a..fa8f7ded 100644 --- a/app/console/commands/panel.go +++ b/app/console/commands/panel.go @@ -33,7 +33,7 @@ func (receiver *Panel) Signature() string { // Description The console command description. func (receiver *Panel) Description() string { ctx := context.Background() - return facades.Lang(ctx).Get("panel.description") + return facades.Lang(ctx).Get("commands.panel.description") } // Extend The console command extend. @@ -163,10 +163,10 @@ func (receiver *Panel) Handle(ctx console.Context) error { return nil } - color.Greenln(translate.Get("panel.getPort.port") + ": " + port) + color.Greenln(translate.Get("commands.panel.getPort.port") + ": " + port) case "getEntrance": - color.Greenln(translate.Get("panel.getEntrance.entrance") + ": " + facades.Config().GetString("http.entrance")) + color.Greenln(translate.Get("commands.panel.getEntrance.entrance") + ": " + facades.Config().GetString("http.entrance")) case "deleteEntrance": oldEntrance, err := tools.Exec(`cat /www/panel/panel.conf | grep APP_ENTRANCE | awk -F '=' '{print $2}' | tr -d '\n'`) @@ -691,31 +691,31 @@ func (receiver *Panel) Handle(ctx console.Context) error { color.Greenln("任务已提交") default: - color.Yellowln(facades.Config().GetString("panel.name") + " - " + translate.Get("panel.cmd_tool") + " - " + facades.Config().GetString("panel.version")) - color.Greenln(translate.Get("panel.use_commands") + ":") - color.Greenln("panel update " + translate.Get("panel.update.description")) - color.Greenln("panel getInfo " + translate.Get("panel.getInfo.description")) - color.Greenln("panel getPort " + translate.Get("panel.getPort.description")) - color.Greenln("panel getEntrance " + translate.Get("panel.getEntrance.description")) - color.Greenln("panel deleteEntrance " + translate.Get("panel.deleteEntrance.description")) - color.Greenln("panel cleanTask " + translate.Get("panel.cleanTask.description")) - color.Greenln("panel backup {website/mysql/postgresql} {name} {path} {save_copies} " + translate.Get("panel.backup.description")) - color.Greenln("panel cutoff {website_name} {save_copies} " + translate.Get("panel.cutoff.description")) - color.Greenln("panel installPlugin {slug} " + translate.Get("panel.installPlugin.description")) - color.Greenln("panel uninstallPlugin {slug} " + translate.Get("panel.uninstallPlugin.description")) - color.Greenln("panel updatePlugin {slug} " + translate.Get("panel.updatePlugin.description")) - color.Greenln("panel addSite {name} {domain} {port} {path} {php} " + translate.Get("panel.addSite.description")) - color.Greenln("panel removeSite {name} " + translate.Get("panel.removeSite.description")) - color.Redln(translate.Get("panel.developer_guidance") + ":") - color.Yellowln("panel init " + translate.Get("panel.init.description")) - color.Yellowln("panel writePlugin {slug} {version} " + translate.Get("panel.writePlugin.description")) - color.Yellowln("panel deletePlugin {slug} " + translate.Get("panel.deletePlugin.description")) - color.Yellowln("panel writeMysqlPassword {password} " + translate.Get("panel.writeMysqlPassword.description")) - color.Yellowln("panel writeSite {name} {status} {path} {php} {ssl} " + translate.Get("panel.writeSite.description")) - color.Yellowln("panel deleteSite {name} " + translate.Get("panel.deleteSite.description")) - color.Yellowln("panel getSetting {name} " + translate.Get("panel.getSetting.description")) - color.Yellowln("panel writeSetting {name} {value} " + translate.Get("panel.writeSetting.description")) - color.Yellowln("panel deleteSetting {name} " + translate.Get("panel.deleteSetting.description")) + color.Yellowln(facades.Config().GetString("panel.name") + " - " + translate.Get("commands.panel.tool") + " - " + facades.Config().GetString("panel.version")) + color.Greenln(translate.Get("commands.panel.use") + ":") + color.Greenln("panel update " + translate.Get("commands.panel.update.description")) + color.Greenln("panel getInfo " + translate.Get("commands.panel.getInfo.description")) + color.Greenln("panel getPort " + translate.Get("commands.panel.getPort.description")) + color.Greenln("panel getEntrance " + translate.Get("commands.panel.getEntrance.description")) + color.Greenln("panel deleteEntrance " + translate.Get("commands.panel.deleteEntrance.description")) + color.Greenln("panel cleanTask " + translate.Get("commands.panel.cleanTask.description")) + color.Greenln("panel backup {website/mysql/postgresql} {name} {path} {save_copies} " + translate.Get("commands.panel.backup.description")) + color.Greenln("panel cutoff {website_name} {save_copies} " + translate.Get("commands.panel.cutoff.description")) + color.Greenln("panel installPlugin {slug} " + translate.Get("commands.panel.installPlugin.description")) + color.Greenln("panel uninstallPlugin {slug} " + translate.Get("commands.panel.uninstallPlugin.description")) + color.Greenln("panel updatePlugin {slug} " + translate.Get("commands.panel.updatePlugin.description")) + color.Greenln("panel addSite {name} {domain} {port} {path} {php} " + translate.Get("commands.panel.addSite.description")) + color.Greenln("panel removeSite {name} " + translate.Get("commands.panel.removeSite.description")) + color.Redln(translate.Get("commands.panel.forDeveloper") + ":") + color.Yellowln("panel init " + translate.Get("commands.panel.init.description")) + color.Yellowln("panel writePlugin {slug} {version} " + translate.Get("commands.panel.writePlugin.description")) + color.Yellowln("panel deletePlugin {slug} " + translate.Get("commands.panel.deletePlugin.description")) + color.Yellowln("panel writeMysqlPassword {password} " + translate.Get("commands.panel.writeMysqlPassword.description")) + color.Yellowln("panel writeSite {name} {status} {path} {php} {ssl} " + translate.Get("commands.panel.writeSite.description")) + color.Yellowln("panel deleteSite {name} " + translate.Get("commands.panel.deleteSite.description")) + color.Yellowln("panel getSetting {name} " + translate.Get("commands.panel.getSetting.description")) + color.Yellowln("panel writeSetting {name} {value} " + translate.Get("commands.panel.writeSetting.description")) + color.Yellowln("panel deleteSetting {name} " + translate.Get("commands.panel.deleteSetting.description")) } return nil diff --git a/app/console/commands/panel_task.go b/app/console/commands/panel_task.go index e07592ab..7bd01555 100644 --- a/app/console/commands/panel_task.go +++ b/app/console/commands/panel_task.go @@ -23,7 +23,7 @@ func (receiver *PanelTask) Signature() string { // Description The console command description. func (receiver *PanelTask) Description() string { - return facades.Lang(context.Background()).Get("panel:task.description") + return facades.Lang(context.Background()).Get("commands.panel:task.description") } // Extend The console command extend. diff --git a/lang/en.json b/lang/en.json index 42998091..1f22bef8 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1,85 +1,87 @@ { - "panel:cert-renew": { - "description": "[Panel] Certificate renewal" - }, - "panel:monitoring": { - "description": "[Panel] System Monitoring" - }, - "panel": { - "description": "[Panel] Command line", - "developer_guidance": "Please use the following commands under the guidance of the developer", - "use_commands": "Please use the following commands", - "cmd_tool": "command line tool", - "update": { - "description": "update/fix panel to latest version" + "commands": { + "panel:cert-renew": { + "description": "[Panel] Certificate renewal" }, - "getInfo": { - "description": "reinitialize panel account information" + "panel:monitoring": { + "description": "[Panel] System Monitoring" }, - "getPort": { - "description": "get the panel access port", - "port": "panel port" + "panel": { + "description": "[Panel] Command line", + "forDeveloper": "Please use the following commands under the guidance of the developer", + "use": "Please use the following commands", + "tool": "command line tool", + "update": { + "description": "update/fix panel to latest version" + }, + "getInfo": { + "description": "reinitialize panel account information" + }, + "getPort": { + "description": "get the panel access port", + "port": "panel port" + }, + "getEntrance": { + "description": "get panel access", + "entrance": "entrance" + }, + "deleteEntrance": { + "description": "delete panel access" + }, + "cleanTask": { + "description": "clean up running and waiting tasks in the panel [used when tasks are stuck]" + }, + "backup": { + "description": "back up website/MySQL database/PostgreSQL database to the specified directory and retain the specified amount" + }, + "cutoff": { + "description": "cut website logs and keep specified amount" + }, + "installPlugin": { + "description": "install plugin" + }, + "uninstallPlugin": { + "description": "uninstall plugin" + }, + "updatePlugin": { + "description": "update plugin" + }, + "addSite": { + "description": "add website [domain name and port separated by commas]" + }, + "removeSite": { + "description": "remove website" + }, + "init": { + "description": "initialize the panel" + }, + "writePlugin": { + "description": "write plugin installation status" + }, + "deletePlugin": { + "description": "delete plugin installation status" + }, + "writeMysqlPassword": { + "description": "write MySQL root password" + }, + "writeSite": { + "description": "write website data to the panel" + }, + "deleteSite": { + "description": "delete panel website data" + }, + "getSetting": { + "description": "get panel setting data" + }, + "writeSetting": { + "description": "write/update panel setting data" + }, + "deleteSetting": { + "description": "delete panel setting data" + } }, - "getEntrance": { - "description": "get panel access", - "entrance": "entrance" - }, - "deleteEntrance": { - "description": "delete panel access" - }, - "cleanTask": { - "description": "clean up running and waiting tasks in the panel [used when tasks are stuck]" - }, - "backup": { - "description": "back up website/MySQL database/PostgreSQL database to the specified directory and retain the specified amount" - }, - "cutoff": { - "description": "cut website logs and keep specified amount" - }, - "installPlugin": { - "description": "install plugin" - }, - "uninstallPlugin": { - "description": "uninstall plugin" - }, - "updatePlugin": { - "description": "update plugin" - }, - "addSite": { - "description": "add website [domain name and port separated by commas]" - }, - "removeSite": { - "description": "remove website" - }, - "init": { - "description": "initialize the panel" - }, - "writePlugin": { - "description": "write plugin installation status" - }, - "deletePlugin": { - "description": "delete plugin installation status" - }, - "writeMysqlPassword": { - "description": "write MySQL root password" - }, - "writeSite": { - "description": "write website data to the panel" - }, - "deleteSite": { - "description": "delete panel website data" - }, - "getSetting": { - "description": "get panel setting data" - }, - "writeSetting": { - "description": "write/update panel setting data" - }, - "deleteSetting": { - "description": "delete panel setting data" + "panel:task": { + "description": "[Panel] Daily tasks" } - }, - "panel:task": { - "description": "[Panel] Daily tasks" } } \ No newline at end of file diff --git a/lang/zh_CN.json b/lang/zh_CN.json index 36d157f6..d7ccdd3d 100644 --- a/lang/zh_CN.json +++ b/lang/zh_CN.json @@ -1,85 +1,87 @@ { - "panel:cert-renew": { - "description": "[面板] 证书续签" - }, - "panel:monitoring": { - "description": "[面板] 系统监控" - }, - "panel": { - "description": "[面板] 命令行", - "developer_guidance": "以下命令请在开发者指导下使用", - "use_commands": "请使用以下命令", - "cmd_tool": "命令行工具", - "update": { - "description": "更新 / 修复面板到最新版本" + "commands": { + "panel:cert-renew": { + "description": "[面板] 证书续签" }, - "getInfo": { - "description": "重新初始化面板账号信息" + "panel:monitoring": { + "description": "[面板] 系统监控" }, - "getPort": { - "description": "获取面板访问端口", - "port": "面板端口" + "panel": { + "description": "[面板] 命令行", + "forDeveloper": "以下命令请在开发者指导下使用", + "use": "请使用以下命令", + "tool": "命令行工具", + "update": { + "description": "更新 / 修复面板到最新版本" + }, + "getInfo": { + "description": "重新初始化面板账号信息" + }, + "getPort": { + "description": "获取面板访问端口", + "port": "面板端口" + }, + "getEntrance": { + "description": "获取面板访问入口", + "entrance": "面板入口" + }, + "deleteEntrance": { + "description": "删除面板访问入口" + }, + "cleanTask": { + "description": "清理面板运行中和等待中的任务[任务卡住时使用]" + }, + "backup": { + "description": "备份网站 / MySQL数据库 / PostgreSQL数据库到指定目录并保留指定数量" + }, + "cutoff": { + "description": "切割网站日志并保留指定数量" + }, + "installPlugin": { + "description": "安装插件" + }, + "uninstallPlugin": { + "description": "卸载插件" + }, + "updatePlugin": { + "description": "更新插件" + }, + "addSite": { + "description": "添加网站[域名和端口用英文逗号分隔]" + }, + "removeSite": { + "description": "删除网站" + }, + "init": { + "description": "初始化面板" + }, + "writePlugin": { + "description": "写入插件安装状态" + }, + "deletePlugin": { + "description": "移除插件安装状态" + }, + "writeMysqlPassword": { + "description": "写入MySQL root密码" + }, + "writeSite": { + "description": "写入网站数据到面板" + }, + "deleteSite": { + "description": "删除面板网站数据" + }, + "getSetting": { + "description": "获取面板设置数据" + }, + "writeSetting": { + "description": "写入 / 更新面板设置数据" + }, + "deleteSetting": { + "description": "删除面板设置数据" + } }, - "getEntrance": { - "description": "获取面板访问入口", - "entrance": "面板入口" - }, - "deleteEntrance": { - "description": "删除面板访问入口" - }, - "cleanTask": { - "description": "清理面板运行中和等待中的任务[任务卡住时使用]" - }, - "backup": { - "description": "备份网站 / MySQL数据库 / PostgreSQL数据库到指定目录并保留指定数量" - }, - "cutoff": { - "description": "切割网站日志并保留指定数量" - }, - "installPlugin": { - "description": "安装插件" - }, - "uninstallPlugin": { - "description": "卸载插件" - }, - "updatePlugin": { - "description": "更新插件" - }, - "addSite": { - "description": "添加网站[域名和端口用英文逗号分隔]" - }, - "removeSite": { - "description": "删除网站" - }, - "init": { - "description": "初始化面板" - }, - "writePlugin": { - "description": "写入插件安装状态" - }, - "deletePlugin": { - "description": "移除插件安装状态" - }, - "writeMysqlPassword": { - "description": "写入MySQL root密码" - }, - "writeSite": { - "description": "写入网站数据到面板" - }, - "deleteSite": { - "description": "删除面板网站数据" - }, - "getSetting": { - "description": "获取面板设置数据" - }, - "writeSetting": { - "description": "写入 / 更新面板设置数据" - }, - "deleteSetting": { - "description": "删除面板设置数据" + "panel:task": { + "description": "[面板] 每日任务" } - }, - "panel:task": { - "description": "[面板] 每日任务" } } \ No newline at end of file From d8fe050607a21b2cc12c168e0ecff79a71e997f8 Mon Sep 17 00:00:00 2001 From: kkumar-gcc Date: Mon, 22 Apr 2024 22:10:38 +0530 Subject: [PATCH 03/12] add translation for panel init command --- app/console/commands/panel.go | 10 +++++----- lang/en.json | 6 +++++- lang/zh_CN.json | 6 +++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/console/commands/panel.go b/app/console/commands/panel.go index fa8f7ded..1b03ad70 100644 --- a/app/console/commands/panel.go +++ b/app/console/commands/panel.go @@ -59,31 +59,31 @@ func (receiver *Panel) Handle(ctx console.Context) error { var check models.User err := facades.Orm().Query().FirstOrFail(&check) if err == nil { - color.Redln("面板已初始化") + color.Redln(translate.Get("commands.panel.init.exist")) return nil } settings := []models.Setting{{Key: models.SettingKeyName, Value: "耗子 Linux 面板"}, {Key: models.SettingKeyMonitor, Value: "1"}, {Key: models.SettingKeyMonitorDays, Value: "30"}, {Key: models.SettingKeyBackupPath, Value: "/www/backup"}, {Key: models.SettingKeyWebsitePath, Value: "/www/wwwroot"}, {Key: models.SettingKeyVersion, Value: facades.Config().GetString("panel.version")}} err = facades.Orm().Query().Create(&settings) if err != nil { - color.Redln("初始化失败") + color.Redln(translate.Get("commands.panel.init.fail")) return nil } hash, err := facades.Hash().Make(tools.RandomString(32)) if err != nil { - color.Redln("初始化失败") + color.Redln(translate.Get("commands.panel.init.fail")) return nil } user := services.NewUserImpl() _, err = user.Create("admin", hash) if err != nil { - color.Redln("创建管理员失败") + color.Redln(translate.Get("commands.panel.init.adminFail")) return nil } - color.Greenln("初始化成功") + color.Greenln(translate.Get("commands.panel.init.success")) case "update": var task models.Task diff --git a/lang/en.json b/lang/en.json index 1f22bef8..c07dba21 100644 --- a/lang/en.json +++ b/lang/en.json @@ -53,7 +53,11 @@ "description": "remove website" }, "init": { - "description": "initialize the panel" + "description": "initialize the panel", + "exist": "panel has been initialized", + "success": "initialization successful", + "adminFound": "failed to create administrator", + "fail": "initialization failed" }, "writePlugin": { "description": "write plugin installation status" diff --git a/lang/zh_CN.json b/lang/zh_CN.json index d7ccdd3d..4590f926 100644 --- a/lang/zh_CN.json +++ b/lang/zh_CN.json @@ -53,7 +53,11 @@ "description": "删除网站" }, "init": { - "description": "初始化面板" + "description": "初始化面板", + "exist": "面板已初始化", + "success": "初始化成功", + "adminFail": "创建管理员失败", + "fail": "初始化失败" }, "writePlugin": { "description": "写入插件安装状态" From 3503aac2f6d528ed0cc142d15554019589959174 Mon Sep 17 00:00:00 2001 From: kkumar-gcc Date: Fri, 26 Apr 2024 13:36:11 +0530 Subject: [PATCH 04/12] finish translation for panel.update --- app/console/commands/panel.go | 8 ++++---- lang/en.json | 6 +++++- lang/zh_CN.json | 6 +++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/console/commands/panel.go b/app/console/commands/panel.go index 1b03ad70..334f5b8f 100644 --- a/app/console/commands/panel.go +++ b/app/console/commands/panel.go @@ -89,25 +89,25 @@ func (receiver *Panel) Handle(ctx console.Context) error { var task models.Task err := facades.Orm().Query().Where("status", models.TaskStatusRunning).OrWhere("status", models.TaskStatusWaiting).FirstOrFail(&task) if err == nil { - color.Redln("当前有任务正在执行,禁止更新") + color.Redln(translate.Get("commands.panel.update.taskCheck")) return nil } panel, err := tools.GetLatestPanelVersion() if err != nil { - color.Redln("获取最新版本失败") + color.Redln(translate.Get("commands.panel.update.versionFail")) return err } internal.Status = internal.StatusUpgrade if err = tools.UpdatePanel(panel); err != nil { internal.Status = internal.StatusFailed - color.Redln("更新失败: " + err.Error()) + color.Redln(translate.Get("commands.panel.update.fail") + ": " + err.Error()) return nil } internal.Status = internal.StatusNormal - color.Greenln("更新成功") + color.Greenln(translate.Get("commands.panel.update.success")) tools.RestartPanel() case "getInfo": diff --git a/lang/en.json b/lang/en.json index c07dba21..b6e93e2d 100644 --- a/lang/en.json +++ b/lang/en.json @@ -12,7 +12,11 @@ "use": "Please use the following commands", "tool": "command line tool", "update": { - "description": "update/fix panel to latest version" + "description": "update/fix panel to latest version", + "taskCheck": "There is currently a task being executed and updates are prohibited.", + "versionFail": "failed to get latest version", + "fail": "update failed", + "success": "update completed" }, "getInfo": { "description": "reinitialize panel account information" diff --git a/lang/zh_CN.json b/lang/zh_CN.json index 4590f926..a1a45e2f 100644 --- a/lang/zh_CN.json +++ b/lang/zh_CN.json @@ -12,7 +12,11 @@ "use": "请使用以下命令", "tool": "命令行工具", "update": { - "description": "更新 / 修复面板到最新版本" + "description": "更新 / 修复面板到最新版本", + "taskCheck": "当前有任务正在执行,禁止更新", + "versionFail": "获取最新版本失败", + "fail": "更新失败", + "success": "更新成功" }, "getInfo": { "description": "重新初始化面板账号信息" From 4c8a88ea03db252c22a49b28471a67dd589faf89 Mon Sep 17 00:00:00 2001 From: kkumar-gcc Date: Fri, 26 Apr 2024 17:57:51 +0530 Subject: [PATCH 05/12] finish translation for panel.getInfo --- app/console/commands/panel.go | 18 +++++++++--------- lang/en.json | 11 ++++++++++- lang/zh_CN.json | 11 ++++++++++- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/app/console/commands/panel.go b/app/console/commands/panel.go index 334f5b8f..ebdfd425 100644 --- a/app/console/commands/panel.go +++ b/app/console/commands/panel.go @@ -114,14 +114,14 @@ func (receiver *Panel) Handle(ctx console.Context) error { var user models.User err := facades.Orm().Query().Where("id", 1).FirstOrFail(&user) if err != nil { - color.Redln("获取管理员信息失败") + color.Redln(translate.Get("commands.panel.getInfo.adminGetFail")) return nil } password := tools.RandomString(16) hash, err := facades.Hash().Make(password) if err != nil { - color.Redln("生成密码失败") + color.Redln(translate.Get("commands.panel.getInfo.passwordGenerationFail")) return nil } user.Username = tools.RandomString(8) @@ -132,13 +132,13 @@ func (receiver *Panel) Handle(ctx console.Context) error { err = facades.Orm().Query().Save(&user) if err != nil { - color.Redln("保存管理员信息失败") + color.Redln(translate.Get("commands.panel.getInfo.adminSaveFail")) return nil } port, err := tools.Exec(`cat /www/panel/panel.conf | grep APP_PORT | awk -F '=' '{print $2}' | tr -d '\n'`) if err != nil { - color.Redln("获取面板端口失败") + color.Redln(translate.Get("commands.panel.getInfo.portFail")) return nil } ip, err := tools.GetPublicIP() @@ -150,11 +150,11 @@ func (receiver *Panel) Handle(ctx console.Context) error { protocol = "https" } - color.Greenln("用户名: " + user.Username) - color.Greenln("密码: " + password) - color.Greenln("面板端口: " + port) - color.Greenln("面板入口: " + facades.Config().GetString("http.entrance")) - color.Greenln("面板地址: " + protocol + "://" + ip + ":" + port + facades.Config().GetString("http.entrance")) + color.Greenln(translate.Get("commands.panel.getInfo.username") + ": " + user.Username) + color.Greenln(translate.Get("commands.panel.getInfo.password") + ": " + password) + color.Greenln(translate.Get("commands.panel.getInfo.port") + ": " + port) + color.Greenln(translate.Get("commands.panel.getInfo.entrance") + ": " + facades.Config().GetString("http.entrance")) + color.Greenln(translate.Get("commands.panel.getInfo.address") + ": " + protocol + "://" + ip + ":" + port + facades.Config().GetString("http.entrance")) case "getPort": port, err := tools.Exec(`cat /www/panel/panel.conf | grep APP_PORT | awk -F '=' '{print $2}' | tr -d '\n'`) diff --git a/lang/en.json b/lang/en.json index b6e93e2d..056a8c9b 100644 --- a/lang/en.json +++ b/lang/en.json @@ -19,7 +19,16 @@ "success": "update completed" }, "getInfo": { - "description": "reinitialize panel account information" + "description": "reinitialize panel account information", + "adminGetFail": "failed to get administrator information", + "adminSaveFail": "failed to save administrator information", + "passwordGenerationFail": "failed to generate password", + "portFail": "failed to get panel port", + "username": "Username", + "password": "Password", + "port": "Panel port", + "entrance": "Panel entrance", + "address": "Panel address" }, "getPort": { "description": "get the panel access port", diff --git a/lang/zh_CN.json b/lang/zh_CN.json index a1a45e2f..382a28c6 100644 --- a/lang/zh_CN.json +++ b/lang/zh_CN.json @@ -19,7 +19,16 @@ "success": "更新成功" }, "getInfo": { - "description": "重新初始化面板账号信息" + "description": "重新初始化面板账号信息", + "adminGetFail": "获取管理员信息失败", + "adminSaveFail": "保存管理员信息失败", + "passwordGenerationFail": "生成密码失败", + "portFail": "获取面板端口失败", + "username": "用户名", + "password": "密码", + "port": "面板端口", + "entrance": "面板入口", + "address": "面板地址" }, "getPort": { "description": "获取面板访问端口", From 227c5344e363118eecd6033ec67cced5834887ae Mon Sep 17 00:00:00 2001 From: kkumar-gcc Date: Fri, 26 Apr 2024 18:08:50 +0530 Subject: [PATCH 06/12] finish translation for panel.deleteEntrance --- app/console/commands/panel.go | 18 +++++++++--------- lang/en.json | 16 ++++++++-------- lang/zh_CN.json | 16 ++++++++-------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/console/commands/panel.go b/app/console/commands/panel.go index ebdfd425..6d172934 100644 --- a/app/console/commands/panel.go +++ b/app/console/commands/panel.go @@ -138,7 +138,7 @@ func (receiver *Panel) Handle(ctx console.Context) error { port, err := tools.Exec(`cat /www/panel/panel.conf | grep APP_PORT | awk -F '=' '{print $2}' | tr -d '\n'`) if err != nil { - color.Redln(translate.Get("commands.panel.getInfo.portFail")) + color.Redln(translate.Get("commands.panel.portFail")) return nil } ip, err := tools.GetPublicIP() @@ -152,34 +152,34 @@ func (receiver *Panel) Handle(ctx console.Context) error { color.Greenln(translate.Get("commands.panel.getInfo.username") + ": " + user.Username) color.Greenln(translate.Get("commands.panel.getInfo.password") + ": " + password) - color.Greenln(translate.Get("commands.panel.getInfo.port") + ": " + port) - color.Greenln(translate.Get("commands.panel.getInfo.entrance") + ": " + facades.Config().GetString("http.entrance")) + color.Greenln(translate.Get("commands.panel.port") + ": " + port) + color.Greenln(translate.Get("commands.panel.entrance") + ": " + facades.Config().GetString("http.entrance")) color.Greenln(translate.Get("commands.panel.getInfo.address") + ": " + protocol + "://" + ip + ":" + port + facades.Config().GetString("http.entrance")) case "getPort": port, err := tools.Exec(`cat /www/panel/panel.conf | grep APP_PORT | awk -F '=' '{print $2}' | tr -d '\n'`) if err != nil { - color.Redln("获取面板端口失败") + color.Redln(translate.Get("commands.panel.portFail")) return nil } - color.Greenln(translate.Get("commands.panel.getPort.port") + ": " + port) + color.Greenln(translate.Get("commands.panel.port") + ": " + port) case "getEntrance": - color.Greenln(translate.Get("commands.panel.getEntrance.entrance") + ": " + facades.Config().GetString("http.entrance")) + color.Greenln(translate.Get("commands.panel.entrance") + ": " + facades.Config().GetString("http.entrance")) case "deleteEntrance": oldEntrance, err := tools.Exec(`cat /www/panel/panel.conf | grep APP_ENTRANCE | awk -F '=' '{print $2}' | tr -d '\n'`) if err != nil { - color.Redln("获取面板入口失败") + color.Redln(translate.Get("commands.panel.deleteEntrance.fail")) return nil } if _, err = tools.Exec("sed -i 's!APP_ENTRANCE=" + oldEntrance + "!APP_ENTRANCE=/!g' /www/panel/panel.conf"); err != nil { - color.Redln("删除面板入口失败") + color.Redln(translate.Get("commands.panel.deleteEntrance.fail")) return nil } - color.Greenln("删除面板入口成功") + color.Greenln(translate.Get("commands.panel.deleteEntrance.success")) case "writePlugin": slug := arg1 diff --git a/lang/en.json b/lang/en.json index 056a8c9b..1ee13dd7 100644 --- a/lang/en.json +++ b/lang/en.json @@ -11,6 +11,9 @@ "forDeveloper": "Please use the following commands under the guidance of the developer", "use": "Please use the following commands", "tool": "command line tool", + "portFail": "failed to get panel port", + "port": "Panel port", + "entrance": "Panel entrance", "update": { "description": "update/fix panel to latest version", "taskCheck": "There is currently a task being executed and updates are prohibited.", @@ -23,23 +26,20 @@ "adminGetFail": "failed to get administrator information", "adminSaveFail": "failed to save administrator information", "passwordGenerationFail": "failed to generate password", - "portFail": "failed to get panel port", "username": "Username", "password": "Password", - "port": "Panel port", - "entrance": "Panel entrance", "address": "Panel address" }, "getPort": { - "description": "get the panel access port", - "port": "panel port" + "description": "get the panel access port" }, "getEntrance": { - "description": "get panel access", - "entrance": "entrance" + "description": "get panel access" }, "deleteEntrance": { - "description": "delete panel access" + "description": "delete panel access", + "fail": "failed to delete panel entrance", + "success": "panel entrance deleted successfully" }, "cleanTask": { "description": "clean up running and waiting tasks in the panel [used when tasks are stuck]" diff --git a/lang/zh_CN.json b/lang/zh_CN.json index 382a28c6..30dfb8d3 100644 --- a/lang/zh_CN.json +++ b/lang/zh_CN.json @@ -11,6 +11,9 @@ "forDeveloper": "以下命令请在开发者指导下使用", "use": "请使用以下命令", "tool": "命令行工具", + "port": "面板端口", + "portFail": "获取面板端口失败", + "entrance": "面板入口", "update": { "description": "更新 / 修复面板到最新版本", "taskCheck": "当前有任务正在执行,禁止更新", @@ -23,23 +26,20 @@ "adminGetFail": "获取管理员信息失败", "adminSaveFail": "保存管理员信息失败", "passwordGenerationFail": "生成密码失败", - "portFail": "获取面板端口失败", "username": "用户名", "password": "密码", - "port": "面板端口", - "entrance": "面板入口", "address": "面板地址" }, "getPort": { - "description": "获取面板访问端口", - "port": "面板端口" + "description": "获取面板访问端口" }, "getEntrance": { - "description": "获取面板访问入口", - "entrance": "面板入口" + "description": "获取面板访问入口" }, "deleteEntrance": { - "description": "删除面板访问入口" + "description": "删除面板访问入口", + "fail": "删除面板入口失败", + "success": "删除面板入口成功" }, "cleanTask": { "description": "清理面板运行中和等待中的任务[任务卡住时使用]" From a5743f94b261bcef13f486e29b98fff0ed1a7fc1 Mon Sep 17 00:00:00 2001 From: kkumar-gcc Date: Fri, 26 Apr 2024 18:13:13 +0530 Subject: [PATCH 07/12] finish translation for panel.writePlugin --- app/console/commands/panel.go | 6 +++--- lang/en.json | 5 ++++- lang/zh_CN.json | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/console/commands/panel.go b/app/console/commands/panel.go index 6d172934..f2a99a51 100644 --- a/app/console/commands/panel.go +++ b/app/console/commands/panel.go @@ -185,7 +185,7 @@ func (receiver *Panel) Handle(ctx console.Context) error { slug := arg1 version := arg2 if len(slug) == 0 || len(version) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.writePlugin.paramFail")) return nil } @@ -197,11 +197,11 @@ func (receiver *Panel) Handle(ctx console.Context) error { }) if err != nil { - color.Redln("写入插件安装状态失败") + color.Redln(translate.Get("commands.panel.writePlugin.fail")) return nil } - color.Greenln("写入插件安装状态成功") + color.Greenln(translate.Get("commands.panel.writePlugin.success")) case "deletePlugin": slug := arg1 diff --git a/lang/en.json b/lang/en.json index 1ee13dd7..04b4113f 100644 --- a/lang/en.json +++ b/lang/en.json @@ -73,7 +73,10 @@ "fail": "initialization failed" }, "writePlugin": { - "description": "write plugin installation status" + "description": "write plugin installation status", + "paramFail": "plugin slug and version are required", + "fail": "failed to write plugin installation status", + "success": "plugin installation status written successfully" }, "deletePlugin": { "description": "delete plugin installation status" diff --git a/lang/zh_CN.json b/lang/zh_CN.json index 30dfb8d3..6c4bf6ed 100644 --- a/lang/zh_CN.json +++ b/lang/zh_CN.json @@ -73,7 +73,10 @@ "fail": "初始化失败" }, "writePlugin": { - "description": "写入插件安装状态" + "description": "写入插件安装状态", + "paramFail": "参数错误", + "fail": "写入插件安装状态失败", + "success": "写入插件安装状态成功" }, "deletePlugin": { "description": "移除插件安装状态" From 48ed174dc6f0756c86ec0bdaa1b5e8ff294486f0 Mon Sep 17 00:00:00 2001 From: kkumar-gcc Date: Fri, 26 Apr 2024 18:16:26 +0530 Subject: [PATCH 08/12] finish translation for panel.deletePlugin --- app/console/commands/panel.go | 6 +++--- lang/en.json | 5 ++++- lang/zh_CN.json | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/console/commands/panel.go b/app/console/commands/panel.go index f2a99a51..06b9a808 100644 --- a/app/console/commands/panel.go +++ b/app/console/commands/panel.go @@ -206,17 +206,17 @@ func (receiver *Panel) Handle(ctx console.Context) error { case "deletePlugin": slug := arg1 if len(slug) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.deletePlugin.paramFail")) return nil } _, err := facades.Orm().Query().Where("slug", slug).Delete(&models.Plugin{}) if err != nil { - color.Redln("移除插件安装状态失败") + color.Redln(translate.Get("commands.panel.deletePlugin.fail")) return nil } - color.Greenln("移除插件安装状态成功") + color.Greenln(translate.Get("commands.panel.deletePlugin.success")) case "writeMysqlPassword": password := arg1 diff --git a/lang/en.json b/lang/en.json index 04b4113f..0d2861ea 100644 --- a/lang/en.json +++ b/lang/en.json @@ -79,7 +79,10 @@ "success": "plugin installation status written successfully" }, "deletePlugin": { - "description": "delete plugin installation status" + "description": "delete plugin installation status", + "paramFail": "plugin slug is required", + "fail": "failed to remove plugin installation status", + "success": "plugin installation status removed successfully" }, "writeMysqlPassword": { "description": "write MySQL root password" diff --git a/lang/zh_CN.json b/lang/zh_CN.json index 6c4bf6ed..dda059e1 100644 --- a/lang/zh_CN.json +++ b/lang/zh_CN.json @@ -79,7 +79,10 @@ "success": "写入插件安装状态成功" }, "deletePlugin": { - "description": "移除插件安装状态" + "description": "移除插件安装状态", + "paramFail": "参数错误", + "fail": "移除插件安装状态失败", + "success": "移除插件安装状态成功" }, "writeMysqlPassword": { "description": "写入MySQL root密码" From 7f46dea052d45877e822dd7df78bed500a4b4e78 Mon Sep 17 00:00:00 2001 From: kkumar-gcc Date: Fri, 26 Apr 2024 18:19:55 +0530 Subject: [PATCH 09/12] finish translation for panel.writeMysqlPassword --- app/console/commands/panel.go | 6 +++--- lang/en.json | 5 ++++- lang/zh_CN.json | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/console/commands/panel.go b/app/console/commands/panel.go index 06b9a808..3fe471b4 100644 --- a/app/console/commands/panel.go +++ b/app/console/commands/panel.go @@ -221,7 +221,7 @@ func (receiver *Panel) Handle(ctx console.Context) error { case "writeMysqlPassword": password := arg1 if len(password) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.writeMysqlPassword.paramFail")) return nil } @@ -233,11 +233,11 @@ func (receiver *Panel) Handle(ctx console.Context) error { }) if err != nil { - color.Redln("写入MySQL root密码失败") + color.Redln(translate.Get("commands.panel.writeMysqlPassword.fail")) return nil } - color.Greenln("写入MySQL root密码成功") + color.Greenln(translate.Get("commands.panel.writeMysqlPassword.success")) case "cleanTask": _, err := facades.Orm().Query().Model(&models.Task{}).Where("status", models.TaskStatusRunning).OrWhere("status", models.TaskStatusWaiting).Update("status", models.TaskStatusFailed) diff --git a/lang/en.json b/lang/en.json index 0d2861ea..e669da6e 100644 --- a/lang/en.json +++ b/lang/en.json @@ -85,7 +85,10 @@ "success": "plugin installation status removed successfully" }, "writeMysqlPassword": { - "description": "write MySQL root password" + "description": "write MySQL root password", + "paramFail": "MySQL root password is required", + "fail": "failed to write MySQL root password", + "success": "MySQL root password written successfully" }, "writeSite": { "description": "write website data to the panel" diff --git a/lang/zh_CN.json b/lang/zh_CN.json index dda059e1..156923d6 100644 --- a/lang/zh_CN.json +++ b/lang/zh_CN.json @@ -85,7 +85,10 @@ "success": "移除插件安装状态成功" }, "writeMysqlPassword": { - "description": "写入MySQL root密码" + "description": "写入MySQL root密码", + "paramFail": "参数错误", + "fail": "写入MySQL root密码失败", + "success": "写入MySQL root密码成功" }, "writeSite": { "description": "写入网站数据到面板" From d35245aa11b0a1ef4a5b5143b68ff72f7f1977c3 Mon Sep 17 00:00:00 2001 From: kkumar-gcc Date: Fri, 26 Apr 2024 18:46:41 +0530 Subject: [PATCH 10/12] finish translation for panel.cutoff --- app/console/commands/panel.go | 30 +++++++++++++++--------------- lang/en.json | 18 ++++++++++++++++-- lang/zh_CN.json | 18 ++++++++++++++++-- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/app/console/commands/panel.go b/app/console/commands/panel.go index 3fe471b4..5b2ad950 100644 --- a/app/console/commands/panel.go +++ b/app/console/commands/panel.go @@ -242,11 +242,11 @@ func (receiver *Panel) Handle(ctx console.Context) error { case "cleanTask": _, err := facades.Orm().Query().Model(&models.Task{}).Where("status", models.TaskStatusRunning).OrWhere("status", models.TaskStatusWaiting).Update("status", models.TaskStatusFailed) if err != nil { - color.Redln("清理任务失败") + color.Redln(translate.Get("commands.panel.cleanTask.fail")) return nil } - color.Greenln("清理任务成功") + color.Greenln(translate.Get("commands.panel.cleanTask.success")) case "backup": backupType := arg1 @@ -401,44 +401,44 @@ func (receiver *Panel) Handle(ctx console.Context) error { save := arg2 hr := `+----------------------------------------------------` if len(name) == 0 || len(save) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.cutoff.paramFail")) return nil } color.Greenln(hr) - color.Greenln("★ 开始切割 [" + carbon.Now().ToDateTimeString() + "]") + color.Greenln("★ " + translate.Get("commands.panel.cutoff.start") + " [" + carbon.Now().ToDateTimeString() + "]") color.Greenln(hr) - color.Yellowln("|-目标网站: " + name) + color.Yellowln("|-" + translate.Get("commands.panel.cutoff.targetSite") + ": " + name) var website models.Website if err := facades.Orm().Query().Where("name", name).FirstOrFail(&website); err != nil { - color.Redln("|-网站不存在") + color.Redln("|-" + translate.Get("commands.panel.cutoff.siteNotExist")) color.Greenln(hr) return nil } logPath := "/www/wwwlogs/" + website.Name + ".log" if !tools.Exists(logPath) { - color.Redln("|-日志文件不存在") + color.Redln("|-" + translate.Get("commands.panel.cutoff.logNotExist")) color.Greenln(hr) return nil } backupPath := "/www/wwwlogs/" + website.Name + "_" + carbon.Now().ToShortDateTimeString() + ".log.zip" if _, err := tools.Exec(`cd /www/wwwlogs && zip -r ` + backupPath + ` ` + website.Name + ".log"); err != nil { - color.Redln("|-备份失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.cutoff.backupFail") + ": " + err.Error()) return nil } if _, err := tools.Exec(`echo "" > ` + logPath); err != nil { - color.Redln("|-清空失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.cutoff.clearFail") + ": " + err.Error()) return nil } - color.Greenln("|-切割成功") + color.Greenln("|-" + translate.Get("commands.panel.cutoff.cutSuccess")) color.Greenln(hr) files, err := os.ReadDir("/www/wwwlogs") if err != nil { - color.Redln("|-清理失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.cutoff.cleanupFail") + ": " + err.Error()) return nil } var filteredFiles []os.FileInfo @@ -456,15 +456,15 @@ func (receiver *Panel) Handle(ctx console.Context) error { }) for i := cast.ToInt(save); i < len(filteredFiles); i++ { fileToDelete := filepath.Join("/www/wwwlogs", filteredFiles[i].Name()) - color.Yellowln("|-清理日志: " + fileToDelete) + color.Yellowln("|-" + translate.Get("commands.panel.cutoff.clearLog") + ": " + fileToDelete) if err := tools.Remove(fileToDelete); err != nil { - color.Redln("|-清理失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.cutoff.cleanupFail") + ": " + err.Error()) return nil } } - color.Greenln("|-清理完成") + color.Greenln("|-" + translate.Get("commands.panel.cutoff.cleanupSuccess")) color.Greenln(hr) - color.Greenln("☆ 切割完成 [" + carbon.Now().ToDateTimeString() + "]") + color.Greenln("☆ " + translate.Get("commands.panel.cutoff.end") + " [" + carbon.Now().ToDateTimeString() + "]") color.Greenln(hr) case "writeSite": diff --git a/lang/en.json b/lang/en.json index e669da6e..8963bdb0 100644 --- a/lang/en.json +++ b/lang/en.json @@ -42,13 +42,27 @@ "success": "panel entrance deleted successfully" }, "cleanTask": { - "description": "clean up running and waiting tasks in the panel [used when tasks are stuck]" + "description": "clean up running and waiting tasks in the panel [used when tasks are stuck]", + "fail": "failed to clean up tasks", + "success": "tasks cleaned up successfully" }, "backup": { "description": "back up website/MySQL database/PostgreSQL database to the specified directory and retain the specified amount" }, "cutoff": { - "description": "cut website logs and keep specified amount" + "description": "cut website logs and keep specified amount", + "paramFail": "website domain name and keep amount are required", + "start": "start cutting", + "targetSite": "target website", + "siteNotExist": "website does not exist", + "logNotExist": "log file does not exist", + "backupFail": "backup failed", + "clearFail": "clearing failed", + "cleanupFail": "cleanup failed", + "clearLog": "clear log", + "cutSuccess": "cutting successful", + "cleanupSuccess": "cleanup successful", + "end": "cutting completed" }, "installPlugin": { "description": "install plugin" diff --git a/lang/zh_CN.json b/lang/zh_CN.json index 156923d6..5479ed96 100644 --- a/lang/zh_CN.json +++ b/lang/zh_CN.json @@ -42,13 +42,27 @@ "success": "删除面板入口成功" }, "cleanTask": { - "description": "清理面板运行中和等待中的任务[任务卡住时使用]" + "description": "清理面板运行中和等待中的任务[任务卡住时使用]", + "fail": "清理任务失败", + "success": "清理任务成功" }, "backup": { "description": "备份网站 / MySQL数据库 / PostgreSQL数据库到指定目录并保留指定数量" }, "cutoff": { - "description": "切割网站日志并保留指定数量" + "description": "切割网站日志并保留指定数量", + "paramFail": "参数错误", + "start": "开始切割", + "targetSite": "目标网站", + "siteNotExist": "网站不存在", + "logNotExist": "日志文件不存在", + "backupFail": "备份失败", + "clearFail": "清空失败", + "cleanupFail": "清理失败", + "clearLog": "清理日志", + "cutSuccess": "切割成功", + "cleanupSuccess": "清理完成", + "end": "切割完成" }, "installPlugin": { "description": "安装插件" From 48b539b31afe1bc8d108248bedfa6a130f0b8599 Mon Sep 17 00:00:00 2001 From: kkumar-gcc Date: Fri, 26 Apr 2024 19:05:50 +0530 Subject: [PATCH 11/12] finish translation for panel.writeSite --- app/console/commands/panel.go | 42 +++++++++++++++++------------------ lang/en.json | 37 +++++++++++++++++++++++------- lang/zh_CN.json | 37 +++++++++++++++++++++++------- 3 files changed, 79 insertions(+), 37 deletions(-) diff --git a/app/console/commands/panel.go b/app/console/commands/panel.go index 5b2ad950..128d78f8 100644 --- a/app/console/commands/panel.go +++ b/app/console/commands/panel.go @@ -474,19 +474,19 @@ func (receiver *Panel) Handle(ctx console.Context) error { php := cast.ToInt(arg4) ssl := cast.ToBool(ctx.Argument(5)) if len(name) == 0 || len(path) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.writeSite.paramFail")) return nil } var website models.Website if err := facades.Orm().Query().Where("name", name).FirstOrFail(&website); err == nil { - color.Redln("网站已存在") + color.Redln(translate.Get("commands.panel.writeSite.siteExist")) return nil } _, err := os.Stat(path) if os.IsNotExist(err) { - color.Redln("网站目录不存在") + color.Redln(translate.Get("commands.panel.writeSite.pathNotExist")) return nil } @@ -498,32 +498,32 @@ func (receiver *Panel) Handle(ctx console.Context) error { Ssl: ssl, }) if err != nil { - color.Redln("写入网站失败") + color.Redln(translate.Get("commands.panel.writeSite.fail")) return nil } - color.Greenln("写入网站成功") + color.Greenln(translate.Get("commands.panel.writeSite.success")) case "deleteSite": name := arg1 if len(name) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.deleteSite.paramFail")) return nil } _, err := facades.Orm().Query().Where("name", name).Delete(&models.Website{}) if err != nil { - color.Redln("删除网站失败") + color.Redln(translate.Get("commands.panel.deleteSite.fail")) return nil } - color.Greenln("删除网站成功") + color.Greenln(translate.Get("commands.panel.deleteSite.success")) case "writeSetting": key := arg1 value := arg2 if len(key) == 0 || len(value) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.writeSetting.paramFail")) return nil } @@ -534,16 +534,16 @@ func (receiver *Panel) Handle(ctx console.Context) error { Value: value, }) if err != nil { - color.Redln("写入设置失败") + color.Redln(translate.Get("commands.panel.writeSetting.fail")) return nil } - color.Greenln("写入设置成功") + color.Greenln(translate.Get("commands.panel.writeSetting.success")) case "getSetting": key := arg1 if len(key) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.getSetting.paramFail")) return nil } @@ -557,17 +557,17 @@ func (receiver *Panel) Handle(ctx console.Context) error { case "deleteSetting": key := arg1 if len(key) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.deleteSetting.paramFail")) return nil } _, err := facades.Orm().Query().Where("key", key).Delete(&models.Setting{}) if err != nil { - color.Redln("删除设置失败") + color.Redln(translate.Get("commands.panel.deleteSetting.fail")) return nil } - color.Greenln("删除设置成功") + color.Greenln(translate.Get("commands.panel.deleteSetting.success")) case "addSite": name := arg1 @@ -648,7 +648,7 @@ func (receiver *Panel) Handle(ctx console.Context) error { case "installPlugin": slug := arg1 if len(slug) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.installPlugin.paramFail")) return nil } @@ -658,12 +658,12 @@ func (receiver *Panel) Handle(ctx console.Context) error { return nil } - color.Greenln("任务已提交") + color.Greenln(translate.Get("commands.panel.installPlugin.success")) case "uninstallPlugin": slug := arg1 if len(slug) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.uninstallPlugin.paramFail")) return nil } @@ -673,12 +673,12 @@ func (receiver *Panel) Handle(ctx console.Context) error { return nil } - color.Greenln("任务已提交") + color.Greenln(translate.Get("commands.panel.uninstallPlugin.success")) case "updatePlugin": slug := arg1 if len(slug) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.updatePlugin.paramFail")) return nil } @@ -688,7 +688,7 @@ func (receiver *Panel) Handle(ctx console.Context) error { return nil } - color.Greenln("任务已提交") + color.Greenln(translate.Get("commands.panel.updatePlugin.success")) default: color.Yellowln(facades.Config().GetString("panel.name") + " - " + translate.Get("commands.panel.tool") + " - " + facades.Config().GetString("panel.version")) diff --git a/lang/en.json b/lang/en.json index 8963bdb0..df706fc7 100644 --- a/lang/en.json +++ b/lang/en.json @@ -65,13 +65,19 @@ "end": "cutting completed" }, "installPlugin": { - "description": "install plugin" + "description": "install plugin", + "paramFail": "plugin slug is required", + "success": "task has been submitted" }, "uninstallPlugin": { - "description": "uninstall plugin" + "description": "uninstall plugin", + "paramFail": "plugin slug is required", + "success": "task has been submitted" }, "updatePlugin": { - "description": "update plugin" + "description": "update plugin", + "paramFail": "plugin slug is required", + "success": "task has been submitted" }, "addSite": { "description": "add website [domain name and port separated by commas]" @@ -105,19 +111,34 @@ "success": "MySQL root password written successfully" }, "writeSite": { - "description": "write website data to the panel" + "description": "write website data to the panel", + "paramFail": "name and path are required", + "siteExist": "website already exists", + "pathNotExist": "website directory does not exist", + "fail": "failed to write to website", + "success": "writing to website successfully" }, "deleteSite": { - "description": "delete panel website data" + "description": "delete panel website data", + "paramFail": "website name is required", + "fail": "failed to delete website", + "success": "website deleted successfully" }, "getSetting": { - "description": "get panel setting data" + "description": "get panel setting data", + "paramFail": "key is required" }, "writeSetting": { - "description": "write/update panel setting data" + "description": "write/update panel setting data", + "paramFail": "key and value are required", + "fail": "Writing settings failed", + "success": "settings written successfully" }, "deleteSetting": { - "description": "delete panel setting data" + "description": "delete panel setting data", + "paramFail": "key is required", + "fail": "failed to delete settings", + "success": "settings deleted successfully" } }, "panel:task": { diff --git a/lang/zh_CN.json b/lang/zh_CN.json index 5479ed96..84d618ba 100644 --- a/lang/zh_CN.json +++ b/lang/zh_CN.json @@ -65,13 +65,19 @@ "end": "切割完成" }, "installPlugin": { - "description": "安装插件" + "description": "安装插件", + "paramFail": "参数错误", + "success": "任务已提交" }, "uninstallPlugin": { - "description": "卸载插件" + "description": "卸载插件", + "paramFail": "参数错误", + "success": "任务已提交" }, "updatePlugin": { - "description": "更新插件" + "description": "更新插件", + "paramFail": "参数错误", + "success": "任务已提交" }, "addSite": { "description": "添加网站[域名和端口用英文逗号分隔]" @@ -105,19 +111,34 @@ "success": "写入MySQL root密码成功" }, "writeSite": { - "description": "写入网站数据到面板" + "description": "写入网站数据到面板", + "paramFail": "参数错误", + "siteExist": "网站已存在", + "pathNotExist": "网站目录不存在", + "fail": "写入网站失败", + "success": "写入网站成功" }, "deleteSite": { - "description": "删除面板网站数据" + "description": "删除面板网站数据", + "paramFail": "参数错误", + "fail": "删除网站失败", + "success": "删除网站成功" }, "getSetting": { - "description": "获取面板设置数据" + "description": "获取面板设置数据", + "paramFail": "参数错误" }, "writeSetting": { - "description": "写入 / 更新面板设置数据" + "description": "写入 / 更新面板设置数据", + "paramFail": "参数错误", + "fail": "写入设置失败", + "success": "写入设置成功" }, "deleteSetting": { - "description": "删除面板设置数据" + "description": "删除面板设置数据", + "paramFail": "参数错误", + "fail": "删除设置失败", + "success": "删除设置成功" } }, "panel:task": { From e55e3402e9883b326061eb64c3c51278c6445572 Mon Sep 17 00:00:00 2001 From: kkumar-gcc Date: Sat, 27 Apr 2024 16:13:28 +0530 Subject: [PATCH 12/12] finish translation --- app/console/commands/monitoring.go | 4 +- app/console/commands/panel.go | 92 ++++++++++++++--------------- app/http/controllers/controller.go | 5 +- app/http/middleware/jwt.go | 7 ++- app/http/middleware/must_install.go | 27 +++++++-- app/http/middleware/status.go | 10 ++-- lang/en.json | 65 ++++++++++++++++++-- lang/zh_CN.json | 65 ++++++++++++++++++-- 8 files changed, 206 insertions(+), 69 deletions(-) diff --git a/app/console/commands/monitoring.go b/app/console/commands/monitoring.go index 3eeb28e5..4c7b9ae7 100644 --- a/app/console/commands/monitoring.go +++ b/app/console/commands/monitoring.go @@ -53,6 +53,8 @@ func (receiver *Monitoring) Handle(console.Context) error { info := tools.GetMonitoringInfo() + translate := facades.Lang(context.Background()) + // 去除部分数据以减少数据库存储 info.Disk = nil for _, cpu := range info.Cpus { @@ -72,7 +74,7 @@ func (receiver *Monitoring) Handle(console.Context) error { }) if err != nil { facades.Log().Infof("[面板] 系统监控保存失败: %s", err.Error()) - color.Redf("[面板] 系统监控保存失败: %s", err.Error()) + color.Redf(translate.Get("commands.panel:monitoring.fail")+": %s", err.Error()) return nil } diff --git a/app/console/commands/panel.go b/app/console/commands/panel.go index 128d78f8..d6f6cfc4 100644 --- a/app/console/commands/panel.go +++ b/app/console/commands/panel.go @@ -255,37 +255,37 @@ func (receiver *Panel) Handle(ctx console.Context) error { save := arg4 hr := `+----------------------------------------------------` if len(backupType) == 0 || len(name) == 0 || len(path) == 0 || len(save) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.backup.paramFail")) return nil } color.Greenln(hr) - color.Greenln("★ 开始备份 [" + carbon.Now().ToDateTimeString() + "]") + color.Greenln("★ " + translate.Get("commands.panel.backup.start") + " [" + carbon.Now().ToDateTimeString() + "]") color.Greenln(hr) if !tools.Exists(path) { if err := tools.Mkdir(path, 0644); err != nil { - color.Redln("|-创建备份目录失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.backup.backupDirFail") + ": " + err.Error()) return nil } } switch backupType { case "website": - color.Yellowln("|-目标网站: " + name) + color.Yellowln("|-" + translate.Get("commands.panel.backup.targetSite") + ": " + name) var website models.Website if err := facades.Orm().Query().Where("name", name).FirstOrFail(&website); err != nil { - color.Redln("|-网站不存在") + color.Redln("|-" + translate.Get("commands.panel.backup.siteNotExist")) color.Greenln(hr) return nil } backupFile := path + "/" + website.Name + "_" + carbon.Now().ToShortDateTimeString() + ".zip" if _, err := tools.Exec(`cd '` + website.Path + `' && zip -r '` + backupFile + `' .`); err != nil { - color.Redln("|-备份失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.backup.backupFail") + ": " + err.Error()) return nil } - color.Greenln("|-备份成功") + color.Greenln("|-" + translate.Get("commands.panel.backup.backupSuccess")) case "mysql": rootPassword := services.NewSettingImpl().Get(models.SettingKeyMysqlRootPassword) @@ -293,81 +293,81 @@ func (receiver *Panel) Handle(ctx console.Context) error { err := os.Setenv("MYSQL_PWD", rootPassword) if err != nil { - color.Redln("|-备份MySQL数据库失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.backup.mysqlBackupFail") + ": " + err.Error()) color.Greenln(hr) return nil } - color.Greenln("|-目标MySQL数据库: " + name) - color.Greenln("|-开始导出") + color.Greenln("|-" + translate.Get("commands.panel.backup.targetMysql") + ": " + name) + color.Greenln("|-" + translate.Get("commands.panel.backup.startExport")) if _, err = tools.Exec(`mysqldump -uroot ` + name + ` > /tmp/` + backupFile + ` 2>&1`); err != nil { - color.Redln("|-导出失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.backup.exportFail") + ": " + err.Error()) return nil } - color.Greenln("|-导出成功") - color.Greenln("|-开始压缩") + color.Greenln("|-" + translate.Get("commands.panel.backup.exportSuccess")) + color.Greenln("|-" + translate.Get("commands.panel.backup.startCompress")) if _, err = tools.Exec("cd /tmp && zip -r " + backupFile + ".zip " + backupFile); err != nil { - color.Redln("|-压缩失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.backup.compressFail") + ": " + err.Error()) return nil } if err := tools.Remove("/tmp/" + backupFile); err != nil { - color.Redln("|-删除失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.backup.deleteFail") + ": " + err.Error()) return nil } - color.Greenln("|-压缩成功") - color.Greenln("|-开始移动") + color.Greenln("|-" + translate.Get("commands.panel.backup.compressSuccess")) + color.Greenln("|-" + translate.Get("commands.panel.backup.startMove")) if err := tools.Mv("/tmp/"+backupFile+".zip", path+"/"+backupFile+".zip"); err != nil { - color.Redln("|-移动失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.backup.moveFail") + ": " + err.Error()) return nil } - color.Greenln("|-移动成功") + color.Greenln("|-" + translate.Get("commands.panel.backup.moveSuccess")) _ = os.Unsetenv("MYSQL_PWD") - color.Greenln("|-备份成功") + color.Greenln("|-" + translate.Get("commands.panel.backup.success")) case "postgresql": backupFile := name + "_" + carbon.Now().ToShortDateTimeString() + ".sql" check, err := tools.Exec(`su - postgres -c "psql -l" 2>&1`) if err != nil { - color.Redln("|-获取数据库失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.backup.databaseGetFail") + ": " + err.Error()) color.Greenln(hr) return nil } if !strings.Contains(check, name) { - color.Redln("|-数据库不存在") + color.Redln("|-" + translate.Get("commands.panel.backup.databaseNotExist")) color.Greenln(hr) return nil } - color.Greenln("|-目标PostgreSQL数据库: " + name) - color.Greenln("|-开始导出") + color.Greenln("|-" + translate.Get("commands.panel.backup.targetPostgres") + ": " + name) + color.Greenln("|-" + translate.Get("commands.panel.backup.startExport")) if _, err = tools.Exec(`su - postgres -c "pg_dump '` + name + `'" > /tmp/` + backupFile + ` 2>&1`); err != nil { - color.Redln("|-导出失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.backup.exportFail") + ": " + err.Error()) return nil } - color.Greenln("|-导出成功") - color.Greenln("|-开始压缩") + color.Greenln("|-" + translate.Get("commands.panel.backup.exportSuccess")) + color.Greenln("|-" + translate.Get("commands.panel.backup.startCompress")) if _, err = tools.Exec("cd /tmp && zip -r " + backupFile + ".zip " + backupFile); err != nil { - color.Redln("|-压缩失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.backup.compressFail") + ": " + err.Error()) return nil } if err := tools.Remove("/tmp/" + backupFile); err != nil { - color.Redln("|-删除失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.backup.deleteFail") + ": " + err.Error()) return nil } - color.Greenln("|-压缩成功") - color.Greenln("|-开始移动") + color.Greenln("|-" + translate.Get("commands.panel.backup.compressSuccess")) + color.Greenln("|-" + translate.Get("commands.panel.backup.startMove")) if err := tools.Mv("/tmp/"+backupFile+".zip", path+"/"+backupFile+".zip"); err != nil { - color.Redln("|-移动失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.backup.moveFail") + ": " + err.Error()) return nil } - color.Greenln("|-移动成功") - color.Greenln("|-备份成功") + color.Greenln("|-" + translate.Get("commands.panel.backup.moveSuccess")) + color.Greenln("|-" + translate.Get("commands.panel.backup.success")) } color.Greenln(hr) files, err := os.ReadDir(path) if err != nil { - color.Redln("|-清理失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.backup.cleanupFail") + ": " + err.Error()) return nil } var filteredFiles []os.FileInfo @@ -385,15 +385,15 @@ func (receiver *Panel) Handle(ctx console.Context) error { }) for i := cast.ToInt(save); i < len(filteredFiles); i++ { fileToDelete := filepath.Join(path, filteredFiles[i].Name()) - color.Yellowln("|-清理备份: " + fileToDelete) + color.Yellowln("|-" + translate.Get("commands.panel.backup.cleanBackup") + ": " + fileToDelete) if err := tools.Remove(fileToDelete); err != nil { - color.Redln("|-清理失败: " + err.Error()) + color.Redln("|-" + translate.Get("commands.panel.backup.cleanupFail") + ": " + err.Error()) return nil } } - color.Greenln("|-清理完成") + color.Greenln("|-" + translate.Get("commands.panel.backup.cleanupSuccess")) color.Greenln(hr) - color.Greenln("☆ 备份完成 [" + carbon.Now().ToDateTimeString() + "]") + color.Greenln("☆ " + translate.Get("commands.panel.backup.success") + " [" + carbon.Now().ToDateTimeString() + "]") color.Greenln(hr) case "cutoff": @@ -576,14 +576,14 @@ func (receiver *Panel) Handle(ctx console.Context) error { path := arg4 php := arg5 if len(name) == 0 || len(domain) == 0 || len(port) == 0 || len(path) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.addSite.paramFail")) return nil } domains := strings.Split(domain, ",") ports := strings.Split(port, ",") if len(domains) == 0 || len(ports) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.addSite.paramFail")) return nil } @@ -599,7 +599,7 @@ func (receiver *Panel) Handle(ctx console.Context) error { return nil } if id != 0 { - color.Redln("网站名已存在") + color.Redln(translate.Get("commands.panel.addSite.siteExist")) return nil } @@ -618,12 +618,12 @@ func (receiver *Panel) Handle(ctx console.Context) error { return nil } - color.Greenln("网站添加成功") + color.Greenln(translate.Get("commands.panel.addSite.success")) case "removeSite": name := arg1 if len(name) == 0 { - color.Redln("参数错误") + color.Redln(translate.Get("commands.panel.removeSite.paramFail")) return nil } @@ -634,7 +634,7 @@ func (receiver *Panel) Handle(ctx console.Context) error { return nil } if id == 0 { - color.Redln("网站名不存在") + color.Redln(translate.Get("commands.panel.removeSite.siteNotExist")) return nil } @@ -643,7 +643,7 @@ func (receiver *Panel) Handle(ctx console.Context) error { return nil } - color.Greenln("网站删除成功") + color.Greenln(translate.Get("commands.panel.removeSite.success")) case "installPlugin": slug := arg1 diff --git a/app/http/controllers/controller.go b/app/http/controllers/controller.go index c5fe445c..66014cb1 100644 --- a/app/http/controllers/controller.go +++ b/app/http/controllers/controller.go @@ -2,6 +2,7 @@ package controllers import ( "github.com/goravel/framework/contracts/http" + "github.com/goravel/framework/facades" ) // SuccessResponse 通用成功响应 @@ -26,14 +27,14 @@ func Success(ctx http.Context, data any) http.Response { // Error 响应错误 func Error(ctx http.Context, code int, message string) http.Response { return ctx.Response().Json(code, &ErrorResponse{ - Message: "错误: " + message, + Message: facades.Lang(ctx).Get("messages.mistake") + ": " + message, }) } // ErrorSystem 响应系统错误 func ErrorSystem(ctx http.Context) http.Response { return ctx.Response().Json(http.StatusInternalServerError, &ErrorResponse{ - Message: "系统内部错误", + Message: facades.Lang(ctx).Get("errors.internal"), }) } diff --git a/app/http/middleware/jwt.go b/app/http/middleware/jwt.go index b862271c..1e6bc8f8 100644 --- a/app/http/middleware/jwt.go +++ b/app/http/middleware/jwt.go @@ -11,10 +11,11 @@ import ( // Jwt 确保通过 JWT 鉴权 func Jwt() http.Middleware { return func(ctx http.Context) { + translate := facades.Lang(ctx) token := ctx.Request().Header("Authorization", ctx.Request().Header("Sec-WebSocket-Protocol")) if len(token) == 0 { ctx.Request().AbortWithStatusJson(http.StatusUnauthorized, http.Json{ - "message": "未登录", + "message": translate.Get("auth.token.missing"), }) return } @@ -26,7 +27,7 @@ func Jwt() http.Middleware { if err != nil { // 到达刷新时间上限 ctx.Request().AbortWithStatusJson(http.StatusUnauthorized, http.Json{ - "message": "登录已过期", + "message": translate.Get("auth.token.expired"), }) return } @@ -34,7 +35,7 @@ func Jwt() http.Middleware { token = "Bearer " + token } else { ctx.Request().AbortWithStatusJson(http.StatusUnauthorized, http.Json{ - "message": "登录已过期", + "message": translate.Get("auth.token.expired"), }) return } diff --git a/app/http/middleware/must_install.go b/app/http/middleware/must_install.go index 6768854a..46bcb7fb 100644 --- a/app/http/middleware/must_install.go +++ b/app/http/middleware/must_install.go @@ -4,6 +4,8 @@ import ( "strings" "github.com/goravel/framework/contracts/http" + "github.com/goravel/framework/contracts/translation" + "github.com/goravel/framework/facades" "panel/internal/services" ) @@ -12,6 +14,7 @@ import ( func MustInstall() http.Middleware { return func(ctx http.Context) { path := ctx.Request().Path() + translate := facades.Lang(ctx) var slug string if strings.HasPrefix(path, "/api/panel/website") { slug = "openresty" @@ -19,7 +22,7 @@ func MustInstall() http.Middleware { pathArr := strings.Split(path, "/") if len(pathArr) < 4 { ctx.Request().AbortWithStatusJson(http.StatusForbidden, http.Json{ - "message": "插件不存在", + "message": translate.Get("errors.plugin.notExist"), }) return } @@ -31,14 +34,18 @@ func MustInstall() http.Middleware { installedPlugins, err := services.NewPluginImpl().AllInstalled() if err != nil { ctx.Request().AbortWithStatusJson(http.StatusInternalServerError, http.Json{ - "message": "系统内部错误", + "message": translate.Get("errors.internal"), }) return } if installedPlugin.Slug != plugin.Slug { ctx.Request().AbortWithStatusJson(http.StatusForbidden, http.Json{ - "message": "插件 " + slug + " 未安装", + "message": translate.Get("errors.plugin.notInstalled", translation.Option{ + Replace: map[string]string{ + "slug": slug, + }, + }), }) return } @@ -53,7 +60,12 @@ func MustInstall() http.Middleware { _, requireFound := pluginsMap[require] if !requireFound { ctx.Request().AbortWithStatusJson(http.StatusForbidden, http.Json{ - "message": "插件 " + slug + " 需要依赖 " + require + " 插件", + "message": translate.Get("errors.plugin.dependent", translation.Option{ + Replace: map[string]string{ + "slug": slug, + "dependency": require, + }, + }), }) return } @@ -63,7 +75,12 @@ func MustInstall() http.Middleware { _, excludeFound := pluginsMap[exclude] if excludeFound { ctx.Request().AbortWithStatusJson(http.StatusForbidden, http.Json{ - "message": "插件 " + slug + " 不兼容 " + exclude + " 插件", + "message": translate.Get("errors.plugin.incompatible", translation.Option{ + Replace: map[string]string{ + "slug": slug, + "exclude": exclude, + }, + }), }) return } diff --git a/app/http/middleware/status.go b/app/http/middleware/status.go index c9525c1a..1964ee04 100644 --- a/app/http/middleware/status.go +++ b/app/http/middleware/status.go @@ -2,6 +2,7 @@ package middleware import ( "github.com/goravel/framework/contracts/http" + "github.com/goravel/framework/facades" "panel/internal" ) @@ -9,25 +10,26 @@ import ( // Status 检查程序状态 func Status() http.Middleware { return func(ctx http.Context) { + translate := facades.Lang(ctx) switch internal.Status { case internal.StatusUpgrade: ctx.Request().AbortWithStatusJson(http.StatusServiceUnavailable, http.Json{ - "message": "面板升级中,请稍后", + "message": translate.Get("status.upgrade"), }) return case internal.StatusMaintain: ctx.Request().AbortWithStatusJson(http.StatusServiceUnavailable, http.Json{ - "message": "面板正在运行维护,请稍后", + "message": translate.Get("status.maintain"), }) return case internal.StatusClosed: ctx.Request().AbortWithStatusJson(http.StatusForbidden, http.Json{ - "message": "面板已关闭", + "message": translate.Get("status.closed"), }) return case internal.StatusFailed: ctx.Request().AbortWithStatusJson(http.StatusInternalServerError, http.Json{ - "message": "面板运行出错,请检查排除或联系支持", + "message": translate.Get("status.failed"), }) return default: diff --git a/lang/en.json b/lang/en.json index df706fc7..43eb7101 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1,10 +1,17 @@ { + "auth": { + "token": { + "expired": "login has expired", + "missing": "not logged in" + } + }, "commands": { "panel:cert-renew": { "description": "[Panel] Certificate renewal" }, "panel:monitoring": { - "description": "[Panel] System Monitoring" + "description": "[Panel] System Monitoring", + "fail": "[Panel] System monitoring failed to save" }, "panel": { "description": "[Panel] Command line", @@ -47,7 +54,33 @@ "success": "tasks cleaned up successfully" }, "backup": { - "description": "back up website/MySQL database/PostgreSQL database to the specified directory and retain the specified amount" + "description": "back up website/MySQL database/PostgreSQL database to the specified directory and retain the specified amount", + "paramFail": "backup type, path, name and keep amount are required", + "start": "start backup", + "backupDirFail": "failed to create backup directory", + "targetSite": "target website", + "siteNotExist": "website does not exist", + "backupFail": "backup failed", + "backupSuccess": "backup successful", + "mysqlBackupFail": "MySQL database backup failed", + "targetMysql": "target MySQL database", + "startExport": "start exporting", + "exportFail": "export failed", + "exportSuccess": "export successful", + "startCompress": "start compressing", + "compressFail": "compression failed", + "compressSuccess": "compression successful", + "startMove": "start moving", + "moveFail": "move failed", + "moveSuccess": "move successful", + "databaseGetFail": "failed to get database", + "databaseNotExist": "database does not exist", + "targetPostgres": "target PostgreSQL database", + "cleanBackup" : "clean backup", + "cleanupFail": "cleanup failed", + "cleanupSuccess": "cleanup successful", + "deleteFail": "failed to delete", + "success": "backup completed" }, "cutoff": { "description": "cut website logs and keep specified amount", @@ -80,10 +113,16 @@ "success": "task has been submitted" }, "addSite": { - "description": "add website [domain name and port separated by commas]" + "description": "add website [domain name and port separated by commas]", + "paramFail": "name, domain, port and path are required", + "siteExist": "website already exists", + "success": "website added successfully" }, "removeSite": { - "description": "remove website" + "description": "remove website", + "paramFail": "name is required", + "siteNotExist": "website does not exist", + "success": "website deleted successfully" }, "init": { "description": "initialize the panel", @@ -144,5 +183,23 @@ "panel:task": { "description": "[Panel] Daily tasks" } + }, + "errors": { + "internal": "internal system error", + "plugin": { + "notExist": "plugin does not exist", + "notInstalled": "plugin :slug is not installed", + "dependent": "plugin :slug requires dependency :dependency", + "incompatible": "plugin :slug is incompatible with :exclude plugin" + } + }, + "messages": { + "mistake": "mistake" + }, + "status": { + "upgrade": "Panel is currently undergoing an upgrade. Please try again later.", + "maintain": "Panel is currently undergoing maintenance. Please try again later.", + "closed": "Panel is closed.", + "failed": "Panel encountered an error during operation. Please check the troubleshooting or contact support." } } \ No newline at end of file diff --git a/lang/zh_CN.json b/lang/zh_CN.json index 84d618ba..40ffbf76 100644 --- a/lang/zh_CN.json +++ b/lang/zh_CN.json @@ -1,10 +1,17 @@ { + "auth": { + "token": { + "expired": "登录已过期", + "missing": "未登录" + } + }, "commands": { "panel:cert-renew": { "description": "[面板] 证书续签" }, "panel:monitoring": { - "description": "[面板] 系统监控" + "description": "[面板] 系统监控", + "fail": "[面板] 系统监控保存失败" }, "panel": { "description": "[面板] 命令行", @@ -47,7 +54,33 @@ "success": "清理任务成功" }, "backup": { - "description": "备份网站 / MySQL数据库 / PostgreSQL数据库到指定目录并保留指定数量" + "description": "备份网站 / MySQL数据库 / PostgreSQL数据库到指定目录并保留指定数量", + "paramFail": "参数错误", + "start": "开始备份", + "backupDirFail": "创建备份目录失败", + "targetSite": "目标网站", + "siteNotExist": "网站不存在", + "backupFail": "备份失败", + "backupSuccess": "备份成功", + "mysqlBackupFail": "备份MySQL数据库失败", + "targetMysql": "目标MySQL数据库", + "startExport": "开始导出", + "exportFail": "导出失败", + "exportSuccess": "导出成功", + "startCompress": "开始压缩", + "compressFail": "压缩失败", + "compressSuccess": "压缩成功", + "startMove": "开始移动", + "moveFail": "移动失败", + "moveSuccess": "移动成功", + "databaseGetFail": "获取数据库失败", + "databaseNotExist": "数据库不存在", + "targetPostgres": "目标PostgreSQL数据库", + "cleanBackup": "清理备份", + "cleanupFail": "清理失败", + "cleanupSuccess": "清理完成", + "deleteFail": "删除失败", + "success": "备份完成" }, "cutoff": { "description": "切割网站日志并保留指定数量", @@ -80,10 +113,16 @@ "success": "任务已提交" }, "addSite": { - "description": "添加网站[域名和端口用英文逗号分隔]" + "description": "添加网站[域名和端口用英文逗号分隔]", + "paramFail": "参数错误", + "siteExist": "网站名已存在", + "success": "网站添加成功" }, "removeSite": { - "description": "删除网站" + "description": "删除网站", + "paramFail": "参数错误", + "siteNotExist": "网站名不存在", + "success": "网站删除成功" }, "init": { "description": "初始化面板", @@ -144,5 +183,23 @@ "panel:task": { "description": "[面板] 每日任务" } + }, + "errors": { + "internal": "系统内部错误", + "plugin": { + "notExist": "插件不存在", + "notInstalled": "插件 :slug 未安装", + "dependent": "插件 :slug 需要依赖 :dependency 插件", + "incompatible": "插件 :slug 不兼容 :exclude 插件" + } + }, + "messages": { + "mistake": "错误" + }, + "status": { + "upgrade": "面板升级中,请稍后", + "maintain": "面板正在运行维护,请稍后", + "closed": "面板已关闭", + "failed": "面板运行出错,请检查排除或联系支持" } } \ No newline at end of file