From 8a8cf42e935696fa79f0028cbaf96d3392d14c6e Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Wed, 2 Feb 2022 09:18:13 +0100 Subject: [PATCH] Add support for body translations for content block --- compose/service/locale.go | 11 ++++++++++- compose/types/locale.gen.go | 9 +++++++-- compose/types/page.go | 25 +++++++++++++++++++++---- def/compose.page.yaml | 3 ++- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/compose/service/locale.go b/compose/service/locale.go index d95d2e64e..d3b5d324d 100644 --- a/compose/service/locale.go +++ b/compose/service/locale.go @@ -179,6 +179,15 @@ func (svc resourceTranslationsManager) pageExtended(ctx context.Context, res *ty } out = append(out, aux...) + case "Content": + k = types.LocaleKeyPageBlockContentBody + out = append(out, &locale.ResourceTranslation{ + Resource: res.ResourceTranslation(), + Lang: tag.String(), + Key: rpl.Replace(k.Path), + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), rpl.Replace(k.Path)), + }) + } } } @@ -188,7 +197,7 @@ func (svc resourceTranslationsManager) pageExtended(ctx context.Context, res *ty func (svc resourceTranslationsManager) pageExtendedAutomationBlock(tag language.Tag, res *types.Page, block types.PageBlock, blockID uint64) (locale.ResourceTranslationSet, error) { var ( - k = types.LocaleKeyPagePageBlockBlockIDButtonButtonIDLabel + k = types.LocaleKeyPageBlockAutomationButtonLabel out = make(locale.ResourceTranslationSet, 0, 10) bb, _ = block.Options["buttons"].([]interface{}) ) diff --git a/compose/types/locale.gen.go b/compose/types/locale.gen.go index 3d33fceb1..4a0549045 100644 --- a/compose/types/locale.gen.go +++ b/compose/types/locale.gen.go @@ -118,11 +118,16 @@ var ( Resource: PageResourceTranslationType, Path: "pageBlock.{{blockID}}.description", } - LocaleKeyPageBlockAutomationButtonlabel = LocaleKey{ - Name: "blockAutomationButtonlabel", + LocaleKeyPageBlockAutomationButtonLabel = LocaleKey{ + Name: "blockAutomationButtonLabel", Resource: PageResourceTranslationType, Path: "pageBlock.{{blockID}}.button.{{buttonID}}.label", } + LocaleKeyPageBlockContentBody = LocaleKey{ + Name: "blockContentBody", + Resource: PageResourceTranslationType, + Path: "pageBlock.{{blockID}}.content.body", + } ) // ResourceTranslation returns string representation of Locale resource for ModuleField by calling ModuleFieldResourceTranslation fn diff --git a/compose/types/page.go b/compose/types/page.go index f4c1a9705..95ab4793a 100644 --- a/compose/types/page.go +++ b/compose/types/page.go @@ -123,7 +123,8 @@ func (p *Page) decodeTranslations(tt locale.ResourceTranslationIndex) { } // - automation page block stuff - if block.Kind == "Automation" { + switch block.Kind { + case "Automation": bb, _ := block.Options["buttons"].([]interface{}) for j, auxBtn := range bb { btn := auxBtn.(map[string]interface{}) @@ -139,11 +140,17 @@ func (p *Page) decodeTranslations(tt locale.ResourceTranslationIndex) { "{{buttonID}}", strconv.FormatUint(buttonID, 10), ) - if aux = tt.FindByKey(rpl.Replace(LocaleKeyPageBlockAutomationButtonlabel.Path)); aux != nil { + if aux = tt.FindByKey(rpl.Replace(LocaleKeyPageBlockAutomationButtonLabel.Path)); aux != nil { btn["label"] = aux.Msg } } + + case "Content": + if aux = tt.FindByKey(rpl.Replace(LocaleKeyPageBlockContentBody.Path)); aux != nil { + block.Options["body"] = aux.Msg + } } + } } @@ -171,7 +178,9 @@ func (p *Page) encodeTranslations() (out locale.ResourceTranslationSet) { }) // - automation page block stuff - if block.Kind == "Automation" { + + switch block.Kind { + case "Automation": bb, _ := block.Options["buttons"].([]interface{}) for j, auxBtn := range bb { btn := auxBtn.(map[string]interface{}) @@ -193,10 +202,18 @@ func (p *Page) encodeTranslations() (out locale.ResourceTranslationSet) { out = append(out, &locale.ResourceTranslation{ Resource: p.ResourceTranslation(), - Key: rpl.Replace(LocaleKeyPageBlockAutomationButtonlabel.Path), + Key: rpl.Replace(LocaleKeyPageBlockAutomationButtonLabel.Path), Msg: btn["label"].(string), }) + } + case "Content": + body, _ := block.Options["body"].(string) + out = append(out, &locale.ResourceTranslation{ + Resource: p.ResourceTranslation(), + Key: rpl.Replace(LocaleKeyPageBlockContentBody.Path), + Msg: body, + }) } } diff --git a/def/compose.page.yaml b/def/compose.page.yaml index 5affab111..81cfceeb3 100644 --- a/def/compose.page.yaml +++ b/def/compose.page.yaml @@ -20,4 +20,5 @@ locale: - description - { name: blockTitle, path: "pageBlock.{{blockID}}.title", custom: true } - { name: blockDescription, path: "pageBlock.{{blockID}}.description", custom: true } - - { name: blockAutomationButtonlabel, path: "pageBlock.{{blockID}}.button.{{buttonID}}.label", custom: true } + - { name: blockAutomationButtonLabel, path: "pageBlock.{{blockID}}.button.{{buttonID}}.label", custom: true } + - { name: blockContentBody, path: "pageBlock.{{blockID}}.content.body", custom: true }