From af883a4b3f06df750a161bba84d1dc923ffb807f Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 15 Feb 2023 22:30:01 +0100 Subject: [PATCH] chore: remove template languague (#6245) --- cmd/configure/flow.go | 2 +- cmd/configure/helper.go | 5 ++--- cmd/configure/survey.go | 2 +- util/templates/generate/generate.go | 3 ++- util/templates/template.go | 18 +++++++----------- util/templates/template_documentation.go | 2 +- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/cmd/configure/flow.go b/cmd/configure/flow.go index 7e4b979fb..2877245f1 100644 --- a/cmd/configure/flow.go +++ b/cmd/configure/flow.go @@ -114,7 +114,7 @@ func (c *CmdConfigure) configureLinkedTypes(templateItem templates.Template) { break } - linkedTemplateItem.SetCombinedTitle() + linkedTemplateItem.SetCombinedTitle(c.lang) category := DeviceCategory(linkedTemplate.Usage) localizeMap := localizeMap{ diff --git a/cmd/configure/helper.go b/cmd/configure/helper.go index bb782956f..ac41d91d9 100644 --- a/cmd/configure/helper.go +++ b/cmd/configure/helper.go @@ -328,10 +328,9 @@ func (c *CmdConfigure) fetchElements(deviceCategory DeviceCategory) []templates. titleTmpl := templates.Template{ TemplateDefinition: tmpl.TemplateDefinition, ConfigDefaults: tmpl.ConfigDefaults, - Lang: c.lang, } title := t - groupTitle := titleTmpl.GroupTitle() + groupTitle := titleTmpl.GroupTitle(c.lang) if groupTitle != "" { title += " [" + groupTitle + "]" } @@ -359,7 +358,7 @@ func (c *CmdConfigure) fetchElements(deviceCategory DeviceCategory) []templates. return true } if items[i].Group != items[j].Group { - return strings.ToLower(items[i].GroupTitle()) < strings.ToLower(items[j].GroupTitle()) + return strings.ToLower(items[i].GroupTitle(c.lang)) < strings.ToLower(items[j].GroupTitle(c.lang)) } return strings.ToLower(items[i].Title()) < strings.ToLower(items[j].Title()) }) diff --git a/cmd/configure/survey.go b/cmd/configure/survey.go index f297c71d4..131fe95b9 100644 --- a/cmd/configure/survey.go +++ b/cmd/configure/survey.go @@ -54,7 +54,7 @@ func (c *CmdConfigure) askSelection(message string, items []string) (string, int // selectItem selects item from list func (c *CmdConfigure) selectItem(deviceCategory DeviceCategory) templates.Template { - emptyItem := templates.Template{Lang: c.lang} + var emptyItem templates.Template emptyItem.SetTitle(c.localizedString("ItemNotPresent", nil)) elements := c.fetchElements(deviceCategory) diff --git a/util/templates/generate/generate.go b/util/templates/generate/generate.go index f6936b45b..93757f3db 100644 --- a/util/templates/generate/generate.go +++ b/util/templates/generate/generate.go @@ -13,6 +13,7 @@ import ( ) const ( + language = "de" docsPath = "../../../templates/docs" websitePath = "../../../templates/evcc.io" ) @@ -49,7 +50,7 @@ func generateClass(class templates.Class) error { } for index, product := range tmpl.Products { - fmt.Println(tmpl.Template + ": " + product.Title(tmpl.Lang)) + fmt.Println(tmpl.Template + ": " + product.Title(language)) if err := writeTemplate(class, index, product, tmpl); err != nil { return err diff --git a/util/templates/template.go b/util/templates/template.go index cae4f05c1..15d11ba17 100644 --- a/util/templates/template.go +++ b/util/templates/template.go @@ -18,8 +18,6 @@ type Template struct { ConfigDefaults ConfigDefaults `json:"-"` - Lang string - title string titles []string } @@ -84,9 +82,9 @@ func (t *Template) Validate() error { } // set the language title by combining all product titles -func (t *Template) SetCombinedTitle() { +func (t *Template) SetCombinedTitle(lang string) { if len(t.titles) == 0 { - t.resolveTitles() + t.resolveTitles(lang) } t.title = strings.Join(t.titles, "/") @@ -104,19 +102,17 @@ func (t *Template) Title() string { // return the language specific product titles func (t *Template) Titles(lang string) []string { - t.Lang = lang - if len(t.titles) == 0 { - t.resolveTitles() + t.resolveTitles(lang) } return t.titles } // set the language specific product titles -func (t *Template) resolveTitles() { +func (t *Template) resolveTitles(lang string) { for _, p := range t.Products { - t.titles = append(t.titles, p.Title(t.Lang)) + t.titles = append(t.titles, p.Title(lang)) } } @@ -163,9 +159,9 @@ func (t *Template) ResolveGroup() error { } // return the language specific group title -func (t *Template) GroupTitle() string { +func (t *Template) GroupTitle(lang string) string { tl := t.ConfigDefaults.DeviceGroups[t.Group] - return tl.String(t.Lang) + return tl.String(lang) } // Defaults returns a map of default values for the template diff --git a/util/templates/template_documentation.go b/util/templates/template_documentation.go index 5996dd0ae..4ac37698b 100644 --- a/util/templates/template_documentation.go +++ b/util/templates/template_documentation.go @@ -85,7 +85,7 @@ func (t *Template) RenderDocumentation(product Product, values map[string]interf "Template": t.Template, "ProductBrand": product.Brand, "ProductDescription": product.Description.String(lang), - "ProductGroup": t.GroupTitle(), + "ProductGroup": t.GroupTitle(lang), "Capabilities": t.Capabilities, "Requirements": t.Requirements.EVCC, "RequirementDescription": t.Requirements.Description.String(lang),