3
0

Add provision for page button resource translations

This commit is contained in:
Tomaž Jerman
2023-04-02 17:00:00 +02:00
committed by Jože Fortun
parent 9b5c59ded4
commit 67e7698b28
5 changed files with 99 additions and 32 deletions

View File

@@ -178,30 +178,6 @@ page: {
keys: {
title: {}
description: {}
recordToolbarButtonNewLabel: {
path: ["recordToolbar", "new", "label"]
customHandler: true
}
recordToolbarButtonEditLabel: {
path: ["recordToolbar", "edit", "label"]
customHandler: true
}
recordToolbarButtonSubmitLabel: {
path: ["recordToolbar", "submit", "label"]
customHandler: true
}
recordToolbarButtonDeleteLabel: {
path: ["recordToolbar", "delete", "label"]
customHandler: true
}
recordToolbarButtonCloneLabel: {
path: ["recordToolbar", "clone", "label"]
customHandler: true
}
recordToolbarButtonBackLabel: {
path: ["recordToolbar", "back", "label"]
customHandler: true
}
blockTitle: {
path: ["pageBlock", {part: "blockID", var: true}, "title"]
customHandler: true

View File

@@ -142,6 +142,31 @@ pageLayout: {
description: {
path: ["meta", "description"]
}
recordToolbarButtonNewLabel: {
path: ["config", "buttons", "new", "label"]
customHandler: true
}
recordToolbarButtonEditLabel: {
path: ["config", "buttons", "edit", "label"]
customHandler: true
}
recordToolbarButtonSubmitLabel: {
path: ["config", "buttons", "submit", "label"]
customHandler: true
}
recordToolbarButtonDeleteLabel: {
path: ["config", "buttons", "delete", "label"]
customHandler: true
}
recordToolbarButtonCloneLabel: {
path: ["config", "buttons", "clone", "label"]
customHandler: true
}
recordToolbarButtonBackLabel: {
path: ["config", "buttons", "back", "label"]
customHandler: true
}
actionLabel: {
path: ["config", "actions", {part: "actionID", var: true}, "label"]
customHandler: true

View File

@@ -50,18 +50,18 @@ var (
LocaleKeyNamespaceMetaDescription = LocaleKey{Path: "meta.description"}
LocaleKeyPageTitle = LocaleKey{Path: "title"}
LocaleKeyPageDescription = LocaleKey{Path: "description"}
LocaleKeyPageRecordToolbarNewLabel = LocaleKey{Path: "recordToolbar.new.label"}
LocaleKeyPageRecordToolbarEditLabel = LocaleKey{Path: "recordToolbar.edit.label"}
LocaleKeyPageRecordToolbarSubmitLabel = LocaleKey{Path: "recordToolbar.submit.label"}
LocaleKeyPageRecordToolbarDeleteLabel = LocaleKey{Path: "recordToolbar.delete.label"}
LocaleKeyPageRecordToolbarCloneLabel = LocaleKey{Path: "recordToolbar.clone.label"}
LocaleKeyPageRecordToolbarBackLabel = LocaleKey{Path: "recordToolbar.back.label"}
LocaleKeyPagePageBlockBlockIDTitle = LocaleKey{Path: "pageBlock.{{blockID}}.title"}
LocaleKeyPagePageBlockBlockIDDescription = LocaleKey{Path: "pageBlock.{{blockID}}.description"}
LocaleKeyPagePageBlockBlockIDButtonButtonIDLabel = LocaleKey{Path: "pageBlock.{{blockID}}.button.{{buttonID}}.label"}
LocaleKeyPagePageBlockBlockIDContentBody = LocaleKey{Path: "pageBlock.{{blockID}}.content.body"}
LocaleKeyPageLayoutMetaTitle = LocaleKey{Path: "meta.title"}
LocaleKeyPageLayoutMetaDescription = LocaleKey{Path: "meta.description"}
LocaleKeyPageLayoutConfigButtonsNewLabel = LocaleKey{Path: "config.buttons.new.label"}
LocaleKeyPageLayoutConfigButtonsEditLabel = LocaleKey{Path: "config.buttons.edit.label"}
LocaleKeyPageLayoutConfigButtonsSubmitLabel = LocaleKey{Path: "config.buttons.submit.label"}
LocaleKeyPageLayoutConfigButtonsDeleteLabel = LocaleKey{Path: "config.buttons.delete.label"}
LocaleKeyPageLayoutConfigButtonsCloneLabel = LocaleKey{Path: "config.buttons.clone.label"}
LocaleKeyPageLayoutConfigButtonsBackLabel = LocaleKey{Path: "config.buttons.back.label"}
LocaleKeyPageLayoutConfigActionsActionIDLabel = LocaleKey{Path: "config.actions.{{actionID}}.label"}
)

View File

@@ -2,11 +2,13 @@ package provision
import (
"context"
"strings"
"github.com/cortezaproject/corteza/server/compose/types"
"github.com/cortezaproject/corteza/server/pkg/filter"
"github.com/cortezaproject/corteza/server/store"
"github.com/cortezaproject/corteza/server/system/service"
systemTypes "github.com/cortezaproject/corteza/server/system/types"
"go.uber.org/zap"
)
@@ -25,9 +27,16 @@ func migratePages(ctx context.Context, log *zap.Logger, s store.Storer) (err err
crs *filter.PagingCursor
pages types.PageSet
auxf types.PageFilter
translations systemTypes.ResourceTranslationSet
)
return store.Tx(ctx, s, func(ctx context.Context, s store.Storer) (err error) {
translations, err = getRelevantTranslations(ctx, s)
if err != nil {
return
}
for {
pages, auxf, err = store.SearchComposePages(ctx, s, types.PageFilter{
Deleted: filter.StateInclusive,
@@ -42,7 +51,7 @@ func migratePages(ctx context.Context, log *zap.Logger, s store.Storer) (err err
break
}
err = migratePageChunk(ctx, s, pages)
err = migratePageChunk(ctx, s, translations, pages)
if err != nil {
return
}
@@ -56,7 +65,42 @@ func migratePages(ctx context.Context, log *zap.Logger, s store.Storer) (err err
})
}
func migratePageChunk(ctx context.Context, s store.Storer, pages types.PageSet) (err error) {
func getRelevantTranslations(ctx context.Context, s store.Storer) (out systemTypes.ResourceTranslationSet, err error) {
var (
crs *filter.PagingCursor
ll systemTypes.ResourceTranslationSet
auxf systemTypes.ResourceTranslationFilter
)
for {
ll, auxf, err = store.SearchResourceTranslations(ctx, s, systemTypes.ResourceTranslationFilter{
Paging: filter.Paging{
PageCursor: crs,
},
})
if err != nil {
return
}
if len(ll) == 0 {
break
}
for _, l := range ll {
if strings.HasPrefix(l.K, "recordToolbar.") {
out = append(out, l)
}
}
crs = auxf.Paging.PageCursor
if crs == nil {
break
}
}
return
}
func migratePageChunk(ctx context.Context, s store.Storer, translations systemTypes.ResourceTranslationSet, pages types.PageSet) (err error) {
n := now()
for _, p := range pages {
@@ -85,6 +129,14 @@ func migratePageChunk(ctx context.Context, s store.Storer, pages types.PageSet)
DeletedAt: p.DeletedAt,
}
// Translations
sr := strings.NewReplacer("recordToolbar", "config.buttons")
tt := translations.FilterResource(p.ResourceTranslation())
for _, t := range tt {
t.K = sr.Replace(t.K)
t.Resource = ly.ResourceTranslation()
}
// Blocks
for _, b := range p.Blocks {
b.XYWH = adjustBlockScale(b.XYWH, 12, 48)
@@ -104,6 +156,11 @@ func migratePageChunk(ctx context.Context, s store.Storer, pages types.PageSet)
if err != nil {
return
}
err = store.UpsertResourceTranslation(ctx, s, tt...)
if err != nil {
return
}
}
return

View File

@@ -153,6 +153,15 @@ func (set ResourceTranslationSet) FilterKey(key string) (out ResourceTranslation
return
}
func (set ResourceTranslationSet) FilterResource(res string) (out ResourceTranslationSet) {
for _, a := range set {
if a.Resource == res {
out = append(out, a)
}
}
return
}
func FromLocale(ll locale.ResourceTranslationSet) (out ResourceTranslationSet) {
for _, l := range ll {
out = append(out, &ResourceTranslation{