From aa5964ca09f8d02e1853921785ccb1af5c8f698e Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 19 Oct 2022 05:56:00 +0800 Subject: [PATCH] [remove] form.lang --- widgets/form/action.go | 23 +++++++++++++++++++++++ widgets/form/form.go | 7 +------ widgets/form/lang.go | 7 ------- 3 files changed, 24 insertions(+), 13 deletions(-) delete mode 100644 widgets/form/lang.go diff --git a/widgets/form/action.go b/widgets/form/action.go index 7136a534..a4e57b8c 100644 --- a/widgets/form/action.go +++ b/widgets/form/action.go @@ -7,6 +7,8 @@ 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" ) @@ -196,5 +198,26 @@ func processHandler(p *action.Process, process *gou.Process) (interface{}, error } } + // Tranlate + if p.Name == "yao.form.Setting" { + + widgets := []string{} + if form.Action.Bind.Model != "" { + m := gou.Select(form.Action.Bind.Model) + widgets = append(widgets, fmt.Sprintf("model.%s", m.ID)) + } + + if form.Action.Bind.Table != "" { + widgets = append(widgets, fmt.Sprintf("table.%s", form.Action.Bind.Table)) + } + + widgets = append(widgets, fmt.Sprintf("form.%s", form.ID)) + res, err = i18n.Trans(process.Lang(config.Conf.Lang), widgets, res) + if err != nil { + return nil, fmt.Errorf("[form] Trans.table.%s %s", form.ID, err.Error()) + } + + } + return res, nil } diff --git a/widgets/form/form.go b/widgets/form/form.go index 91b8d71d..e258052e 100644 --- a/widgets/form/form.go +++ b/widgets/form/form.go @@ -7,7 +7,6 @@ import ( jsoniter "github.com/json-iterator/go" "github.com/yaoapp/gou" - "github.com/yaoapp/gou/lang" "github.com/yaoapp/kun/exception" "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/share" @@ -129,11 +128,6 @@ func LoadFrom(dir string, prefix string) error { return } - // Apply a language pack - if lang.Default != nil { - lang.Default.Apply(dsl) - } - Forms[id] = dsl }) @@ -211,5 +205,6 @@ func (dsl *DSL) Xgen() (map[string]interface{}, error) { } } + setting["name"] = dsl.Name return setting, nil } diff --git a/widgets/form/lang.go b/widgets/form/lang.go deleted file mode 100644 index 9b677474..00000000 --- a/widgets/form/lang.go +++ /dev/null @@ -1,7 +0,0 @@ -package form - -// 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) -}