mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48: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> | |
|
||||
| ![默认主题魔改](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)
|
||||
- [中文文档](docs/UserGuide_zh.md)
|
||||
|
@ -69,6 +69,8 @@ func (mp *memberPage) notification(c *gin.Context) {
|
||||
|
||||
func (mp *memberPage) setting(c *gin.Context) {
|
||||
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"
|
||||
)
|
||||
|
||||
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 (
|
||||
ConfigTypeGitHub = "github"
|
||||
ConfigTypeGitee = "gitee"
|
||||
|
@ -68,14 +68,3 @@ 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
|
||||
}
|
||||
|
3
resource/l10n/zh-CN.toml
vendored
3
resource/l10n/zh-CN.toml
vendored
@ -271,9 +271,6 @@ other = "管理员列表"
|
||||
[Theme]
|
||||
other = "主题"
|
||||
|
||||
[DefaultTheme]
|
||||
other = "默认主题"
|
||||
|
||||
[CustomCodes]
|
||||
other = "自定义代码(style、script 都可以)"
|
||||
|
||||
|
@ -15,22 +15,18 @@
|
||||
<div class="field">
|
||||
<label>{{tr "Theme"}}</label>
|
||||
<select name="Theme">
|
||||
<option value="default" {{if eq .Conf.Site.Theme "default" }} selected="selected" {{end}}>{{tr "DefaultTheme"}}
|
||||
</option>
|
||||
<option value="daynight" {{if eq .Conf.Site.Theme "daynight" }} selected="selected" {{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>
|
||||
{{range $k,$v := .Themes}}
|
||||
<option value="{{$k}}" {{if eq $.Conf.Site.Theme $k }} selected="selected" {{end}}>{{$v}}
|
||||
{{end}}
|
||||
</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>
|
||||
{{range $k,$v := .Languages}}
|
||||
<option value="{{$k}}" {{if eq $.Conf.Language $k }} selected="selected" {{end}}>
|
||||
{{$v}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
|
@ -4,9 +4,10 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/naiba/nezha/pkg/utils"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/naiba/nezha/model"
|
||||
)
|
||||
|
||||
var Localizer *i18n.Localizer
|
||||
@ -15,13 +16,11 @@ func InitLocalizer() {
|
||||
bundle := i18n.NewBundle(language.Chinese)
|
||||
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
|
||||
|
||||
userCustomLanguageFile := "resource/l10n/" + Conf.Language + ".toml"
|
||||
|
||||
if exists, err := utils.PathExists(userCustomLanguageFile); !exists {
|
||||
log.Println("NEZHA>> language file not found:", userCustomLanguageFile, err)
|
||||
if _, exists := model.Languages[Conf.Language]; !exists {
|
||||
log.Println("NEZHA>> language not exists:", Conf.Language)
|
||||
Conf.Language = "zh-CN"
|
||||
} else {
|
||||
_, err := bundle.LoadMessageFile(userCustomLanguageFile)
|
||||
_, err := bundle.LoadMessageFile("resource/l10n/" + Conf.Language + ".toml")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user