1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-29 12:30:11 +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:
Harvey Tindall 2021-02-02 15:19:43 +00:00
parent 86bc26543a
commit bfab71c24b
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
3 changed files with 23 additions and 11 deletions

View File

@ -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."
}
}
}

View File

@ -14,6 +14,7 @@ with open("embed.go", "w") as f:
f.write("""package main
import (
"embed"
"io/fs"
"log"
)
@ -21,9 +22,20 @@ import (
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() {
langFS = LangFS{lFS}
log.Println("Using internal storage")
}""")
elif EMBED in falses:
@ -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
View File

@ -338,10 +338,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 == "" {
@ -576,7 +576,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)