Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from mindoc-org:master #89

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,43 @@ func RegisterFunction() {
logs.Error("注册函数 i18n 出错 ->", err)
os.Exit(-1)
}
langs := strings.Split("en-us|zh-cn", "|")
for _, lang := range langs {

i18nList, err := web.AppConfig.String("i18n_list")
if err != nil {
logs.Error("error : failed to read i18n_list config ->", err)
i18nList = ""
}
if i18nList == "" { // 之所以分开判断是因为读取出的配置也可能是空串
logs.Error("error : config `i18n_list` is empty, please add config item like format: `i18n_list=zh-CN:简体中文|en-US:English`")
i18nList = "zh-cn:简体中文|en-us:English|ru-ru:Русский" // 没有配置时给个默认配置,避免啥语言都没有
}

langs := strings.Split(i18nList, "|")
i18nMap := make(map[string]string)
for _, langItem := range langs {
langItemSplit := strings.Split(langItem, ":")
if len(langItemSplit) < 2 {
logs.Error("error: language config value `" + langItem + "` for `i18n_list` format error")
continue
}
lang := langItemSplit[0]
i18nMap[lang] = langItemSplit[1]
if err := i18n.SetMessage(lang, "conf/lang/"+lang+".ini"); err != nil {
logs.Error("Fail to set message file: " + err.Error())
return
}
}

i18nMapBytes, err := json.Marshal(i18nMap)
if err != nil {
logs.Error("error: Fail to marshal i18n map, " + err.Error())
i18nMapBytes = []byte("{}")
}

err = web.AppConfig.Set("i18n_map", string(i18nMapBytes))
if err != nil {
logs.Error("error: Fail to set i18n_map, " + err.Error())
}
}

// 解析命令
Expand Down
1 change: 1 addition & 0 deletions conf/app.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,5 @@ workweixin_agentid="${MINDOC_WORKWEIXIN_AGENTID}"
workweixin_secret="${MINDOC_WORKWEIXIN_SECRET}"

# i18n config
i18n_list=zh-cn:简体中文|en-us:English|ru-ru:Русский
default_lang="zh-cn"
583 changes: 583 additions & 0 deletions conf/lang/ru-ru.ini

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions controllers/ManagerController.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,19 @@ func (c *ManagerController) Setting() {
for _, item := range options {
c.Data[item.OptionName] = item.OptionValue
}

i18nMapStrs, err := web.AppConfig.String("i18n_map")
if err != nil {
logs.Error("web.AppConfig `i18n_map` not found")
i18nMapStrs = "{}"
}
var i18nMap map[string]string
err = json.Unmarshal([]byte(i18nMapStrs), &i18nMap)
if err != nil {
logs.Error("json `i18nList` Unmarshal fail")
i18nMap = make(map[string]string)
}
c.Data["i18n_map"] = i18nMap
}

// Transfer 转让项目.
Expand Down
26 changes: 0 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,58 +22,32 @@ require (
github.com/Azure/go-ntlmssp v0.0.0-20220621081337-cb9428e4ac1e // indirect
github.com/Unknwon/goconfig v1.0.0 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/astaxie/beego v1.12.1 // indirect
github.com/beego/bee v1.12.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cosiner/argv v0.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/flosch/pongo2 v0.0.0-20200529170236-5abacdfa4915 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/gadelkareem/delve v1.4.2-0.20200619175259-dcd01330766f // indirect
github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect
github.com/go-redis/redis/v7 v7.4.1 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gomodule/redigo v2.0.0+incompatible // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.2 // indirect
github.com/peterh/liner v0.0.0-20170317030525-88609521dc4b // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.13.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rivo/uniseg v0.3.4 // indirect
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/smartwalle/pongo2render v1.0.1 // indirect
github.com/smartystreets/goconvey v1.7.2 // indirect
github.com/spf13/afero v1.1.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.3 // indirect
github.com/spf13/viper v1.7.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
go.starlark.net v0.0.0-20190702223751-32f345186213 // indirect
golang.org/x/arch v0.0.0-20190927153633-4e8777c89be4 // indirect
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d // indirect
golang.org/x/image v0.5.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading