Skip to content

Commit

Permalink
🔖 dashboard v0.13.0 Globalization
Browse files Browse the repository at this point in the history
  • Loading branch information
naiba committed Apr 29, 2022
1 parent fe51b1a commit ade0683
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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 |
| ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------- |
Expand Down
4 changes: 4 additions & 0 deletions cmd/dashboard/controller/member_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -594,6 +596,8 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
})
return
}
// 更新系统语言
singleton.InitLocalizer()
c.JSON(http.StatusOK, model.Response{
Code: http.StatusOK,
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/dashboard/controller/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions resource/template/common/menu.html
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
10 changes: 10 additions & 0 deletions resource/template/dashboard/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -86,6 +95,7 @@
time: '3',
position: 'top-center',
});
window.location.reload()
} else {
$.suiAlert({
title: '',
Expand Down
1 change: 1 addition & 0 deletions script/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
debug: false
httpport: 80
language: nz_language
grpcport: nz_grpc_port
oauth2:
type: "nz_oauth2_type" #Oauth2 登录接入类型,gitee/github
Expand Down
2 changes: 1 addition & 1 deletion script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion script/install_en.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
21 changes: 16 additions & 5 deletions service/singleton/l10n.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion service/singleton/singleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ade0683

Please sign in to comment.