mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-07 23:23:08 +08:00
🎨 Plugin i18n
This commit is contained in:
parent
2ebc265996
commit
abc87ba9ea
@ -104,9 +104,40 @@ func LoadPetals() (ret []*Petal) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i18nPath := filepath.Join(pluginDir, "i18n", Conf.Lang)
|
i18nDir := filepath.Join(pluginDir, "i18n")
|
||||||
if gulu.File.IsExist(i18nPath) {
|
if gulu.File.IsDir(i18nDir) {
|
||||||
data, err := filelock.ReadFile(i18nPath)
|
langJSONs, err := os.ReadDir(i18nDir)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("read plugin [%s] i18n failed: %s", petal.Name, err)
|
||||||
|
} else {
|
||||||
|
preferredLang := Conf.Lang + ".json"
|
||||||
|
foundPreferredLang := false
|
||||||
|
foundEnUS := false
|
||||||
|
foundZhCN := false
|
||||||
|
for _, langJSON := range langJSONs {
|
||||||
|
if langJSON.Name() == preferredLang {
|
||||||
|
foundPreferredLang = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if langJSON.Name() == "en_US.json" {
|
||||||
|
foundEnUS = true
|
||||||
|
}
|
||||||
|
if langJSON.Name() == "zh_CN.json" {
|
||||||
|
foundZhCN = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !foundPreferredLang {
|
||||||
|
if foundEnUS {
|
||||||
|
preferredLang = "en_US.json"
|
||||||
|
} else if foundZhCN {
|
||||||
|
preferredLang = "zh_CN.json"
|
||||||
|
} else {
|
||||||
|
preferredLang = langJSONs[0].Name()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := filelock.ReadFile(filepath.Join(i18nDir, preferredLang))
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("read plugin [%s] i18n failed: %s", petal.Name, err)
|
logging.LogErrorf("read plugin [%s] i18n failed: %s", petal.Name, err)
|
||||||
} else {
|
} else {
|
||||||
@ -116,6 +147,7 @@ func LoadPetals() (ret []*Petal) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = append(ret, petal)
|
ret = append(ret, petal)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user