diff --git a/.github/workflows/auto_lang.yml b/.github/workflows/auto_lang.yml index 10685f9af87..f9772435f37 100644 --- a/.github/workflows/auto_lang.yml +++ b/.github/workflows/auto_lang.yml @@ -39,7 +39,7 @@ jobs: cd .. - name: Copy lang file run: | - cp -f ./alist/drivers.json ./alist-web/src/lang/en/ + cp -f ./alist/lang/*.json ./alist-web/src/lang/en/ - name: Commit git run: | diff --git a/.gitignore b/.gitignore index f73edf4fd49..3ae8845ca1f 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ public/*.html public/assets/ public/public/ /data -log/ \ No newline at end of file +log/ +lang/ \ No newline at end of file diff --git a/cmd/lang.go b/cmd/lang.go index 19e5cd20bd8..25028023ac6 100644 --- a/cmd/lang.go +++ b/cmd/lang.go @@ -6,6 +6,9 @@ package cmd import ( "fmt" + "github.com/alist-org/alist/v3/internal/bootstrap/data" + log "github.com/sirupsen/logrus" + "os" "strings" _ "github.com/alist-org/alist/v3/drivers" @@ -56,7 +59,27 @@ func generateDriversJson() { } drivers[k] = items } - utils.WriteJsonToFile("drivers.json", drivers) + utils.WriteJsonToFile("lang/drivers.json", drivers) +} + +func generateSettingsJson() { + settings := data.InitialSettings() + settingsLang := make(KV[any]) + for _, setting := range settings { + settingsLang[setting.Key] = convert(setting.Key) + if setting.Help != "" { + settingsLang[fmt.Sprintf("%s-tips", setting.Key)] = setting.Help + } + if setting.Type == conf.TypeSelect && len(setting.Options) > 0 { + options := make(KV[string]) + _options := strings.Split(setting.Options, ",") + for _, o := range _options { + options[o] = convert(o) + } + settingsLang[fmt.Sprintf("%ss", setting.Key)] = options + } + } + utils.WriteJsonToFile("lang/settings.json", settingsLang) } // langCmd represents the lang command @@ -64,7 +87,12 @@ var langCmd = &cobra.Command{ Use: "lang", Short: "Generate language json file", Run: func(cmd *cobra.Command, args []string) { + err := os.MkdirAll("lang", 0777) + if err != nil { + log.Fatal("failed create folder: %s", err.Error()) + } generateDriversJson() + generateSettingsJson() }, } diff --git a/internal/bootstrap/data/setting.go b/internal/bootstrap/data/setting.go index 9982dc50feb..a020b3100dc 100644 --- a/internal/bootstrap/data/setting.go +++ b/internal/bootstrap/data/setting.go @@ -14,7 +14,7 @@ import ( var initialSettingItems []model.SettingItem func initSettings() { - initialSettings() + InitialSettings() // check deprecated settings, err := db.GetSettingItems() if err != nil { @@ -58,7 +58,7 @@ func isActive(key string) bool { return false } -func initialSettings() { +func InitialSettings() []model.SettingItem { var token string if flags.Dev { token = "dev_token" @@ -105,6 +105,7 @@ func initialSettings() { {Key: conf.VideoAutoplay, Value: "true", Type: conf.TypeBool, Group: model.PREVIEW}, // global settings {Key: conf.HideFiles, Value: "/\\/README.md/i", Type: conf.TypeText, Group: model.GLOBAL}, + {Key: "package_download", Value: "true", Type: conf.TypeBool, Group: model.GLOBAL}, {Key: conf.GlobalReadme, Value: "This is global readme", Type: conf.TypeText, Group: model.GLOBAL}, {Key: conf.CustomizeHead, Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE}, {Key: conf.CustomizeBody, Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE}, @@ -119,6 +120,11 @@ func initialSettings() { {Key: conf.Token, Value: token, Type: conf.TypeString, Group: model.SINGLE, Flag: model.PRIVATE}, } if flags.Dev { - initialSettingItems = append(initialSettingItems, model.SettingItem{Key: "test_deprecated", Value: "test_value", Type: conf.TypeString, Flag: model.DEPRECATED}) + initialSettingItems = append(initialSettingItems, []model.SettingItem{ + {Key: "test_deprecated", Value: "test_value", Type: conf.TypeString, Flag: model.DEPRECATED}, + {Key: "test_options", Value: "a", Type: conf.TypeSelect, Options: "a,b,c"}, + {Key: "test_help", Type: conf.TypeString, Help: "this is a help message"}, + }...) } + return initialSettingItems }