mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-06-28 15:45:35 +08:00
feat: 配置管理中增加本地化切换
This commit is contained in:
parent
b0234582f8
commit
0e92e0e2b4
@ -234,6 +234,9 @@ func RegisterCommand() {
|
|||||||
} else if len(os.Args) >= 2 && os.Args[1] == "version" {
|
} else if len(os.Args) >= 2 && os.Args[1] == "version" {
|
||||||
CheckUpdate()
|
CheckUpdate()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
} else if len(os.Args) >= 2 && os.Args[1] == "update" {
|
||||||
|
Update()
|
||||||
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,12 @@ package commands
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/mindoc-org/mindoc/models"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
@ -47,3 +49,23 @@ func CheckUpdate() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Update() {
|
||||||
|
fmt.Println("Update...")
|
||||||
|
RegisterDataBase()
|
||||||
|
RegisterModel()
|
||||||
|
err := orm.RunSyncdb("default", false, true)
|
||||||
|
if err == nil {
|
||||||
|
UpdateInitialization()
|
||||||
|
} else {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
fmt.Println("Update Successfully!")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
func UpdateInitialization() {
|
||||||
|
err := models.NewOption().Update()
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -502,6 +502,9 @@ edit_user = Edit User
|
|||||||
pwd_tips = Please leave it blank if you do not change the password, only local users can change the password
|
pwd_tips = Please leave it blank if you do not change the password, only local users can change the password
|
||||||
|
|
||||||
[mgr]
|
[mgr]
|
||||||
|
language = Default Language
|
||||||
|
zh_cn = 简体中文
|
||||||
|
en_us = English
|
||||||
dashboard_menu = Dashboard
|
dashboard_menu = Dashboard
|
||||||
user_menu = User
|
user_menu = User
|
||||||
team_menu = Team
|
team_menu = Team
|
||||||
|
@ -502,6 +502,9 @@ edit_user = 编辑用户
|
|||||||
pwd_tips = 不修改密码请留空,只支持本地用户修改密码
|
pwd_tips = 不修改密码请留空,只支持本地用户修改密码
|
||||||
|
|
||||||
[mgr]
|
[mgr]
|
||||||
|
language = 默认语言
|
||||||
|
zh_cn = 简体中文
|
||||||
|
en_us = English
|
||||||
dashboard_menu = 仪表盘
|
dashboard_menu = 仪表盘
|
||||||
user_menu = 用户管理
|
user_menu = 用户管理
|
||||||
team_menu = 团队管理
|
team_menu = 团队管理
|
||||||
|
@ -3,6 +3,7 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -217,8 +218,13 @@ func (c *BaseController) SetLang() {
|
|||||||
}
|
}
|
||||||
if len(lang) == 0 ||
|
if len(lang) == 0 ||
|
||||||
!i18n.IsExist(lang) {
|
!i18n.IsExist(lang) {
|
||||||
|
fmt.Println("c.Data[item.OptionName]", c.Data["language"])
|
||||||
|
if c.Data["language"] != nil {
|
||||||
|
lang = c.Data["language"].(string)
|
||||||
|
} else {
|
||||||
lang, _ = web.AppConfig.String("default_lang")
|
lang, _ = web.AppConfig.String("default_lang")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if !hasCookie {
|
if !hasCookie {
|
||||||
c.Ctx.SetCookie("lang", lang, 1<<31-1, "/")
|
c.Ctx.SetCookie("lang", lang, 1<<31-1, "/")
|
||||||
}
|
}
|
||||||
|
@ -164,5 +164,30 @@ func (m *Option) Init() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !o.QueryTable(m.TableNameWithPrefix()).Filter("option_name", "language").Exist() {
|
||||||
|
option := NewOption()
|
||||||
|
option.OptionValue = "zh-cn"
|
||||||
|
option.OptionName = "language"
|
||||||
|
option.OptionTitle = "站点语言"
|
||||||
|
if _, err := o.Insert(option); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Option) Update() error {
|
||||||
|
o := orm.NewOrm()
|
||||||
|
|
||||||
|
if !o.QueryTable(m.TableNameWithPrefix()).Filter("option_name", "language").Exist() {
|
||||||
|
option := NewOption()
|
||||||
|
option.OptionValue = "zh-cn"
|
||||||
|
option.OptionName = "language"
|
||||||
|
option.OptionTitle = "站点语言"
|
||||||
|
if _, err := o.Insert(option); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,13 @@
|
|||||||
<label>{{i18n .Lang "mgr.site_desc"}}</label>
|
<label>{{i18n .Lang "mgr.site_desc"}}</label>
|
||||||
<textarea rows="3" class="form-control" name="site_description" style="height: 90px" placeholder="{{i18n .Lang "mgr.site_desc"}}">{{.site_description}}</textarea>
|
<textarea rows="3" class="form-control" name="site_description" style="height: 90px" placeholder="{{i18n .Lang "mgr.site_desc"}}">{{.site_description}}</textarea>
|
||||||
<p class="text">{{i18n .Lang "mgr.site_desc_tips"}}</p>
|
<p class="text">{{i18n .Lang "mgr.site_desc_tips"}}</p>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>{{i18n .Lang "mgr.language"}}</label>
|
||||||
|
<select name="language" class="form-control">
|
||||||
|
<option value="zh-cn" {{if eq .language "zh-cn"}}selected{{end}}>{{i18n .Lang "mgr.zh_cn"}}</option>
|
||||||
|
<option value="en-us" {{if eq .language "en-us"}}selected{{end}}>{{i18n .Lang "mgr.en_us"}}</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>{{i18n .Lang "mgr.enable_anonymous_access"}}</label>
|
<label>{{i18n .Lang "mgr.enable_anonymous_access"}}</label>
|
||||||
@ -123,6 +130,7 @@
|
|||||||
},success : function (res) {
|
},success : function (res) {
|
||||||
if(res.errcode === 0) {
|
if(res.errcode === 0) {
|
||||||
showSuccess({{i18n .Lang "message.success"}})
|
showSuccess({{i18n .Lang "message.success"}})
|
||||||
|
window.location.reload()
|
||||||
}else{
|
}else{
|
||||||
showError(res.message);
|
showError(res.message);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user