🔖 dashboard v0.13.0 Globalization

This commit is contained in:
naiba 2022-04-30 00:48:39 +08:00
parent fe51b1afdc
commit ade06839b7
11 changed files with 52 additions and 13 deletions

View File

@ -4,7 +4,7 @@
<br>
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
<br><br>
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.12.30&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github">&nbsp;<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/badge/Installer-v0.9.0-brightgreen?style=for-the-badge&logo=linux">
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.13.0&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github">&nbsp;<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/badge/Installer-v0.9.1-brightgreen?style=for-the-badge&logo=linux">&nbsp;<a title="Crowdin" target="_blank" href="https://crowdin.com/project/nezha"><img src="https://badges.crowdin.net/nezha/localized.svg"></a>
<br>
<br>
<p>:trollface: <b>Nezha Monitoring</b> One-stop light monitoring and light operation and maintenance system. Supports system status, HTTP (SSL certificate change, upcoming expiration, expiration), TCP, Ping monitoring and alarm, scheduled tasks and web terminal.</p>
@ -14,7 +14,7 @@
\>> QQ 交流群872069346 **加群要求:已搭建好哪吒监控 & 有 2+ 服务器, 机器人自动审核**
\>> [Use Cases | 我们的用户](https://www.google.com/search?q="powered+by+哪吒监控"&filter=0) (Google)
\>> [Use Cases | 我们的用户](https://www.google.com/search?q=%22powered+by+%E5%93%AA%E5%90%92%E7%9B%91%E6%8E%A7%22+OR+%22powered+by+Nezha+Monitoring%22&filter=0) (Google)
| Default Theme | DayNight [@JackieSung](https://github.com/JackieSung4ev) | hotaru |
| ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------- |

View File

@ -551,6 +551,7 @@ func (ma *memberAPI) logout(c *gin.Context) {
type settingForm struct {
Title string
Admin string
Language string
Theme string
CustomCode string
ViewPassword string
@ -572,6 +573,7 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
})
return
}
singleton.Conf.Language = sf.Language
singleton.Conf.EnableIPChangeNotification = sf.EnableIPChangeNotification == "on"
singleton.Conf.EnablePlainIPInNotification = sf.EnablePlainIPInNotification == "on"
singleton.Conf.Cover = sf.Cover
@ -594,6 +596,8 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
})
return
}
// 更新系统语言
singleton.InitLocalizer()
c.JSON(http.StatusOK, model.Response{
Code: http.StatusOK,
})

View File

