mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 18:35:51 +02:00
enhance: dynamic translation module
This commit is contained in:
parent
c8cd3e6186
commit
7640c1fdc3
4 changed files with 19 additions and 2 deletions
|
@ -4,5 +4,5 @@ import (
|
|||
"embed"
|
||||
)
|
||||
|
||||
//go:embed dist/* dist/*/* src/language/* src/language/*/*
|
||||
//go:embed i18n.json dist/* dist/*/* src/language/* src/language/*/*
|
||||
var DistFS embed.FS
|
||||
|
|
1
go.mod
1
go.mod
|
@ -203,6 +203,7 @@ require (
|
|||
github.com/sacloud/go-http v0.1.8 // indirect
|
||||
github.com/sacloud/iaas-api-go v1.11.2 // indirect
|
||||
github.com/sacloud/packages-go v0.0.10 // indirect
|
||||
github.com/samber/lo v1.39.0 // indirect
|
||||
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.23 // indirect
|
||||
github.com/schollz/closestmatch v2.1.0+incompatible // indirect
|
||||
github.com/shoenig/go-m1cpu v0.1.6 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -1533,6 +1533,8 @@ github.com/sacloud/iaas-api-go v1.11.2/go.mod h1:gjiuIY5c/7lj2LmFnVgyHcPMT17PysX
|
|||
github.com/sacloud/packages-go v0.0.10 h1:UiQGjy8LretewkRhsuna1TBM9Vz/l9FoYpQx+D+AOck=
|
||||
github.com/sacloud/packages-go v0.0.10/go.mod h1:f8QITBh9z4IZc4yE9j21Q8b0sXEMwRlRmhhjWeDVTYs=
|
||||
github.com/sagikazarmark/crypt v0.10.0/go.mod h1:gwTNHQVoOS3xp9Xvz5LLR+1AauC5M6880z5NWzdhOyQ=
|
||||
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
|
||||
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
|
||||
github.com/sanity-io/litter v1.5.5 h1:iE+sBxPBzoK6uaEP5Lt3fHNgpKcHXc/A2HGETy0uJQo=
|
||||
github.com/sanity-io/litter v1.5.5/go.mod h1:9gzJgR2i4ZpjZHsKvUXIRQVk7P+yM3e+jAF7bU2UI5U=
|
||||
github.com/sashabaranov/go-openai v1.19.2 h1:+dkuCADSnwXV02YVJkdphY8XD9AyHLUWwk6V7LB6EL8=
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package translation
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/app"
|
||||
"github.com/0xJacky/pofile/pofile"
|
||||
"github.com/samber/lo"
|
||||
"io"
|
||||
"log"
|
||||
)
|
||||
|
@ -13,7 +15,19 @@ var Dict map[string]pofile.Dict
|
|||
func init() {
|
||||
Dict = make(map[string]pofile.Dict)
|
||||
|
||||
langCode := []string{"zh_CN", "zh_TW", "ru_RU", "fr_FR", "es", "vi_VN"}
|
||||
i18nJson, _ := app.DistFS.Open("i18n.json")
|
||||
|
||||
defer i18nJson.Close()
|
||||
|
||||
bytes, _ := io.ReadAll(i18nJson)
|
||||
|
||||
i18nMap := make(map[string]string)
|
||||
|
||||
_ = json.Unmarshal(bytes, &i18nMap)
|
||||
|
||||
langCode := lo.MapToSlice(i18nMap, func(key string, value string) string {
|
||||
return key
|
||||
})
|
||||
|
||||
for _, v := range langCode {
|
||||
handlePo(v)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue