Skip to content

Commit

Permalink
perf(app/init): generate translated config file by env variable `ATK_…
Browse files Browse the repository at this point in the history
…LOCALE`
  • Loading branch information
qwqcode committed Jun 9, 2024
1 parent b8da04e commit 2549052
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions docs/docs/guide/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ docker run -d \
--name artalk \
-p 8080:23366 \
-v $(pwd)/data:/data \
-e ATK_TRUSTED_DOMAINS="https://your_domain" \
-e ATK_LOCALE="zh-CN" \
-e ATK_SITE_DEFAULT="Artalk 的博客" \
-e ATK_TRUSTED_DOMAINS="https://your_domain" \
artalk/artalk-go
```

Expand Down Expand Up @@ -87,8 +88,9 @@ services:
- ./data:/data
environment:
- TZ=Asia/Shanghai
- ATK_TRUSTED_DOMAINS="https://your_domain"
- ATK_LOCALE="zh-CN"
- ATK_SITE_DEFAULT="Artalk 的博客"
- ATK_TRUSTED_DOMAINS="https://your_domain"
```

创建容器:
Expand Down
1 change: 1 addition & 0 deletions docs/docs/guide/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:
volumes:
- ./data:/data
environment:
- ATK_LOCALE="zh-CN"
- ATK_TRUSTED_DOMAINS="https://your_domain https://your_domain2"
- ATK_ADMIN_USERS_0_NAME=admin
- [email protected]
Expand Down
6 changes: 4 additions & 2 deletions internal/core/gen.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package core

import (
"cmp"
"fmt"
"io"
"os"
Expand All @@ -15,6 +16,8 @@ import (
)

func Gen(genType string, specificPath string, overwrite bool) {
locale := cmp.Or(os.Getenv("ATK_LOCALE"), "en")

// check if generate config file
isGenConf := false
if genType == "config" || genType == "conf" || genType == "artalk.yml" {
Expand All @@ -25,8 +28,7 @@ func Gen(genType string, specificPath string, overwrite bool) {
// get generation content
var fileStr string
if isGenConf {
// TODO detect the user env language
fileStr = config.Template("en")
fileStr = config.Template(locale)
// gen random `app_key`
appKey := utils.RandomStringWithAlphabet(16, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*1234567890")
fileStr = strings.Replace(fileStr, `app_key: ""`, fmt.Sprintf(`app_key: "%s"`, appKey), 1)
Expand Down

0 comments on commit 2549052

Please sign in to comment.