[change] i18n Trans
This commit is contained in:
parent
cd7a776a5e
commit
355ae10dcf
8 changed files with 75 additions and 78 deletions
|
|
@ -28,7 +28,7 @@ func check(t *testing.T) {
|
|||
keys = append(keys, key)
|
||||
}
|
||||
assert.Equal(t, 3, len(keys))
|
||||
_, err := i18n.Trans("zh-hk", "chart", "lang", Charts["lang"])
|
||||
_, err := i18n.Trans("zh-hk", []string{"chart.lang"}, Charts["lang"])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ func uiIndexHtml() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "ui/index.html", size: 11, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "ui/index.html", size: 11, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -236,7 +236,7 @@ func xgenV09IndexHtml() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xgen/v0.9/index.html", size: 14, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "xgen/v0.9/index.html", size: 14, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -256,7 +256,7 @@ func xgenV10IndexHtml() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xgen/v1.0/index.html", size: 50, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "xgen/v1.0/index.html", size: 50, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -276,7 +276,7 @@ func xgenV10Layouts__indexAsyncJs() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xgen/v1.0/layouts__index.async.js", size: 71, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "xgen/v1.0/layouts__index.async.js", size: 71, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -296,7 +296,7 @@ func xgenV10UmiJs() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "xgen/v1.0/umi.js", size: 71, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "xgen/v1.0/umi.js", size: 71, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -316,7 +316,7 @@ func yaoApisReadmeMd() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/apis/README.md", size: 13, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/apis/README.md", size: 13, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -336,7 +336,7 @@ func yaoApisChartHttpJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/apis/chart.http.json", size: 624, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/apis/chart.http.json", size: 624, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -356,7 +356,7 @@ func yaoApisImportHttpJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/apis/import.http.json", size: 1676, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/apis/import.http.json", size: 1676, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -376,7 +376,7 @@ func yaoApisPageHttpJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/apis/page.http.json", size: 609, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/apis/page.http.json", size: 609, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -396,7 +396,7 @@ func yaoApisStorageHttpJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/apis/storage.http.json", size: 1026, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/apis/storage.http.json", size: 1026, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -416,7 +416,7 @@ func yaoApisTableHttpJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/apis/table.http.json", size: 3213, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/apis/table.http.json", size: 3213, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -436,7 +436,7 @@ func yaoApisUserHttpJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/apis/user.http.json", size: 1453, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/apis/user.http.json", size: 1453, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -456,7 +456,7 @@ func yaoApisXiangHttpJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/apis/xiang.http.json", size: 1239, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/apis/xiang.http.json", size: 1239, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -476,7 +476,7 @@ func yaoDataAppJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/data/app.json", size: 277, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/data/app.json", size: 277, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -496,7 +496,7 @@ func yaoDataIcons404Png() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/data/icons/404.png", size: 9342, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/data/icons/404.png", size: 9342, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -516,7 +516,7 @@ func yaoDataIconsIconIcns() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/data/icons/icon.icns", size: 67465, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/data/icons/icon.icns", size: 67465, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -536,7 +536,7 @@ func yaoDataIconsIconIco() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/data/icons/icon.ico", size: 54993, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/data/icons/icon.ico", size: 54993, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -556,7 +556,7 @@ func yaoDataIconsIconPng() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/data/icons/icon.png", size: 34558, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/data/icons/icon.png", size: 34558, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -576,7 +576,7 @@ func yaoDataIndexHtml() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/data/index.html", size: 282, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/data/index.html", size: 282, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -596,7 +596,7 @@ func yaoFieldsModelTransJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/fields/model.trans.json", size: 14602, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/fields/model.trans.json", size: 14602, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -616,7 +616,7 @@ func yaoFlowsReadmeMd() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/flows/README.md", size: 12, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/flows/README.md", size: 12, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -636,7 +636,7 @@ func yaoFlowsAdminGuardFlowJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/flows/admin/guard.flow.json", size: 559, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/flows/admin/guard.flow.json", size: 559, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -656,7 +656,7 @@ func yaoFlowsMenuFlowJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/flows/menu.flow.json", size: 1045, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/flows/menu.flow.json", size: 1045, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -676,7 +676,7 @@ func yaoFlowsUserFindFlowJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/flows/user/find.flow.json", size: 328, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/flows/user/find.flow.json", size: 328, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -696,7 +696,7 @@ func yaoLangsEnUsJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/langs/en-US.json", size: 66, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/langs/en-US.json", size: 66, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -716,7 +716,7 @@ func yaoLangsZhCnGlobalYml() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/langs/zh-cn/global.yml", size: 1424, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/langs/zh-cn/global.yml", size: 1424, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -736,7 +736,7 @@ func yaoLangsZhCnLoginsAdminLoginYml() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/langs/zh-cn/logins/admin.login.yml", size: 94, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/langs/zh-cn/logins/admin.login.yml", size: 94, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -756,7 +756,7 @@ func yaoLangsZhCnLoginsUserLoginYml() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/langs/zh-cn/logins/user.login.yml", size: 90, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/langs/zh-cn/logins/user.login.yml", size: 90, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -776,7 +776,7 @@ func yaoLangsZhHkGlobalYml() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/langs/zh-hk/global.yml", size: 1424, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/langs/zh-hk/global.yml", size: 1424, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -796,7 +796,7 @@ func yaoLangsZhHkLoginsAdminLoginYml() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/langs/zh-hk/logins/admin.login.yml", size: 94, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/langs/zh-hk/logins/admin.login.yml", size: 94, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -816,7 +816,7 @@ func yaoLangsZhHkLoginsUserLoginYml() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/langs/zh-hk/logins/user.login.yml", size: 90, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/langs/zh-hk/logins/user.login.yml", size: 90, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -836,7 +836,7 @@ func yaoModelsReadmeMd() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/models/README.md", size: 15, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/models/README.md", size: 15, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -856,7 +856,7 @@ func yaoModelsMenuModJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/models/menu.mod.json", size: 2378, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/models/menu.mod.json", size: 2378, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -876,7 +876,7 @@ func yaoModelsUserModJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/models/user.mod.json", size: 8826, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/models/user.mod.json", size: 8826, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -896,7 +896,7 @@ func yaoModelsWorkflowModJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/models/workflow.mod.json", size: 3333, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/models/workflow.mod.json", size: 3333, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -916,7 +916,7 @@ func yaoTablesReadmeMd() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/tables/README.md", size: 15, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/tables/README.md", size: 15, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -936,7 +936,7 @@ func yaoTablesMenuTabJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/tables/menu.tab.json", size: 10471, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/tables/menu.tab.json", size: 10471, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
@ -956,7 +956,7 @@ func yaoTablesUserTabJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "yao/tables/user.tab.json", size: 2357, mode: os.FileMode(420), modTime: time.Unix(1666093682, 0)}
|
||||
info := bindataFileInfo{name: "yao/tables/user.tab.json", size: 2357, mode: os.FileMode(420), modTime: time.Unix(1666102858, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
|
|
|||
28
i18n/i18n.go
28
i18n/i18n.go
|
|
@ -3,6 +3,7 @@ package i18n
|
|||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
|
@ -72,10 +73,10 @@ func Load(cfg config.Config) error {
|
|||
}
|
||||
|
||||
// Trans translate dsl
|
||||
func Trans(langName, widgetName, widgetInstance string, data interface{}) (interface{}, error) {
|
||||
func Trans(langName string, widgets []string, data interface{}) (interface{}, error) {
|
||||
|
||||
// Get From cache
|
||||
key := fmt.Sprintf("%s::%s::%s", langName, widgetName, widgetInstance)
|
||||
key := fmt.Sprintf("%s::%s", langName, strings.Join(widgets, "::"))
|
||||
if res, has := cache.data[key]; has {
|
||||
return res, nil
|
||||
}
|
||||
|
|
@ -85,20 +86,20 @@ func Trans(langName, widgetName, widgetInstance string, data interface{}) (inter
|
|||
dict = lang.Pick(langName)
|
||||
}
|
||||
|
||||
res, err := dict.ReplaceClone(widgetName, widgetInstance, data)
|
||||
res, err := dict.ReplaceClone(widgets, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cacheSet(dict, widgetName, widgetInstance, res)
|
||||
cacheSet(dict, widgets, res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// cacheSet cache set
|
||||
func cacheSet(dict *lang.Dict, widgetName, widgetInstance string, value interface{}) {
|
||||
func cacheSet(dict *lang.Dict, widgets []string, value interface{}) {
|
||||
cache.mu.Lock()
|
||||
defer cache.mu.Unlock()
|
||||
key := fmt.Sprintf("%s::%s::%s", dict.Name, widgetName, widgetInstance)
|
||||
key := fmt.Sprintf("%s::%s", dict.Name, strings.Join(widgets, "::"))
|
||||
cache.data[key] = value
|
||||
}
|
||||
|
||||
|
|
@ -107,18 +108,17 @@ func loadFromBin() error {
|
|||
dirs := map[string][]struct {
|
||||
File string
|
||||
Widget string
|
||||
Instance string
|
||||
IsGlobal bool
|
||||
}{
|
||||
"zh-cn": {
|
||||
{File: "yao/langs/zh-cn/global.yml", IsGlobal: true},
|
||||
{File: "yao/langs/zh-cn/logins/admin.login.yml", Widget: "login", Instance: "admin"},
|
||||
{File: "yao/langs/zh-cn/logins/user.login.yml", Widget: "login", Instance: "user"},
|
||||
{File: "yao/langs/zh-cn/logins/admin.login.yml", Widget: "login.admin"},
|
||||
{File: "yao/langs/zh-cn/logins/user.login.yml", Widget: "login.user"},
|
||||
},
|
||||
"zh-hk": {
|
||||
{File: "yao/langs/zh-hk/global.yml", IsGlobal: true},
|
||||
{File: "yao/langs/zh-hk/logins/admin.login.yml", Widget: "login", Instance: "admin"},
|
||||
{File: "yao/langs/zh-hk/logins/user.login.yml", Widget: "login", Instance: "user"},
|
||||
{File: "yao/langs/zh-hk/logins/admin.login.yml", Widget: "login.admin"},
|
||||
{File: "yao/langs/zh-hk/logins/user.login.yml", Widget: "login.user"},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +127,7 @@ func loadFromBin() error {
|
|||
dict := &lang.Dict{
|
||||
Name: langName,
|
||||
Global: lang.Words{},
|
||||
Widgets: map[string]lang.Widget{},
|
||||
Widgets: map[string]lang.Words{},
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
|
|
@ -148,9 +148,9 @@ func loadFromBin() error {
|
|||
}
|
||||
|
||||
if _, has := dict.Widgets[f.Widget]; !has {
|
||||
dict.Widgets[f.Widget] = map[string]lang.Words{}
|
||||
dict.Widgets[f.Widget] = lang.Words{}
|
||||
}
|
||||
dict.Widgets[f.Widget][f.Instance] = words
|
||||
dict.Widgets[f.Widget] = words
|
||||
}
|
||||
|
||||
if _, has := lang.Dicts[langName]; has {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ func check(t *testing.T) {
|
|||
keys = append(keys, key)
|
||||
}
|
||||
assert.Equal(t, 2, len(keys))
|
||||
_, err := i18n.Trans("zh-hk", "chart", "lang", Pages["lang"])
|
||||
_, err := i18n.Trans("zh-hk", []string{"chart.lang"}, Pages["lang"])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ func processSetup(process *gou.Process) interface{} {
|
|||
root = Setting.Optional.AdminRoot
|
||||
}
|
||||
|
||||
setting, err := i18n.Trans(lang, "app", "app", Setting)
|
||||
setting, err := i18n.Trans(lang, []string{"app.app"}, Setting)
|
||||
if err != nil {
|
||||
exception.New(err.Error(), 500).Throw()
|
||||
}
|
||||
|
|
@ -383,7 +383,7 @@ func processSetting(process *gou.Process) interface{} {
|
|||
session.Global().ID(sid).Set("__yao_lang", lang)
|
||||
}
|
||||
|
||||
setting, err := i18n.Trans(process.Lang(), "app", "app", Setting)
|
||||
setting, err := i18n.Trans(process.Lang(config.Conf.Lang), []string{"app.app"}, Setting)
|
||||
if err != nil {
|
||||
exception.New(err.Error(), 500).Throw()
|
||||
}
|
||||
|
|
@ -443,7 +443,7 @@ func processXgen(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// Translate
|
||||
newLayout, err := i18n.Trans(process.Lang(), "login", "admin", layout)
|
||||
newLayout, err := i18n.Trans(process.Lang(config.Conf.Lang), []string{"login.admin"}, layout)
|
||||
if err != nil {
|
||||
layout = newLayout.(map[string]interface{})
|
||||
}
|
||||
|
|
@ -472,7 +472,7 @@ func processXgen(process *gou.Process) interface{} {
|
|||
}
|
||||
|
||||
// Translate
|
||||
newLayout, err := i18n.Trans(process.Lang(), "login", "user", layout)
|
||||
newLayout, err := i18n.Trans(process.Lang(config.Conf.Lang), []string{"login.user"}, layout)
|
||||
if err != nil {
|
||||
layout = newLayout.(map[string]interface{})
|
||||
}
|
||||
|
|
@ -506,7 +506,7 @@ func processXgen(process *gou.Process) interface{} {
|
|||
xgenSetting["favicon"] = Setting.Favicon
|
||||
}
|
||||
|
||||
setting, err := i18n.Trans(process.Lang(), "app", "app", xgenSetting)
|
||||
setting, err := i18n.Trans(process.Lang(config.Conf.Lang), []string{"app.app"}, xgenSetting)
|
||||
if err != nil {
|
||||
exception.New(err.Error(), 500).Throw()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ func TestLoadHK(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
newSetting, err := i18n.Trans("zh-hk", "app", "app", Setting)
|
||||
newSetting, err := i18n.Trans("zh-hk", []string{"app.app"}, Setting)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -77,7 +77,7 @@ func TestLoadCN(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
newSetting, err := i18n.Trans("zh-cn", "app", "app", Setting)
|
||||
newSetting, err := i18n.Trans("zh-cn", []string{"app.app"}, Setting)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ func TestLoadHK(t *testing.T) {
|
|||
assert.Equal(t, "https://yaoapps.com/doc", Logins["user"].Layout.Site)
|
||||
assert.Equal(t, "::Make Your Dream With Yao App Engine", Logins["user"].Layout.Slogan)
|
||||
|
||||
adminV, err := i18n.Trans("zh-hk", "login", "admin", Logins["admin"])
|
||||
adminV, err := i18n.Trans("zh-hk", []string{"login.admin"}, Logins["admin"])
|
||||
admin := adminV.(*DSL)
|
||||
assert.Equal(t, "admin", admin.ID)
|
||||
assert.Equal(t, "管理員登錄", admin.Name)
|
||||
|
|
@ -83,7 +83,7 @@ func TestLoadHK(t *testing.T) {
|
|||
assert.Equal(t, "https://yaoapps.com", admin.Layout.Site)
|
||||
assert.Equal(t, "和 Yao App Engine 一起,為夢想而努力", admin.Layout.Slogan)
|
||||
|
||||
userV, err := i18n.Trans("zh-hk", "login", "user", Logins["user"])
|
||||
userV, err := i18n.Trans("zh-hk", []string{"login.user"}, Logins["user"])
|
||||
user := userV.(*DSL)
|
||||
assert.Equal(t, "user", user.ID)
|
||||
assert.Equal(t, "用戶登錄", user.Name)
|
||||
|
|
@ -107,7 +107,7 @@ func TestLoadCN(t *testing.T) {
|
|||
|
||||
assert.Equal(t, 2, len(Logins))
|
||||
|
||||
adminV, err := i18n.Trans("zh-cn", "login", "admin", Logins["admin"])
|
||||
adminV, err := i18n.Trans("zh-cn", []string{"login.admin"}, Logins["admin"])
|
||||
admin := adminV.(*DSL)
|
||||
|
||||
assert.Equal(t, "admin", admin.ID)
|
||||
|
|
@ -120,7 +120,7 @@ func TestLoadCN(t *testing.T) {
|
|||
assert.Equal(t, "https://yaoapps.com", admin.Layout.Site)
|
||||
assert.Equal(t, "和 Yao App Engine 一起,为梦想而努力", admin.Layout.Slogan)
|
||||
|
||||
userV, err := i18n.Trans("zh-cn", "login", "user", Logins["user"])
|
||||
userV, err := i18n.Trans("zh-cn", []string{"login.user"}, Logins["user"])
|
||||
user := userV.(*DSL)
|
||||
|
||||
assert.Equal(t, "user", user.ID)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/yaoapp/kun/any"
|
||||
"github.com/yaoapp/kun/log"
|
||||
"github.com/yaoapp/kun/maps"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/i18n"
|
||||
"github.com/yaoapp/yao/widgets/action"
|
||||
"github.com/yaoapp/yao/widgets/hook"
|
||||
|
|
@ -367,24 +368,20 @@ func processHandler(p *action.Process, process *gou.Process) (interface{}, error
|
|||
// Tranlate
|
||||
if p.Name == "yao.table.Setting" {
|
||||
|
||||
res, err = i18n.Trans(process.Lang(), "table", tab.ID, res)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("[table] Trans.table.%s %s", tab.ID, err.Error())
|
||||
widgets := []string{}
|
||||
if tab.Action.Bind.Model != "" {
|
||||
m := gou.Select(tab.Action.Bind.Model)
|
||||
widgets = append(widgets, fmt.Sprintf("model.%s", m.ID))
|
||||
}
|
||||
|
||||
if tab.Action.Bind.Table != "" {
|
||||
res, err = i18n.Trans(process.Lang(), "table", tab.Action.Bind.Table, res)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("[table] Trans.bind.table.%s %s", tab.ID, err.Error())
|
||||
}
|
||||
widgets = append(widgets, fmt.Sprintf("table.%s", tab.Action.Bind.Table))
|
||||
}
|
||||
|
||||
if tab.Action.Bind.Model != "" {
|
||||
m := gou.Select(tab.Action.Bind.Model)
|
||||
res, err = i18n.Trans(process.Lang(), "model", m.ID, res)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("[table] Trans.model.%s %s", m.ID, err.Error())
|
||||
}
|
||||
widgets = append(widgets, fmt.Sprintf("table.%s", tab.ID))
|
||||
res, err = i18n.Trans(process.Lang(config.Conf.Lang), widgets, res)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("[table] Trans.table.%s %s", tab.ID, err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue