mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 20:58:14 -05:00
♻️ refactor settings page [skip ci]
This commit is contained in:
parent
c2625240c4
commit
2fc4939878
12
README.md
12
README.md
@ -22,9 +22,17 @@
|
|||||||
| <div align="center"><b>Default modified <a href="https://ii.do/43.html">[Guide]</a></b></div> | <div align="center"><b>Neko Mdui <a href="https://github.com/MikoyChinese">@MikoyChinese</a></b></div> | |
|
| <div align="center"><b>Default modified <a href="https://ii.do/43.html">[Guide]</a></b></div> | <div align="center"><b>Neko Mdui <a href="https://github.com/MikoyChinese">@MikoyChinese</a></b></div> | |
|
||||||
| ![默认主题魔改](https://fastly.jsdelivr.net/gh/idarku/img@main/me/1631120192341.webp) | ![Neko Mdui](resource/template/theme-mdui/screenshot.png) | |
|
| ![默认主题魔改](https://fastly.jsdelivr.net/gh/idarku/img@main/me/1631120192341.webp) | ![Neko Mdui](resource/template/theme-mdui/screenshot.png) | |
|
||||||
|
|
||||||
## User Guide
|
## Supported Languages
|
||||||
|
|
||||||
[![Crowdin](https://badges.crowdin.net/nezha/localized.svg)](https://crowdin.com/project/nezha)
|
Help us improve translation [![Crowdin](https://badges.crowdin.net/nezha/localized.svg)](https://crowdin.com/project/nezha)
|
||||||
|
|
||||||
|
- English
|
||||||
|
- 简体中文
|
||||||
|
- Español _WIP_
|
||||||
|
|
||||||
|
You can change the system language in the settings page (`/setting`) after the admin panel is installed.
|
||||||
|
|
||||||
|
## User Guide
|
||||||
|
|
||||||
- [English](docs/UserGuide_en.md)
|
- [English](docs/UserGuide_en.md)
|
||||||
- [中文文档](docs/UserGuide_zh.md)
|
- [中文文档](docs/UserGuide_zh.md)
|
||||||
|
@ -70,5 +70,7 @@ func (mp *memberPage) notification(c *gin.Context) {
|
|||||||
func (mp *memberPage) setting(c *gin.Context) {
|
func (mp *memberPage) setting(c *gin.Context) {
|
||||||
c.HTML(http.StatusOK, "dashboard/setting", mygin.CommonEnvironment(c, gin.H{
|
c.HTML(http.StatusOK, "dashboard/setting", mygin.CommonEnvironment(c, gin.H{
|
||||||
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "Settings"}),
|
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "Settings"}),
|
||||||
|
"Languages": model.Languages,
|
||||||
|
"Themes": model.Themes,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,19 @@ import (
|
|||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var Languages = map[string]string{
|
||||||
|
"zh-CN": "简体中文",
|
||||||
|
"en-US": "English",
|
||||||
|
"es-ES": "Español",
|
||||||
|
}
|
||||||
|
|
||||||
|
var Themes = map[string]string{
|
||||||
|
"default": "Default",
|
||||||
|
"daynight": "JackieSung DayNight",
|
||||||
|
"mdui": "Neko Mdui",
|
||||||
|
"hotaru": "Hotaru",
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ConfigTypeGitHub = "github"
|
ConfigTypeGitHub = "github"
|
||||||
ConfigTypeGitee = "gitee"
|
ConfigTypeGitee = "gitee"
|
||||||
|
@ -68,14 +68,3 @@ func IPDesensitize(ipAddr string) string {
|
|||||||
ipAddr = ipv6Desensitize(ipAddr)
|
ipAddr = ipv6Desensitize(ipAddr)
|
||||||
return 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
|
|
||||||
}
|
|
||||||
|
3
resource/l10n/zh-CN.toml
vendored
3
resource/l10n/zh-CN.toml
vendored
@ -271,9 +271,6 @@ other = "管理员列表"
|
|||||||
[Theme]
|
[Theme]
|
||||||
other = "主题"
|
other = "主题"
|
||||||
|
|
||||||
[DefaultTheme]
|
|
||||||
other = "默认主题"
|
|
||||||
|
|
||||||
[CustomCodes]
|
[CustomCodes]
|
||||||
other = "自定义代码(style、script 都可以)"
|
other = "自定义代码(style、script 都可以)"
|
||||||
|
|
||||||
|
@ -15,22 +15,18 @@
|
|||||||
<div class="field">
|
<div class="field">
|
||||||
<label>{{tr "Theme"}}</label>
|
<label>{{tr "Theme"}}</label>
|
||||||
<select name="Theme">
|
<select name="Theme">
|
||||||
<option value="default" {{if eq .Conf.Site.Theme "default" }} selected="selected" {{end}}>{{tr "DefaultTheme"}}
|
{{range $k,$v := .Themes}}
|
||||||
</option>
|
<option value="{{$k}}" {{if eq $.Conf.Site.Theme $k }} selected="selected" {{end}}>{{$v}}
|
||||||
<option value="daynight" {{if eq .Conf.Site.Theme "daynight" }} selected="selected" {{end}}>
|
{{end}}
|
||||||
JackieSung DayNight</option>
|
|
||||||
<option value="hotaru" {{if eq .Conf.Site.Theme "hotaru" }} selected="selected" {{end}}>CokeMine
|
|
||||||
Hotaru</option>
|
|
||||||
<option value="mdui" {{if eq .Conf.Site.Theme "mdui" }} selected="selected" {{end}}>Neko Mdui</option>
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Language</label>
|
<label>Language</label>
|
||||||
<select name="Language">
|
<select name="Language">
|
||||||
<option value="zh-CN" {{if eq .Conf.Language "zh-CN" }} selected="selected" {{end}}>
|
{{range $k,$v := .Languages}}
|
||||||
简体中文</option>
|
<option value="{{$k}}" {{if eq $.Conf.Language $k }} selected="selected" {{end}}>
|
||||||
<option value="en-US" {{if eq .Conf.Language "en-US" }} selected="selected" {{end}}>
|
{{$v}}</option>
|
||||||
English</option>
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
@ -4,9 +4,10 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/naiba/nezha/pkg/utils"
|
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
|
|
||||||
|
"github.com/naiba/nezha/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Localizer *i18n.Localizer
|
var Localizer *i18n.Localizer
|
||||||
@ -15,13 +16,11 @@ func InitLocalizer() {
|
|||||||
bundle := i18n.NewBundle(language.Chinese)
|
bundle := i18n.NewBundle(language.Chinese)
|
||||||
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
|
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
|
||||||
|
|
||||||
userCustomLanguageFile := "resource/l10n/" + Conf.Language + ".toml"
|
if _, exists := model.Languages[Conf.Language]; !exists {
|
||||||
|
log.Println("NEZHA>> language not exists:", Conf.Language)
|
||||||
if exists, err := utils.PathExists(userCustomLanguageFile); !exists {
|
|
||||||
log.Println("NEZHA>> language file not found:", userCustomLanguageFile, err)
|
|
||||||
Conf.Language = "zh-CN"
|
Conf.Language = "zh-CN"
|
||||||
} else {
|
} else {
|
||||||
_, err := bundle.LoadMessageFile(userCustomLanguageFile)
|
_, err := bundle.LoadMessageFile("resource/l10n/" + Conf.Language + ".toml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user