@ -108,7 +108,7 @@ func (oa *oauth2controller) callback(c *gin.Context) {
}
var isAdmin bool
for _, admin := range strings.Split(singleton.Conf.Oauth2.Admin, ",") {
if admin != "" && gu.GetLogin() == admin {
if admin != "" && strings.ToLower(gu.GetLogin()) == strings.ToLower(admin) {
isAdmin = true
break
}

View File

@ -68,3 +68,14 @@ func IPDesensitize(ipAddr string) string {
ipAddr = ipv6Desensitize(ipAddr)
return ipAddr
}
func PathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}

View File

@ -1,9 +1,9 @@
{{define "common/menu"}}
<div class="ui large top fixed menu nb-menu">
<div class="ui container">
<div class="item">
<a class="item" href="/">
<img src="/static/logo.svg?v20210804">
</div>
</a>
{{if .IsAdminPage}}
<a class='item{{if eq .MatchedPath "/server"}} active{{end}}' href="/server"><i class="server icon"></i>{{tr "Server"}}</a>
<a class='item{{if eq .MatchedPath "/monitor"}} active{{end}}' href="/monitor"><i class="rss icon"></i>{{tr "Services"}}</a>

View File

@ -24,6 +24,15 @@
<option value="mdui" {{if eq .Conf.Site.Theme "mdui" }} selected="selected" {{end}}>Neko Mdui</option>
</select>
</div>
<div class="field">
<label>Language</label>
<select name="Language">
<option value="zh-CN" {{if eq .Conf.Language "zh-CN" }} selected="selected" {{end}}>
简体中文</option>
<option value="en-US" {{if eq .Conf.Language "en-US" }} selected="selected" {{end}}>
English</option>
</select>
</div>
<div class="field">
<label>{{tr "CustomCodes"}}</label>
<textarea name="CustomCode">{{.Conf.Site.CustomCode}}</textarea>
@ -86,6 +95,7 @@
time: '3',
position: 'top-center',
});
window.location.reload()
} else {
$.suiAlert({
title: '',

View File

@ -1,5 +1,6 @@
debug: false
httpport: 80
language: nz_language
grpcport: nz_grpc_port
oauth2:
type: "nz_oauth2_type" #Oauth2 登录接入类型gitee/github

View File

@ -11,7 +11,7 @@ NZ_BASE_PATH="/opt/nezha"
NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard"
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service"
NZ_VERSION="v0.9.0"
NZ_VERSION="v0.9.1"
red='\033[0;31m'
green='\033[0;32m'

View File

@ -11,7 +11,7 @@ NZ_BASE_PATH="/opt/nezha"
NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard"
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service"
NZ_VERSION="v0.9.0"
NZ_VERSION="v0.9.1"
red='\033[0;31m'
green='\033[0;32m'
@ -290,10 +290,12 @@ modify_dashboard_config() {
sed -i "s/nz_github_oauth_client_id/${nz_github_oauth_client_id}/" ${NZ_DASHBOARD_PATH}/data/config.yaml
sed -i "s/nz_github_oauth_client_secret/${nz_github_oauth_client_secret}/" ${NZ_DASHBOARD_PATH}/data/config.yaml
sed -i "s/nz_site_title/${nz_site_title}/" ${NZ_DASHBOARD_PATH}/data/config.yaml
sed -i "s/nz_language/en-US/" ${NZ_DASHBOARD_PATH}/data/config.yaml
sed -i "s/nz_site_port/${nz_site_port}/" ${NZ_DASHBOARD_PATH}/docker-compose.yaml
sed -i "s/nz_grpc_port/${nz_grpc_port}/g" ${NZ_DASHBOARD_PATH}/docker-compose.yaml
sed -i "s/nz_image_url/${Docker_IMG}/" ${NZ_DASHBOARD_PATH}/docker-compose.yaml
echo -e "Dashboard configuration ${green} modified successfully, please wait for Dashboard self-restart to take effect${plain}"
restart_and_update

View File

@ -1,7 +1,10 @@
package singleton
import (
"log"
"github.com/BurntSushi/toml"
"github.com/naiba/nezha/pkg/utils"
"github.com/nicksnyder/go-i18n/v2/i18n"
"golang.org/x/text/language"
)
@ -11,12 +14,20 @@ var Localizer *i18n.Localizer
func InitLocalizer() {
bundle := i18n.NewBundle(language.Chinese)
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
_, err := bundle.LoadMessageFile("resource/l10n/" + Conf.Language + ".toml")
if err != nil {
panic(err)
userCustomLanguageFile := "resource/l10n/" + Conf.Language + ".toml"
if exists, err := utils.PathExists(userCustomLanguageFile); !exists {
log.Println("NEZHA>> language file not found:", userCustomLanguageFile, err)
Conf.Language = "zh-CN"
} else {
_, err := bundle.LoadMessageFile(userCustomLanguageFile)
if err != nil {
panic(err)
}
}
_, err = bundle.LoadMessageFile("resource/l10n/zh-CN.toml")
if err != nil {
if _, err := bundle.LoadMessageFile("resource/l10n/zh-CN.toml"); err != nil {
panic(err)
}
Localizer = i18n.NewLocalizer(bundle, Conf.Language)

View File

@ -12,7 +12,7 @@ import (
"github.com/naiba/nezha/pkg/utils"
)
var Version = "v0.12.30" // !!记得修改 README 中的 badge 版本!!
var Version = "v0.13.0" // !!记得修改 README 中的 badge 版本!!
var (
Conf *model.Config