mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-22 09:00:10 +00:00
use embed.fs wrapper for langFS so lang/ is not needed in paths
[files]lang_files is now the path to the lang directory, not path to a directory containing it.
This commit is contained in:
parent
98a9e20cc0
commit
e6775cd2d1
@ -867,7 +867,7 @@
|
||||
"requires_restart": true,
|
||||
"type": "text",
|
||||
"value": "",
|
||||
"description": "The path to a directory CONTAINING a 'lang/' directory, which follow the same form as the internal one. See GitHub for more info."
|
||||
"description": "The path to a directory which following the same form as the internal 'lang/' directory. See GitHub for more info."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
22
embed.py
22
embed.py
@ -13,18 +13,30 @@ with open("embed.go", "w") as f:
|
||||
if EMBED in trues:
|
||||
f.write("""package main
|
||||
import (
|
||||
"embed"
|
||||
"log"
|
||||
"embed"
|
||||
"io/fs"
|
||||
"log"
|
||||
)
|
||||
|
||||
//go:embed data data/html data/web data/web/css data/web/js
|
||||
var localFS embed.FS
|
||||
|
||||
//go:embed lang/common lang/admin lang/email lang/form lang/setup
|
||||
var langFS embed.FS
|
||||
var lFS embed.FS
|
||||
|
||||
var langFS LangFS
|
||||
|
||||
type LangFS struct {
|
||||
fs embed.FS
|
||||
}
|
||||
|
||||
func (l LangFS) Open(name string) (fs.File, error) { return l.fs.Open("lang/" + name) }
|
||||
func (l LangFS) ReadDir(name string) ([]fs.DirEntry, error) { return l.fs.ReadDir("lang/" + name) }
|
||||
func (l LangFS) ReadFile(name string) ([]byte, error) { return l.fs.ReadFile("lang/" + name) }
|
||||
|
||||
func loadLocalFS() {
|
||||
log.Println("Using internal storage")
|
||||
langFS = LangFS{lFS}
|
||||
log.Println("Using internal storage")
|
||||
}""")
|
||||
elif EMBED in falses:
|
||||
f.write("""package main
|
||||
@ -42,5 +54,5 @@ func loadLocalFS() {
|
||||
log.Println("Using external storage")
|
||||
executable, _ := os.Executable()
|
||||
localFS = os.DirFS(filepath.Dir(executable))
|
||||
langFS = os.DirFS(filepath.Join(filepath.Dir(executable), "data"))
|
||||
langFS = os.DirFS(filepath.Join(filepath.Dir(executable), "data", "lang"))
|
||||
}""")
|
||||
|
10
main.go
10
main.go
@ -339,10 +339,10 @@ func start(asDaemon, firstCall bool) {
|
||||
}()
|
||||
}
|
||||
|
||||
app.storage.lang.CommonPath = "lang/common"
|
||||
app.storage.lang.FormPath = "lang/form"
|
||||
app.storage.lang.AdminPath = "lang/admin"
|
||||
app.storage.lang.EmailPath = "lang/email"
|
||||
app.storage.lang.CommonPath = "common"
|
||||
app.storage.lang.FormPath = "form"
|
||||
app.storage.lang.AdminPath = "admin"
|
||||
app.storage.lang.EmailPath = "email"
|
||||
externalLang := app.config.Section("files").Key("lang_files").MustString("")
|
||||
var err error
|
||||
if externalLang == "" {
|
||||
@ -577,7 +577,7 @@ func start(asDaemon, firstCall bool) {
|
||||
} else {
|
||||
debugMode = false
|
||||
address = "0.0.0.0:8056"
|
||||
app.storage.lang.SetupPath = "lang/setup"
|
||||
app.storage.lang.SetupPath = "setup"
|
||||
err := app.storage.loadLangSetup(langFS)
|
||||
if err != nil {
|
||||
app.info.Fatalf("Failed to load language files: %+v\n", err)
|
||||
|
Loading…
Reference in New Issue
Block a user