Skip to content

Commit fbcf082

Browse files
committed
feat: auto generate settings lang
1 parent cc9ccc4 commit fbcf082

4 files changed

Lines changed: 41 additions & 6 deletions

File tree

.github/workflows/auto_lang.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
cd ..
4040
- name: Copy lang file
4141
run: |
42-
cp -f ./alist/drivers.json ./alist-web/src/lang/en/
42+
cp -f ./alist/lang/*.json ./alist-web/src/lang/en/
4343
4444
- name: Commit git
4545
run: |

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ public/*.html
2828
public/assets/
2929
public/public/
3030
/data
31-
log/
31+
log/
32+
lang/

cmd/lang.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ package cmd
66

77
import (
88
"fmt"
9+
"github.com/alist-org/alist/v3/internal/bootstrap/data"
10+
log "github.com/sirupsen/logrus"
11+
"os"
912
"strings"
1013

1114
_ "github.com/alist-org/alist/v3/drivers"
@@ -56,15 +59,40 @@ func generateDriversJson() {
5659
}
5760
drivers[k] = items
5861
}
59-
utils.WriteJsonToFile("drivers.json", drivers)
62+
utils.WriteJsonToFile("lang/drivers.json", drivers)
63+
}
64+
65+
func generateSettingsJson() {
66+
settings := data.InitialSettings()
67+
settingsLang := make(KV[any])
68+
for _, setting := range settings {
69+
settingsLang[setting.Key] = convert(setting.Key)
70+
if setting.Help != "" {
71+
settingsLang[fmt.Sprintf("%s-tips", setting.Key)] = setting.Help
72+
}
73+
if setting.Type == conf.TypeSelect && len(setting.Options) > 0 {
74+
options := make(KV[string])
75+
_options := strings.Split(setting.Options, ",")
76+
for _, o := range _options {
77+
options[o] = convert(o)
78+
}
79+
settingsLang[fmt.Sprintf("%ss", setting.Key)] = options
80+
}
81+
}
82+
utils.WriteJsonToFile("lang/settings.json", settingsLang)
6083
}
6184

6285
// langCmd represents the lang command
6386
var langCmd = &cobra.Command{
6487
Use: "lang",
6588
Short: "Generate language json file",
6689
Run: func(cmd *cobra.Command, args []string) {
90+
err := os.MkdirAll("lang", 0777)
91+
if err != nil {
92+
log.Fatal("failed create folder: %s", err.Error())
93+
}
6794
generateDriversJson()
95+
generateSettingsJson()
6896
},
6997
}
7098

internal/bootstrap/data/setting.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
var initialSettingItems []model.SettingItem
1515

1616
func initSettings() {
17-
initialSettings()
17+
InitialSettings()
1818
// check deprecated
1919
settings, err := db.GetSettingItems()
2020
if err != nil {
@@ -58,7 +58,7 @@ func isActive(key string) bool {
5858
return false
5959
}
6060

61-
func initialSettings() {
61+
func InitialSettings() []model.SettingItem {
6262
var token string
6363
if flags.Dev {
6464
token = "dev_token"
@@ -105,6 +105,7 @@ func initialSettings() {
105105
{Key: conf.VideoAutoplay, Value: "true", Type: conf.TypeBool, Group: model.PREVIEW},
106106
// global settings
107107
{Key: conf.HideFiles, Value: "/\\/README.md/i", Type: conf.TypeText, Group: model.GLOBAL},
108+
{Key: "package_download", Value: "true", Type: conf.TypeBool, Group: model.GLOBAL},
108109
{Key: conf.GlobalReadme, Value: "This is global readme", Type: conf.TypeText, Group: model.GLOBAL},
109110
{Key: conf.CustomizeHead, Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE},
110111
{Key: conf.CustomizeBody, Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE},
@@ -119,6 +120,11 @@ func initialSettings() {
119120
{Key: conf.Token, Value: token, Type: conf.TypeString, Group: model.SINGLE, Flag: model.PRIVATE},
120121
}
121122
if flags.Dev {
122-
initialSettingItems = append(initialSettingItems, model.SettingItem{Key: "test_deprecated", Value: "test_value", Type: conf.TypeString, Flag: model.DEPRECATED})
123+
initialSettingItems = append(initialSettingItems, []model.SettingItem{
124+
{Key: "test_deprecated", Value: "test_value", Type: conf.TypeString, Flag: model.DEPRECATED},
125+
{Key: "test_options", Value: "a", Type: conf.TypeSelect, Options: "a,b,c"},
126+
{Key: "test_help", Type: conf.TypeString, Help: "this is a help message"},
127+
}...)
123128
}
129+
return initialSettingItems
124130
}

0 commit comments

Comments
 (0)