Add support for body translations for content block

This commit is contained in:
Denis Arh
2022-02-03 09:20:09 +01:00
parent 9d3f4d7706
commit 8a8cf42e93
4 changed files with 40 additions and 8 deletions
+10 -1
View File
@@ -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{})
)
+7 -2
View File
@@ -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
+21 -4
View File
@@ -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,
})
}
}
+2 -1
View File
@@ -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 }