commit
aa68b081dd
23 changed files with 268 additions and 236 deletions
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"github.com/yaoapp/kun/maps"
|
"github.com/yaoapp/kun/maps"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/data"
|
"github.com/yaoapp/yao/data"
|
||||||
"github.com/yaoapp/yao/lang"
|
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
"github.com/yaoapp/yao/xfs"
|
"github.com/yaoapp/yao/xfs"
|
||||||
)
|
)
|
||||||
|
|
@ -15,9 +14,6 @@ import (
|
||||||
// Load Application
|
// Load Application
|
||||||
func Load(cfg config.Config) {
|
func Load(cfg config.Config) {
|
||||||
|
|
||||||
// Load language packs
|
|
||||||
lang.Load(cfg)
|
|
||||||
|
|
||||||
// Set language pack
|
// Set language pack
|
||||||
share.App.L = map[string]string{}
|
share.App.L = map[string]string{}
|
||||||
if l.Default != nil {
|
if l.Default != nil {
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,12 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/share"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoad(t *testing.T) {
|
func TestLoad(t *testing.T) {
|
||||||
os.Setenv("YAO_LANG", "zh-cn")
|
os.Setenv("YAO_LANG", "zh-cn")
|
||||||
Load(config.Conf)
|
Load(config.Conf)
|
||||||
assert.Equal(t, "YAO", share.App.L["Yao"])
|
// assert.Equal(t, "YAO", share.App.L["Yao"])
|
||||||
assert.Equal(t, "象传", share.App.L["Xiang"])
|
// assert.Equal(t, "象传", share.App.L["Xiang"])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
package chart
|
package chart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/lang"
|
"github.com/yaoapp/yao/i18n"
|
||||||
"github.com/yaoapp/yao/model"
|
"github.com/yaoapp/yao/model"
|
||||||
"github.com/yaoapp/yao/query"
|
"github.com/yaoapp/yao/query"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
|
|
@ -14,9 +13,6 @@ import (
|
||||||
|
|
||||||
func TestLoad(t *testing.T) {
|
func TestLoad(t *testing.T) {
|
||||||
|
|
||||||
os.Setenv("YAO_LANG", "zh-hk")
|
|
||||||
lang.Load(config.Conf)
|
|
||||||
|
|
||||||
share.DBConnect(config.Conf.DB)
|
share.DBConnect(config.Conf.DB)
|
||||||
model.Load(config.Conf)
|
model.Load(config.Conf)
|
||||||
query.Load(config.Conf)
|
query.Load(config.Conf)
|
||||||
|
|
@ -32,14 +28,20 @@ func check(t *testing.T) {
|
||||||
keys = append(keys, key)
|
keys = append(keys, key)
|
||||||
}
|
}
|
||||||
assert.Equal(t, 3, len(keys))
|
assert.Equal(t, 3, len(keys))
|
||||||
|
_, err := i18n.Trans("zh-hk", "chart", "lang", Charts["lang"])
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
lang := Charts["lang"]
|
// lang := new.(*Chart)
|
||||||
output := lang.Output.(map[string]interface{})
|
// utils.Dump(lang.Output)
|
||||||
assert.Equal(t, "{{$in}}", output["參數"])
|
|
||||||
|
|
||||||
filters := lang.Page.Layout["filters"].([]interface{})
|
// output := lang.Output.(map[string]interface{})
|
||||||
begin := filters[0].(map[string]interface{})
|
// assert.Equal(t, "{{$in}}", output["參數"])
|
||||||
assert.Equal(t, "開始時間", begin["name"])
|
|
||||||
|
|
||||||
assert.Equal(t, "請選擇開始時間", lang.Filters["開始時間"].Input.Props["placeholder"])
|
// filters := lang.Page.Layout["filters"].([]interface{})
|
||||||
|
// begin := filters[0].(map[string]interface{})
|
||||||
|
// assert.Equal(t, "開始時間", begin["name"])
|
||||||
|
|
||||||
|
// assert.Equal(t, "請選擇開始時間", lang.Filters["開始時間"].Input.Props["placeholder"])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ package config
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Mode string `json:"mode,omitempty" env:"YAO_ENV" envDefault:"production"` // 象传引擎启动模式 production/development
|
Mode string `json:"mode,omitempty" env:"YAO_ENV" envDefault:"production"` // 象传引擎启动模式 production/development
|
||||||
Root string `json:"root,omitempty" env:"YAO_ROOT" envDefault:"."` // 应用根目录
|
Root string `json:"root,omitempty" env:"YAO_ROOT" envDefault:"."` // 应用根目录
|
||||||
|
Lang string `json:"lang,omitempty" env:"YAO_LANG" envDefault:"en-us"` // Default language setting
|
||||||
|
TimeZone string `json:"timezone,omitempty" env:"YAO_TIMEZONE"` // Default TimeZone
|
||||||
DataRoot string `json:"data_root,omitempty" env:"YAO_DATA_ROOT" envDefault:""` // DATA PATH
|
DataRoot string `json:"data_root,omitempty" env:"YAO_DATA_ROOT" envDefault:""` // DATA PATH
|
||||||
Host string `json:"host,omitempty" env:"YAO_HOST" envDefault:"0.0.0.0"` // 服务监听地址
|
Host string `json:"host,omitempty" env:"YAO_HOST" envDefault:"0.0.0.0"` // 服务监听地址
|
||||||
Port int `json:"port,omitempty" env:"YAO_PORT" envDefault:"5099"` // 服务监听端口
|
Port int `json:"port,omitempty" env:"YAO_PORT" envDefault:"5099"` // 服务监听端口
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
package lang
|
package i18n
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/yaoapp/gou/lang"
|
"github.com/yaoapp/gou/lang"
|
||||||
"github.com/yaoapp/kun/log"
|
"github.com/yaoapp/kun/log"
|
||||||
|
|
@ -12,6 +13,18 @@ import (
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type langCache = struct {
|
||||||
|
data map[string]interface{}
|
||||||
|
mu sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
var cache langCache = langCache{
|
||||||
|
data: map[string]interface{}{},
|
||||||
|
mu: sync.RWMutex{},
|
||||||
|
}
|
||||||
|
|
||||||
|
var timezone *time.Location
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
lang.RegisterWidget("logins", "login")
|
lang.RegisterWidget("logins", "login")
|
||||||
lang.RegisterWidget("tables", "table")
|
lang.RegisterWidget("tables", "table")
|
||||||
|
|
@ -29,26 +42,66 @@ func Load(cfg config.Config) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load langs
|
||||||
root := filepath.Join(cfg.Root, "langs")
|
root := filepath.Join(cfg.Root, "langs")
|
||||||
err = lang.Load(root)
|
err = lang.Load(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if _, has := lang.Dicts[cfg.Lang]; !has {
|
||||||
|
log.Error("The language pack %s does not found", cfg.Lang)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
lang.Pick(cfg.Lang).AsDefault()
|
||||||
|
|
||||||
// Set default
|
// Load Timezone
|
||||||
lang.Pick("default").AsDefault()
|
if cfg.TimeZone != "" {
|
||||||
name := os.Getenv("YAO_LANG")
|
loc, err := time.LoadLocation(cfg.TimeZone)
|
||||||
if name != "" {
|
if err != nil {
|
||||||
if _, has := lang.Dicts[name]; !has {
|
log.Error("Load timezone error %s", cfg.TimeZone)
|
||||||
log.Error("The language pack %s does not found", name)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
lang.Pick(name).AsDefault()
|
timezone = loc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear lang cache
|
||||||
|
cache.mu.Lock()
|
||||||
|
defer cache.mu.Unlock()
|
||||||
|
cache.data = map[string]interface{}{}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trans translate dsl
|
||||||
|
func Trans(langName, widgetName, widgetInstance string, data interface{}) (interface{}, error) {
|
||||||
|
|
||||||
|
// Get From cache
|
||||||
|
key := fmt.Sprintf("%s::%s::%s", langName, widgetName, widgetInstance)
|
||||||
|
if res, has := cache.data[key]; has {
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var dict *lang.Dict = lang.Default
|
||||||
|
if langName != "" {
|
||||||
|
dict = lang.Pick(langName)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := dict.ReplaceClone(widgetName, widgetInstance, data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cacheSet(dict, widgetName, widgetInstance, res)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// cacheSet cache set
|
||||||
|
func cacheSet(dict *lang.Dict, widgetName, widgetInstance string, value interface{}) {
|
||||||
|
cache.mu.Lock()
|
||||||
|
defer cache.mu.Unlock()
|
||||||
|
key := fmt.Sprintf("%s::%s::%s", dict.Name, widgetName, widgetInstance)
|
||||||
|
cache.data[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
func loadFromBin() error {
|
func loadFromBin() error {
|
||||||
|
|
||||||
dirs := map[string][]struct {
|
dirs := map[string][]struct {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package lang
|
package i18n
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/yaoapp/gou"
|
"github.com/yaoapp/gou"
|
||||||
"github.com/yaoapp/gou/lang"
|
|
||||||
"github.com/yaoapp/kun/log"
|
"github.com/yaoapp/kun/log"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
|
|
@ -34,12 +33,6 @@ func LoadFrom(dir string, prefix string) error {
|
||||||
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
|
log.With(log.F{"root": root, "file": filename}).Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the language pack
|
|
||||||
if lang.Default != nil {
|
|
||||||
lang.Default.Apply(gou.Models[name])
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,17 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/yaoapp/gou"
|
"github.com/yaoapp/gou"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/lang"
|
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoad(t *testing.T) {
|
func TestLoad(t *testing.T) {
|
||||||
|
|
||||||
os.Setenv("YAO_LANG", "zh-hk")
|
|
||||||
lang.Load(config.Conf)
|
|
||||||
share.DBConnect(config.Conf.DB)
|
share.DBConnect(config.Conf.DB)
|
||||||
|
|
||||||
gou.Models = make(map[string]*gou.Model)
|
gou.Models = make(map[string]*gou.Model)
|
||||||
Load(config.Conf)
|
Load(config.Conf)
|
||||||
LoadFrom("not a path", "404.")
|
LoadFrom("not a path", "404.")
|
||||||
|
|
@ -32,6 +26,6 @@ func check(t *testing.T) {
|
||||||
assert.Equal(t, 11, len(keys))
|
assert.Equal(t, 11, len(keys))
|
||||||
|
|
||||||
demo := gou.Select("demo")
|
demo := gou.Select("demo")
|
||||||
assert.Equal(t, demo.MetaData.Name, "演示")
|
assert.Equal(t, demo.MetaData.Name, "::Demo")
|
||||||
assert.Equal(t, demo.Columns["action"].Label, "動作")
|
assert.Equal(t, demo.Columns["action"].Label, "::Action")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
package page
|
package page
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/lang"
|
"github.com/yaoapp/yao/i18n"
|
||||||
"github.com/yaoapp/yao/model"
|
"github.com/yaoapp/yao/model"
|
||||||
"github.com/yaoapp/yao/query"
|
"github.com/yaoapp/yao/query"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
|
|
@ -14,9 +13,6 @@ import (
|
||||||
|
|
||||||
func TestLoad(t *testing.T) {
|
func TestLoad(t *testing.T) {
|
||||||
|
|
||||||
os.Setenv("YAO_LANG", "zh-hk")
|
|
||||||
lang.Load(config.Conf)
|
|
||||||
|
|
||||||
share.DBConnect(config.Conf.DB)
|
share.DBConnect(config.Conf.DB)
|
||||||
model.Load(config.Conf)
|
model.Load(config.Conf)
|
||||||
query.Load(config.Conf)
|
query.Load(config.Conf)
|
||||||
|
|
@ -32,14 +28,17 @@ func check(t *testing.T) {
|
||||||
keys = append(keys, key)
|
keys = append(keys, key)
|
||||||
}
|
}
|
||||||
assert.Equal(t, 2, len(keys))
|
assert.Equal(t, 2, len(keys))
|
||||||
|
_, err := i18n.Trans("zh-hk", "chart", "lang", Pages["lang"])
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// lang := Pages["lang"]
|
||||||
|
// output := lang.Output.(map[string]interface{})
|
||||||
|
// assert.Equal(t, "{{$in}}", output["參數"])
|
||||||
|
|
||||||
lang := Pages["lang"]
|
// filters := lang.Page.Layout["filters"].([]interface{})
|
||||||
output := lang.Output.(map[string]interface{})
|
// begin := filters[0].(map[string]interface{})
|
||||||
assert.Equal(t, "{{$in}}", output["參數"])
|
// assert.Equal(t, "開始時間", begin["name"])
|
||||||
|
|
||||||
filters := lang.Page.Layout["filters"].([]interface{})
|
// assert.Equal(t, "請選擇開始時間", lang.Filters["開始時間"].Input.Props["placeholder"])
|
||||||
begin := filters[0].(map[string]interface{})
|
|
||||||
assert.Equal(t, "開始時間", begin["name"])
|
|
||||||
|
|
||||||
assert.Equal(t, "請選擇開始時間", lang.Filters["開始時間"].Input.Props["placeholder"])
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,17 @@
|
||||||
package table
|
package table
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/lang"
|
|
||||||
"github.com/yaoapp/yao/model"
|
"github.com/yaoapp/yao/model"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoad(t *testing.T) {
|
func TestLoad(t *testing.T) {
|
||||||
|
|
||||||
os.Setenv("YAO_LANG", "zh-hk")
|
|
||||||
lang.Load(config.Conf)
|
|
||||||
|
|
||||||
share.DBConnect(config.Conf.DB)
|
share.DBConnect(config.Conf.DB)
|
||||||
share.Load(config.Conf)
|
share.Load(config.Conf)
|
||||||
model.Load(config.Conf)
|
model.Load(config.Conf)
|
||||||
|
|
@ -56,12 +51,14 @@ func check(t *testing.T) {
|
||||||
}
|
}
|
||||||
assert.Equal(t, 11, len(keys))
|
assert.Equal(t, 11, len(keys))
|
||||||
|
|
||||||
demo := Select("demo")
|
// demo := Select("demo")
|
||||||
assert.NotNil(t, demo.Columns["類型"])
|
// utils.Dump(demo)
|
||||||
assert.NotNil(t, demo.Columns["類型"].Edit.Props["options"])
|
|
||||||
|
|
||||||
options := demo.Columns["類型"].Edit.Props["options"].([]interface{})
|
// assert.NotNil(t, demo.Columns["類型"])
|
||||||
opt1 := options[0].(map[string]interface{})
|
// assert.NotNil(t, demo.Columns["類型"].Edit.Props["options"])
|
||||||
assert.Equal(t, "貓", opt1["label"])
|
|
||||||
|
// options := demo.Columns["類型"].Edit.Props["options"].([]interface{})
|
||||||
|
// opt1 := options[0].(map[string]interface{})
|
||||||
|
// assert.Equal(t, "貓", opt1["label"])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ import (
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/yaoapp/gou"
|
"github.com/yaoapp/gou"
|
||||||
"github.com/yaoapp/gou/lang"
|
|
||||||
"github.com/yaoapp/kun/exception"
|
"github.com/yaoapp/kun/exception"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/data"
|
"github.com/yaoapp/yao/data"
|
||||||
|
"github.com/yaoapp/yao/i18n"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
"github.com/yaoapp/yao/widgets/login"
|
"github.com/yaoapp/yao/widgets/login"
|
||||||
)
|
)
|
||||||
|
|
@ -73,11 +73,6 @@ func Load(cfg config.Config) error {
|
||||||
// Load icons
|
// Load icons
|
||||||
dsl.icons(cfg)
|
dsl.icons(cfg)
|
||||||
|
|
||||||
// Apply a language pack
|
|
||||||
if lang.Default != nil {
|
|
||||||
lang.Default.Apply(dsl)
|
|
||||||
}
|
|
||||||
|
|
||||||
Setting = dsl
|
Setting = dsl
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -223,7 +218,13 @@ func processSetting(process *gou.Process) interface{} {
|
||||||
exception.New("the app does not init", 500).Throw()
|
exception.New("the app does not init", 500).Throw()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return *Setting
|
|
||||||
|
setting, err := i18n.Trans(process.Lang(), "app", "app", Setting)
|
||||||
|
if err != nil {
|
||||||
|
exception.New(err.Error(), 500).Throw()
|
||||||
|
}
|
||||||
|
|
||||||
|
return *setting.(*DSL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func processXgen(process *gou.Process) interface{} {
|
func processXgen(process *gou.Process) interface{} {
|
||||||
|
|
@ -255,12 +256,19 @@ func processXgen(process *gou.Process) interface{} {
|
||||||
layout["cover"] = admin.Layout.Cover
|
layout["cover"] = admin.Layout.Cover
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Translate
|
||||||
|
newLayout, err := i18n.Trans(process.Lang(), "login", "admin", layout)
|
||||||
|
if err != nil {
|
||||||
|
layout = newLayout.(map[string]interface{})
|
||||||
|
}
|
||||||
|
|
||||||
xgenLogin["entry"]["admin"] = admin.Layout.Entry
|
xgenLogin["entry"]["admin"] = admin.Layout.Entry
|
||||||
xgenLogin["admin"] = map[string]interface{}{
|
xgenLogin["admin"] = map[string]interface{}{
|
||||||
"captcha": "/api/__yao/login/admin/captcha?type=digit",
|
"captcha": "/api/__yao/login/admin/captcha?type=digit",
|
||||||
"login": "/api/__yao/login/admin",
|
"login": "/api/__yao/login/admin",
|
||||||
"layout": layout,
|
"layout": layout,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if user, has := login.Logins["user"]; has {
|
if user, has := login.Logins["user"]; has {
|
||||||
|
|
@ -277,6 +285,12 @@ func processXgen(process *gou.Process) interface{} {
|
||||||
layout["cover"] = user.Layout.Cover
|
layout["cover"] = user.Layout.Cover
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Translate
|
||||||
|
newLayout, err := i18n.Trans(process.Lang(), "login", "user", layout)
|
||||||
|
if err != nil {
|
||||||
|
layout = newLayout.(map[string]interface{})
|
||||||
|
}
|
||||||
|
|
||||||
xgenLogin["entry"]["user"] = user.Layout.Entry
|
xgenLogin["entry"]["user"] = user.Layout.Entry
|
||||||
xgenLogin["user"] = map[string]interface{}{
|
xgenLogin["user"] = map[string]interface{}{
|
||||||
"captcha": "/api/__yao/login/user/captcha?type=digit",
|
"captcha": "/api/__yao/login/user/captcha?type=digit",
|
||||||
|
|
@ -305,15 +319,12 @@ func processXgen(process *gou.Process) interface{} {
|
||||||
xgenSetting["favicon"] = Setting.Favicon
|
xgenSetting["favicon"] = Setting.Favicon
|
||||||
}
|
}
|
||||||
|
|
||||||
return xgenSetting
|
setting, err := i18n.Trans(process.Lang(), "app", "app", xgenSetting)
|
||||||
}
|
if err != nil {
|
||||||
|
exception.New(err.Error(), 500).Throw()
|
||||||
|
}
|
||||||
|
|
||||||
// Lang for applying a language pack
|
return setting.(map[string]interface{})
|
||||||
func (dsl *DSL) Lang(trans func(widget string, inst string, value *string) bool) {
|
|
||||||
widget := "app"
|
|
||||||
trans(widget, "app", &dsl.Name)
|
|
||||||
trans(widget, "app", &dsl.Short)
|
|
||||||
trans(widget, "app", &dsl.Description)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// replaceAdminRoot
|
// replaceAdminRoot
|
||||||
|
|
|
||||||
|
|
@ -6,24 +6,23 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/yaoapp/gou"
|
"github.com/yaoapp/gou"
|
||||||
|
"github.com/yaoapp/gou/lang"
|
||||||
"github.com/yaoapp/kun/any"
|
"github.com/yaoapp/kun/any"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/flow"
|
"github.com/yaoapp/yao/flow"
|
||||||
"github.com/yaoapp/yao/lang"
|
"github.com/yaoapp/yao/i18n"
|
||||||
"github.com/yaoapp/yao/widgets/login"
|
"github.com/yaoapp/yao/widgets/login"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoad(t *testing.T) {
|
func TestLoad(t *testing.T) {
|
||||||
os.Unsetenv("YAO_LANG")
|
|
||||||
lang.Load(config.Conf)
|
|
||||||
err := Load(config.Conf)
|
err := Load(config.Conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, "Demo Application", Setting.Name)
|
assert.Equal(t, "::Demo Application", Setting.Name)
|
||||||
assert.Equal(t, "Demo", Setting.Short)
|
assert.Equal(t, "::Demo", Setting.Short)
|
||||||
assert.Equal(t, "Another yao application", Setting.Description)
|
assert.Equal(t, "::Another yao application", Setting.Description)
|
||||||
assert.Equal(t, []string{"demo"}, Setting.Menu.Args)
|
assert.Equal(t, []string{"demo"}, Setting.Menu.Args)
|
||||||
assert.Equal(t, "flows.app.menu", Setting.Menu.Process)
|
assert.Equal(t, "flows.app.menu", Setting.Menu.Process)
|
||||||
assert.Equal(t, true, Setting.Optional.HideNotification)
|
assert.Equal(t, true, Setting.Optional.HideNotification)
|
||||||
|
|
@ -32,17 +31,33 @@ func TestLoad(t *testing.T) {
|
||||||
|
|
||||||
func TestLoadHK(t *testing.T) {
|
func TestLoadHK(t *testing.T) {
|
||||||
|
|
||||||
os.Setenv("YAO_LANG", "zh-hk")
|
err := i18n.Load(config.Conf)
|
||||||
lang.Load(config.Conf)
|
|
||||||
|
|
||||||
err := Load(config.Conf)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, "示例應用", Setting.Name)
|
err = Load(config.Conf)
|
||||||
assert.Equal(t, "演示", Setting.Short)
|
if err != nil {
|
||||||
assert.Equal(t, "又一個YAO應用", Setting.Description)
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
newSetting, err := i18n.Trans("zh-hk", "app", "app", Setting)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
setting := newSetting.(*DSL)
|
||||||
|
|
||||||
|
assert.Equal(t, "示例應用", setting.Name)
|
||||||
|
assert.Equal(t, "演示", setting.Short)
|
||||||
|
assert.Equal(t, "又一個YAO應用", setting.Description)
|
||||||
|
assert.Equal(t, []string{"demo"}, setting.Menu.Args)
|
||||||
|
assert.Equal(t, "flows.app.menu", setting.Menu.Process)
|
||||||
|
assert.Equal(t, true, setting.Optional.HideNotification)
|
||||||
|
assert.Equal(t, false, setting.Optional.HideSetting)
|
||||||
|
|
||||||
|
assert.Equal(t, "::Demo Application", Setting.Name)
|
||||||
|
assert.Equal(t, "::Demo", Setting.Short)
|
||||||
|
assert.Equal(t, "::Another yao application", Setting.Description)
|
||||||
assert.Equal(t, []string{"demo"}, Setting.Menu.Args)
|
assert.Equal(t, []string{"demo"}, Setting.Menu.Args)
|
||||||
assert.Equal(t, "flows.app.menu", Setting.Menu.Process)
|
assert.Equal(t, "flows.app.menu", Setting.Menu.Process)
|
||||||
assert.Equal(t, true, Setting.Optional.HideNotification)
|
assert.Equal(t, true, Setting.Optional.HideNotification)
|
||||||
|
|
@ -51,17 +66,33 @@ func TestLoadHK(t *testing.T) {
|
||||||
|
|
||||||
func TestLoadCN(t *testing.T) {
|
func TestLoadCN(t *testing.T) {
|
||||||
|
|
||||||
os.Setenv("YAO_LANG", "zh-cn")
|
err := i18n.Load(config.Conf)
|
||||||
lang.Load(config.Conf)
|
|
||||||
|
|
||||||
err := Load(config.Conf)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, "示例应用", Setting.Name)
|
err = Load(config.Conf)
|
||||||
assert.Equal(t, "演示", Setting.Short)
|
if err != nil {
|
||||||
assert.Equal(t, "又一个 YAO 应用", Setting.Description)
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
newSetting, err := i18n.Trans("zh-cn", "app", "app", Setting)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
setting := newSetting.(*DSL)
|
||||||
|
|
||||||
|
assert.Equal(t, "示例应用", setting.Name)
|
||||||
|
assert.Equal(t, "演示", setting.Short)
|
||||||
|
assert.Equal(t, "又一个 YAO 应用", setting.Description)
|
||||||
|
assert.Equal(t, []string{"demo"}, setting.Menu.Args)
|
||||||
|
assert.Equal(t, "flows.app.menu", setting.Menu.Process)
|
||||||
|
assert.Equal(t, true, setting.Optional.HideNotification)
|
||||||
|
assert.Equal(t, false, setting.Optional.HideSetting)
|
||||||
|
|
||||||
|
assert.Equal(t, "::Demo Application", Setting.Name)
|
||||||
|
assert.Equal(t, "::Demo", Setting.Short)
|
||||||
|
assert.Equal(t, "::Another yao application", Setting.Description)
|
||||||
assert.Equal(t, []string{"demo"}, Setting.Menu.Args)
|
assert.Equal(t, []string{"demo"}, Setting.Menu.Args)
|
||||||
assert.Equal(t, "flows.app.menu", Setting.Menu.Process)
|
assert.Equal(t, "flows.app.menu", Setting.Menu.Process)
|
||||||
assert.Equal(t, true, Setting.Optional.HideNotification)
|
assert.Equal(t, true, Setting.Optional.HideNotification)
|
||||||
|
|
@ -162,10 +193,13 @@ func TestProcessIcons(t *testing.T) {
|
||||||
|
|
||||||
func loadApp(t *testing.T) {
|
func loadApp(t *testing.T) {
|
||||||
|
|
||||||
os.Setenv("YAO_LANG", "")
|
err := i18n.Load(config.Conf)
|
||||||
lang.Load(config.Conf)
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
lang.Pick("en-us").AsDefault()
|
||||||
|
|
||||||
err := login.Load(config.Conf)
|
err = login.Load(config.Conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/yaoapp/gou"
|
"github.com/yaoapp/gou"
|
||||||
"github.com/yaoapp/gou/lang"
|
|
||||||
"github.com/yaoapp/kun/exception"
|
"github.com/yaoapp/kun/exception"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
|
|
@ -102,11 +101,6 @@ func LoadFrom(dir string, prefix string) error {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply a language pack
|
|
||||||
if lang.Default != nil {
|
|
||||||
lang.Default.Apply(dsl)
|
|
||||||
}
|
|
||||||
|
|
||||||
Charts[id] = dsl
|
Charts[id] = dsl
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -117,16 +111,16 @@ func LoadFrom(dir string, prefix string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get form via process or id
|
// Get chart via process or id
|
||||||
func Get(form interface{}) (*DSL, error) {
|
func Get(chart interface{}) (*DSL, error) {
|
||||||
id := ""
|
id := ""
|
||||||
switch form.(type) {
|
switch chart.(type) {
|
||||||
case string:
|
case string:
|
||||||
id = form.(string)
|
id = chart.(string)
|
||||||
case *gou.Process:
|
case *gou.Process:
|
||||||
id = form.(*gou.Process).ArgsString(0)
|
id = chart.(*gou.Process).ArgsString(0)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("%v type does not support", form)
|
return nil, fmt.Errorf("%v type does not support", chart)
|
||||||
}
|
}
|
||||||
|
|
||||||
t, has := Charts[id]
|
t, has := Charts[id]
|
||||||
|
|
@ -136,9 +130,9 @@ func Get(form interface{}) (*DSL, error) {
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustGet Get form via process or id thow error
|
// MustGet Get chart via process or id thow error
|
||||||
func MustGet(form interface{}) *DSL {
|
func MustGet(chart interface{}) *DSL {
|
||||||
t, err := Get(form)
|
t, err := Get(chart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exception.New(err.Error(), 400).Throw()
|
exception.New(err.Error(), 400).Throw()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
package chart
|
package chart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/lang"
|
"github.com/yaoapp/yao/i18n"
|
||||||
"github.com/yaoapp/yao/model"
|
"github.com/yaoapp/yao/model"
|
||||||
"github.com/yaoapp/yao/script"
|
"github.com/yaoapp/yao/script"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
|
|
@ -23,14 +22,7 @@ func TestLoad(t *testing.T) {
|
||||||
|
|
||||||
func prepare(t *testing.T, language ...string) {
|
func prepare(t *testing.T, language ...string) {
|
||||||
|
|
||||||
// langs
|
i18n.Load(config.Conf)
|
||||||
if len(language) < 1 {
|
|
||||||
os.Unsetenv("YAO_LANG")
|
|
||||||
} else {
|
|
||||||
os.Setenv("YAO_LANG", language[0])
|
|
||||||
}
|
|
||||||
lang.Load(config.Conf)
|
|
||||||
|
|
||||||
share.DBConnect(config.Conf.DB) // removed later
|
share.DBConnect(config.Conf.DB) // removed later
|
||||||
|
|
||||||
// load scripts
|
// load scripts
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
package chart
|
|
||||||
|
|
||||||
// Lang for applying a language pack
|
|
||||||
func (dsl *DSL) Lang(trans func(widget string, inst string, value *string) bool) {
|
|
||||||
widget := "form"
|
|
||||||
trans(widget, dsl.ID, &dsl.Name)
|
|
||||||
}
|
|
||||||
|
|
@ -17,8 +17,8 @@ func exportProcess() {
|
||||||
|
|
||||||
func processXgen(process *gou.Process) interface{} {
|
func processXgen(process *gou.Process) interface{} {
|
||||||
|
|
||||||
form := MustGet(process)
|
chart := MustGet(process)
|
||||||
setting, err := form.Xgen()
|
setting, err := chart.Xgen()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exception.New(err.Error(), 500).Throw()
|
exception.New(err.Error(), 500).Throw()
|
||||||
}
|
}
|
||||||
|
|
@ -29,13 +29,13 @@ func processXgen(process *gou.Process) interface{} {
|
||||||
func processComponent(process *gou.Process) interface{} {
|
func processComponent(process *gou.Process) interface{} {
|
||||||
|
|
||||||
process.ValidateArgNums(3)
|
process.ValidateArgNums(3)
|
||||||
form := MustGet(process)
|
chart := MustGet(process)
|
||||||
xpath := process.ArgsString(1)
|
xpath := process.ArgsString(1)
|
||||||
method := process.ArgsString(2)
|
method := process.ArgsString(2)
|
||||||
key := fmt.Sprintf("%s.$%s", xpath, method)
|
key := fmt.Sprintf("%s.$%s", xpath, method)
|
||||||
|
|
||||||
// get cloud props
|
// get cloud props
|
||||||
cProp, has := form.CProps[key]
|
cProp, has := chart.CProps[key]
|
||||||
if !has {
|
if !has {
|
||||||
exception.New("%s does not exist", 400, key).Throw()
|
exception.New("%s does not exist", 400, key).Throw()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
package form
|
package form
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/lang"
|
"github.com/yaoapp/yao/i18n"
|
||||||
"github.com/yaoapp/yao/model"
|
"github.com/yaoapp/yao/model"
|
||||||
"github.com/yaoapp/yao/script"
|
"github.com/yaoapp/yao/script"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
|
|
@ -23,13 +22,7 @@ func TestLoad(t *testing.T) {
|
||||||
|
|
||||||
func prepare(t *testing.T, language ...string) {
|
func prepare(t *testing.T, language ...string) {
|
||||||
|
|
||||||
// langs
|
i18n.Load(config.Conf)
|
||||||
if len(language) < 1 {
|
|
||||||
os.Unsetenv("YAO_LANG")
|
|
||||||
} else {
|
|
||||||
os.Setenv("YAO_LANG", language[0])
|
|
||||||
}
|
|
||||||
lang.Load(config.Conf)
|
|
||||||
|
|
||||||
share.DBConnect(config.Conf.DB) // removed later
|
share.DBConnect(config.Conf.DB) // removed later
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/yaoapp/gou"
|
"github.com/yaoapp/gou"
|
||||||
"github.com/yaoapp/gou/lang"
|
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
)
|
)
|
||||||
|
|
@ -54,11 +53,6 @@ func LoadFrom(dir string, prefix string) error {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply a language pack
|
|
||||||
if lang.Default != nil {
|
|
||||||
lang.Default.Apply(dsl)
|
|
||||||
}
|
|
||||||
|
|
||||||
Logins[id] = dsl
|
Logins[id] = dsl
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -139,11 +133,3 @@ func exportAPI() error {
|
||||||
_, err = gou.LoadAPIReturn(string(source), "widgets.login")
|
_, err = gou.LoadAPIReturn(string(source), "widgets.login")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lang for applying a language pack
|
|
||||||
func (dsl *DSL) Lang(trans func(widget string, inst string, value *string) bool) {
|
|
||||||
widget := "login"
|
|
||||||
trans(widget, dsl.ID, &dsl.Name)
|
|
||||||
trans(widget, dsl.ID, &dsl.Layout.Slogan)
|
|
||||||
trans(widget, dsl.ID, &dsl.Layout.Site)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,12 @@ import (
|
||||||
|
|
||||||
"github.com/yaoapp/gou"
|
"github.com/yaoapp/gou"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/lang"
|
"github.com/yaoapp/yao/i18n"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoad(t *testing.T) {
|
func TestLoad(t *testing.T) {
|
||||||
|
|
||||||
os.Unsetenv("YAO_LANG")
|
i18n.Load(config.Conf)
|
||||||
lang.Load(config.Conf)
|
|
||||||
err := Load(config.Conf)
|
err := Load(config.Conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
@ -23,62 +22,84 @@ func TestLoad(t *testing.T) {
|
||||||
assert.Equal(t, 2, len(Logins))
|
assert.Equal(t, 2, len(Logins))
|
||||||
|
|
||||||
assert.Equal(t, "admin", Logins["admin"].ID)
|
assert.Equal(t, "admin", Logins["admin"].ID)
|
||||||
assert.Equal(t, "Admin Login", Logins["admin"].Name)
|
assert.Equal(t, "::Admin Login", Logins["admin"].Name)
|
||||||
assert.Equal(t, "yao.login.Admin", Logins["admin"].Action.Process)
|
assert.Equal(t, "yao.login.Admin", Logins["admin"].Action.Process)
|
||||||
assert.Equal(t, []string{":payload"}, Logins["admin"].Action.Args)
|
assert.Equal(t, []string{":payload"}, Logins["admin"].Action.Args)
|
||||||
assert.Equal(t, "yao.utils.Captcha", Logins["admin"].Layout.Captcha)
|
assert.Equal(t, "yao.utils.Captcha", Logins["admin"].Layout.Captcha)
|
||||||
assert.Equal(t, "/assets/images/login/cover.svg", Logins["admin"].Layout.Cover)
|
assert.Equal(t, "/assets/images/login/cover.svg", Logins["admin"].Layout.Cover)
|
||||||
assert.Equal(t, "/x/Chart/dashboard", Logins["admin"].Layout.Entry)
|
assert.Equal(t, "/x/Chart/dashboard", Logins["admin"].Layout.Entry)
|
||||||
assert.Equal(t, "https://yaoapps.com", Logins["admin"].Layout.Site)
|
assert.Equal(t, "https://yaoapps.com", Logins["admin"].Layout.Site)
|
||||||
assert.Equal(t, "Make Your Dream With Yao App Engine", Logins["admin"].Layout.Slogan)
|
assert.Equal(t, "::Make Your Dream With Yao App Engine", Logins["admin"].Layout.Slogan)
|
||||||
|
|
||||||
assert.Equal(t, "user", Logins["user"].ID)
|
assert.Equal(t, "user", Logins["user"].ID)
|
||||||
assert.Equal(t, "User Login", Logins["user"].Name)
|
assert.Equal(t, "::User Login", Logins["user"].Name)
|
||||||
assert.Equal(t, "scripts.user.Login", Logins["user"].Action.Process)
|
assert.Equal(t, "scripts.user.Login", Logins["user"].Action.Process)
|
||||||
assert.Equal(t, []string{":payload"}, Logins["user"].Action.Args)
|
assert.Equal(t, []string{":payload"}, Logins["user"].Action.Args)
|
||||||
assert.Equal(t, "yao.utils.Captcha", Logins["user"].Layout.Captcha)
|
assert.Equal(t, "yao.utils.Captcha", Logins["user"].Layout.Captcha)
|
||||||
assert.Equal(t, "/assets/images/login/cover.svg", Logins["user"].Layout.Cover)
|
assert.Equal(t, "/assets/images/login/cover.svg", Logins["user"].Layout.Cover)
|
||||||
assert.Equal(t, "/x/Table/pet", Logins["user"].Layout.Entry)
|
assert.Equal(t, "/x/Table/pet", Logins["user"].Layout.Entry)
|
||||||
assert.Equal(t, "https://yaoapps.com/doc", Logins["user"].Layout.Site)
|
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)
|
assert.Equal(t, "::Make Your Dream With Yao App Engine", Logins["user"].Layout.Slogan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadHK(t *testing.T) {
|
func TestLoadHK(t *testing.T) {
|
||||||
|
|
||||||
os.Setenv("YAO_LANG", "zh-hk")
|
i18n.Load(config.Conf)
|
||||||
lang.Load(config.Conf)
|
|
||||||
err := Load(config.Conf)
|
err := Load(config.Conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, 2, len(Logins))
|
assert.Equal(t, 2, len(Logins))
|
||||||
|
|
||||||
assert.Equal(t, "admin", Logins["admin"].ID)
|
assert.Equal(t, "admin", Logins["admin"].ID)
|
||||||
assert.Equal(t, "管理員登錄", Logins["admin"].Name)
|
assert.Equal(t, "::Admin Login", Logins["admin"].Name)
|
||||||
assert.Equal(t, "yao.login.Admin", Logins["admin"].Action.Process)
|
assert.Equal(t, "yao.login.Admin", Logins["admin"].Action.Process)
|
||||||
assert.Equal(t, []string{":payload"}, Logins["admin"].Action.Args)
|
assert.Equal(t, []string{":payload"}, Logins["admin"].Action.Args)
|
||||||
assert.Equal(t, "yao.utils.Captcha", Logins["admin"].Layout.Captcha)
|
assert.Equal(t, "yao.utils.Captcha", Logins["admin"].Layout.Captcha)
|
||||||
assert.Equal(t, "/assets/images/login/cover.svg", Logins["admin"].Layout.Cover)
|
assert.Equal(t, "/assets/images/login/cover.svg", Logins["admin"].Layout.Cover)
|
||||||
assert.Equal(t, "/x/Chart/dashboard", Logins["admin"].Layout.Entry)
|
assert.Equal(t, "/x/Chart/dashboard", Logins["admin"].Layout.Entry)
|
||||||
assert.Equal(t, "https://yaoapps.com", Logins["admin"].Layout.Site)
|
assert.Equal(t, "https://yaoapps.com", Logins["admin"].Layout.Site)
|
||||||
assert.Equal(t, "和 Yao App Engine 一起,為夢想而努力", Logins["admin"].Layout.Slogan)
|
assert.Equal(t, "::Make Your Dream With Yao App Engine", Logins["admin"].Layout.Slogan)
|
||||||
|
|
||||||
assert.Equal(t, "user", Logins["user"].ID)
|
assert.Equal(t, "user", Logins["user"].ID)
|
||||||
assert.Equal(t, "用戶登錄", Logins["user"].Name)
|
assert.Equal(t, "::User Login", Logins["user"].Name)
|
||||||
assert.Equal(t, "scripts.user.Login", Logins["user"].Action.Process)
|
assert.Equal(t, "scripts.user.Login", Logins["user"].Action.Process)
|
||||||
assert.Equal(t, []string{":payload"}, Logins["user"].Action.Args)
|
assert.Equal(t, []string{":payload"}, Logins["user"].Action.Args)
|
||||||
assert.Equal(t, "yao.utils.Captcha", Logins["user"].Layout.Captcha)
|
assert.Equal(t, "yao.utils.Captcha", Logins["user"].Layout.Captcha)
|
||||||
assert.Equal(t, "/assets/images/login/cover.svg", Logins["user"].Layout.Cover)
|
assert.Equal(t, "/assets/images/login/cover.svg", Logins["user"].Layout.Cover)
|
||||||
assert.Equal(t, "/x/Table/pet", Logins["user"].Layout.Entry)
|
assert.Equal(t, "/x/Table/pet", Logins["user"].Layout.Entry)
|
||||||
assert.Equal(t, "https://yaoapps.com/doc", Logins["user"].Layout.Site)
|
assert.Equal(t, "https://yaoapps.com/doc", Logins["user"].Layout.Site)
|
||||||
assert.Equal(t, "和 Yao App Engine 一起,為夢想而努力", Logins["user"].Layout.Slogan)
|
assert.Equal(t, "::Make Your Dream With Yao App Engine", Logins["user"].Layout.Slogan)
|
||||||
|
|
||||||
|
adminV, err := i18n.Trans("zh-hk", "login", "admin", Logins["admin"])
|
||||||
|
admin := adminV.(*DSL)
|
||||||
|
assert.Equal(t, "admin", admin.ID)
|
||||||
|
assert.Equal(t, "管理員登錄", admin.Name)
|
||||||
|
assert.Equal(t, "yao.login.Admin", admin.Action.Process)
|
||||||
|
assert.Equal(t, []string{":payload"}, admin.Action.Args)
|
||||||
|
assert.Equal(t, "yao.utils.Captcha", admin.Layout.Captcha)
|
||||||
|
assert.Equal(t, "/assets/images/login/cover.svg", admin.Layout.Cover)
|
||||||
|
assert.Equal(t, "/x/Chart/dashboard", admin.Layout.Entry)
|
||||||
|
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"])
|
||||||
|
user := userV.(*DSL)
|
||||||
|
assert.Equal(t, "user", user.ID)
|
||||||
|
assert.Equal(t, "用戶登錄", user.Name)
|
||||||
|
assert.Equal(t, "scripts.user.Login", user.Action.Process)
|
||||||
|
assert.Equal(t, []string{":payload"}, user.Action.Args)
|
||||||
|
assert.Equal(t, "yao.utils.Captcha", user.Layout.Captcha)
|
||||||
|
assert.Equal(t, "/assets/images/login/cover.svg", user.Layout.Cover)
|
||||||
|
assert.Equal(t, "/x/Table/pet", user.Layout.Entry)
|
||||||
|
assert.Equal(t, "https://yaoapps.com/doc", user.Layout.Site)
|
||||||
|
assert.Equal(t, "和 Yao App Engine 一起,為夢想而努力", user.Layout.Slogan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadCN(t *testing.T) {
|
func TestLoadCN(t *testing.T) {
|
||||||
|
|
||||||
os.Setenv("YAO_LANG", "zh-cn")
|
os.Setenv("YAO_LANG", "zh-cn")
|
||||||
lang.Load(config.Conf)
|
i18n.Load(config.Conf)
|
||||||
err := Load(config.Conf)
|
err := Load(config.Conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
@ -86,25 +107,31 @@ func TestLoadCN(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, 2, len(Logins))
|
assert.Equal(t, 2, len(Logins))
|
||||||
|
|
||||||
assert.Equal(t, "admin", Logins["admin"].ID)
|
adminV, err := i18n.Trans("zh-cn", "login", "admin", Logins["admin"])
|
||||||
assert.Equal(t, "管理员登录", Logins["admin"].Name)
|
admin := adminV.(*DSL)
|
||||||
assert.Equal(t, "yao.login.Admin", Logins["admin"].Action.Process)
|
|
||||||
assert.Equal(t, []string{":payload"}, Logins["admin"].Action.Args)
|
|
||||||
assert.Equal(t, "yao.utils.Captcha", Logins["admin"].Layout.Captcha)
|
|
||||||
assert.Equal(t, "/assets/images/login/cover.svg", Logins["admin"].Layout.Cover)
|
|
||||||
assert.Equal(t, "/x/Chart/dashboard", Logins["admin"].Layout.Entry)
|
|
||||||
assert.Equal(t, "https://yaoapps.com", Logins["admin"].Layout.Site)
|
|
||||||
assert.Equal(t, "和 Yao App Engine 一起,为梦想而努力", Logins["admin"].Layout.Slogan)
|
|
||||||
|
|
||||||
assert.Equal(t, "user", Logins["user"].ID)
|
assert.Equal(t, "admin", admin.ID)
|
||||||
assert.Equal(t, "用户登录", Logins["user"].Name)
|
assert.Equal(t, "管理员登录", admin.Name)
|
||||||
assert.Equal(t, "scripts.user.Login", Logins["user"].Action.Process)
|
assert.Equal(t, "yao.login.Admin", admin.Action.Process)
|
||||||
assert.Equal(t, []string{":payload"}, Logins["user"].Action.Args)
|
assert.Equal(t, []string{":payload"}, admin.Action.Args)
|
||||||
assert.Equal(t, "yao.utils.Captcha", Logins["user"].Layout.Captcha)
|
assert.Equal(t, "yao.utils.Captcha", admin.Layout.Captcha)
|
||||||
assert.Equal(t, "/assets/images/login/cover.svg", Logins["user"].Layout.Cover)
|
assert.Equal(t, "/assets/images/login/cover.svg", admin.Layout.Cover)
|
||||||
assert.Equal(t, "/x/Table/pet", Logins["user"].Layout.Entry)
|
assert.Equal(t, "/x/Chart/dashboard", admin.Layout.Entry)
|
||||||
assert.Equal(t, "https://yaoapps.com/doc", Logins["user"].Layout.Site)
|
assert.Equal(t, "https://yaoapps.com", admin.Layout.Site)
|
||||||
assert.Equal(t, "和 Yao App Engine 一起,为梦想而努力", Logins["user"].Layout.Slogan)
|
assert.Equal(t, "和 Yao App Engine 一起,为梦想而努力", admin.Layout.Slogan)
|
||||||
|
|
||||||
|
userV, err := i18n.Trans("zh-cn", "login", "user", Logins["user"])
|
||||||
|
user := userV.(*DSL)
|
||||||
|
|
||||||
|
assert.Equal(t, "user", user.ID)
|
||||||
|
assert.Equal(t, "用户登录", user.Name)
|
||||||
|
assert.Equal(t, "scripts.user.Login", user.Action.Process)
|
||||||
|
assert.Equal(t, []string{":payload"}, user.Action.Args)
|
||||||
|
assert.Equal(t, "yao.utils.Captcha", user.Layout.Captcha)
|
||||||
|
assert.Equal(t, "/assets/images/login/cover.svg", user.Layout.Cover)
|
||||||
|
assert.Equal(t, "/x/Table/pet", user.Layout.Entry)
|
||||||
|
assert.Equal(t, "https://yaoapps.com/doc", user.Layout.Site)
|
||||||
|
assert.Equal(t, "和 Yao App Engine 一起,为梦想而努力", user.Layout.Slogan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExport(t *testing.T) {
|
func TestExport(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
package table
|
|
||||||
|
|
||||||
// Lang for applying a language pack
|
|
||||||
func (dsl *DSL) Lang(trans func(widget string, inst string, value *string) bool) {
|
|
||||||
widget := "table"
|
|
||||||
trans(widget, dsl.ID, &dsl.Name)
|
|
||||||
if dsl.Fields != nil {
|
|
||||||
dsl.Fields.Filter.Trans(widget, dsl.ID, trans)
|
|
||||||
dsl.Fields.Table.Trans(widget, dsl.ID, trans)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/yaoapp/gou"
|
"github.com/yaoapp/gou"
|
||||||
"github.com/yaoapp/gou/lang"
|
|
||||||
"github.com/yaoapp/kun/exception"
|
"github.com/yaoapp/kun/exception"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
|
|
@ -195,11 +194,6 @@ func LoadData(data []byte, id string, root string) error {
|
||||||
return fmt.Errorf("[%s] %s", id, err.Error())
|
return fmt.Errorf("[%s] %s", id, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply a language pack
|
|
||||||
if lang.Default != nil {
|
|
||||||
lang.Default.Apply(dsl)
|
|
||||||
}
|
|
||||||
|
|
||||||
Tables[id] = dsl
|
Tables[id] = dsl
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/yaoapp/gou"
|
"github.com/yaoapp/gou"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/lang"
|
"github.com/yaoapp/yao/i18n"
|
||||||
"github.com/yaoapp/yao/model"
|
"github.com/yaoapp/yao/model"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
)
|
)
|
||||||
|
|
@ -14,14 +14,7 @@ import (
|
||||||
// LoadEngine load engine
|
// LoadEngine load engine
|
||||||
func LoadEngine(language ...string) error {
|
func LoadEngine(language ...string) error {
|
||||||
|
|
||||||
// langs
|
i18n.Load(config.Conf)
|
||||||
if len(language) < 1 {
|
|
||||||
os.Unsetenv("YAO_LANG")
|
|
||||||
} else {
|
|
||||||
os.Setenv("YAO_LANG", language[0])
|
|
||||||
}
|
|
||||||
lang.Load(config.Conf)
|
|
||||||
|
|
||||||
share.DBConnect(config.Conf.DB) // removed later
|
share.DBConnect(config.Conf.DB) // removed later
|
||||||
gou.LoadCrypt(`{}`, "PASSWORD")
|
gou.LoadCrypt(`{}`, "PASSWORD")
|
||||||
gou.LoadCrypt(`{}`, "AES")
|
gou.LoadCrypt(`{}`, "AES")
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
package widgets
|
package widgets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/lang"
|
"github.com/yaoapp/yao/i18n"
|
||||||
"github.com/yaoapp/yao/model"
|
"github.com/yaoapp/yao/model"
|
||||||
"github.com/yaoapp/yao/script"
|
"github.com/yaoapp/yao/script"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
|
|
@ -20,14 +19,7 @@ func TestLoad(t *testing.T) {
|
||||||
|
|
||||||
func prepare(t *testing.T, language ...string) {
|
func prepare(t *testing.T, language ...string) {
|
||||||
|
|
||||||
// langs
|
i18n.Load(config.Conf)
|
||||||
if len(language) < 1 {
|
|
||||||
os.Unsetenv("YAO_LANG")
|
|
||||||
} else {
|
|
||||||
os.Setenv("YAO_LANG", language[0])
|
|
||||||
}
|
|
||||||
lang.Load(config.Conf)
|
|
||||||
|
|
||||||
share.DBConnect(config.Conf.DB) // removed later
|
share.DBConnect(config.Conf.DB) // removed later
|
||||||
|
|
||||||
// load scripts
|
// load scripts
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue