🎨 切换到新的工作空间时优先使用系统语言 Fix https://github.com/siyuan-note/siyuan/issues/5355

This commit is contained in:
Liang Ding 2022-07-06 21:58:34 +08:00
parent 346336c588
commit 747f4eb779
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
5 changed files with 44 additions and 5 deletions

View file

@ -56,6 +56,7 @@ require (
dmitri.shuralyov.com/font/woff2 v0.0.0-20180220214647-957792cbbdab // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Xuanwo/go-locale v1.1.0 // indirect
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect
@ -112,7 +113,8 @@ require (
replace github.com/mattn/go-sqlite3 => github.com/88250/go-sqlite3 v1.14.13-0.20220412041952-88c3aaa8595e
//replace github.com/siyuan-note/dejavu => D:\88250\dejavu
replace github.com/siyuan-note/dejavu => D:\88250\dejavu
//replace github.com/siyuan-note/httpclient => D:\88250\httpclient
//replace github.com/siyuan-note/filelock => D:\88250\filelock
//replace github.com/88250/lute => D:\gogogo\src\github.com\88250\lute

View file

@ -73,6 +73,8 @@ github.com/Masterminds/sprig/v3 v3.2.2 h1:17jRggJu518dr3QaafizSXOjKYp94wKfABxUmy
github.com/Masterminds/sprig/v3 v3.2.2/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk=
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
github.com/Xuanwo/go-locale v1.1.0 h1:51gUxhxl66oXAjI9uPGb2O0qwPECpriKQb2hl35mQkg=
github.com/Xuanwo/go-locale v1.1.0/go.mod h1:UKrHoZB3FPIk9wIG2/tVSobnHgNnceGSH3Y8DY5cASs=
github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek=
github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s=
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
@ -435,6 +437,7 @@ github.com/siyuan-note/httpclient v0.0.0-20220629022115-8de64709cc5e h1:5tKpe6Yu
github.com/siyuan-note/httpclient v0.0.0-20220629022115-8de64709cc5e/go.mod h1:UTb1xAQC/eCSDklGWp8qQYlY0+qrVA3+MyOIKcliRLg=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v1.6.7/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
@ -663,6 +666,7 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211020174200-9d6173849985/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211023085530-d6a326fbbf70/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e h1:CsOuNlbOuf0mzxJIefr6Q4uAUetRUwZE4qt7VfzP+xo=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

View file

@ -32,6 +32,7 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute"
"github.com/Xuanwo/go-locale"
humanize "github.com/dustin/go-humanize"
"github.com/getsentry/sentry-go"
"github.com/siyuan-note/filelock"
@ -39,6 +40,7 @@ import (
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
"golang.org/x/text/language"
)
var Conf *AppConf
@ -84,7 +86,7 @@ func InitConf() {
}
}
Conf = &AppConf{LogLevel: "debug", Lang: util.Lang}
Conf = &AppConf{LogLevel: "debug"}
confPath := filepath.Join(util.ConfDir, "conf.json")
if gulu.File.IsExist(confPath) {
data, err := os.ReadFile(confPath)
@ -97,6 +99,37 @@ func InitConf() {
}
}
if "" != util.Lang {
Conf.Lang = util.Lang
util.LogInfof("initialized the specified language [%s]", util.Lang)
} else {
if "" == Conf.Lang {
// 未指定外观语言时使用系统语言
if userLang, err := locale.Detect(); nil == err {
var supportLangs []language.Tag
for lang := range langs {
if tag, err := language.Parse(lang); nil == err {
supportLangs = append(supportLangs, tag)
} else {
util.LogErrorf("load language [%s] failed: %s", lang, err)
}
}
matcher := language.NewMatcher(supportLangs)
lang, _, _ := matcher.Match(userLang)
base, _ := lang.Base()
region, _ := lang.Region()
util.Lang = base.String() + "_" + region.String()
Conf.Lang = util.Lang
util.LogInfof("initialized language [%s] based on device locale", Conf.Lang)
} else {
util.LogDebugf("check device locale failed [%s], using default language [en_US]", err)
util.Lang = "en_US"
Conf.Lang = util.Lang
}
}
}
Conf.Langs = loadLangs()
if nil == Conf.Appearance {
Conf.Appearance = conf.NewAppearance()

View file

@ -72,7 +72,7 @@ func SyncData(boot, exit, byHand bool) {
}
if util.IsMutexLocked(&syncLock) {
util.LogWarnf("a cloud sync operation still processing")
util.LogWarnf("sync is in progress")
planSyncAfter(30 * time.Second)
return
}

View file

@ -64,7 +64,7 @@ func Boot() {
readOnly := flag.Bool("readonly", false, "read-only mode")
accessAuthCode := flag.String("accessAuthCode", "", "access auth code")
ssl := flag.Bool("ssl", false, "for https and wss")
lang := flag.String("lang", "en_US", "zh_CN/zh_CHT/en_US/fr_FR/es_ES")
lang := flag.String("lang", "", "zh_CN/zh_CHT/en_US/fr_FR/es_ES")
mode := flag.String("mode", "prod", "dev/prod")
flag.Parse()
@ -272,7 +272,7 @@ var (
Resident bool
ReadOnly bool
AccessAuthCode string
Lang = "en_US"
Lang = ""
Container string // docker, android, ios, std
)