Skip to content

Commit

Permalink
Implement resource translation for compose namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
darh authored and tjerman committed Sep 22, 2021
1 parent 4276000 commit 7e9c432
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions compose/service/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/cortezaproject/corteza-server/pkg/locale"
"github.com/cortezaproject/corteza-server/pkg/rbac"
"github.com/cortezaproject/corteza-server/store"
"golang.org/x/text/language"
)

type (
Expand Down Expand Up @@ -209,6 +210,15 @@ func (svc namespace) Create(ctx context.Context, new *types.Namespace) (*types.N
return err
}

if contentLang := locale.GetContentLanguageFromContext(ctx); contentLang != language.Und {
tt := new.EncodeTranslations()
tt.SetLanguage(contentLang)
err = DefaultResourceTranslation.Upsert(ctx, tt)
if err != nil {
return err
}
}

if err = label.Create(ctx, s, new); err != nil {
return
}
Expand Down Expand Up @@ -275,12 +285,13 @@ func (svc namespace) updater(ctx context.Context, namespaceID uint64, action fun
}
}

// i18n
tt := ns.EncodeTranslations()
tt.SetLanguage(locale.GetLanguageFromContext(ctx))
err = DefaultResourceTranslation.Upsert(ctx, tt)
if err != nil {
return err
if contentLang := locale.GetContentLanguageFromContext(ctx); contentLang != language.Und {
tt := ns.EncodeTranslations()
tt.SetLanguage(contentLang)
err = DefaultResourceTranslation.Upsert(ctx, tt)
if err != nil {
return err
}
}

if changes&namespaceLabelsChanged > 0 {
Expand Down

0 comments on commit 7e9c432

Please sign in to comment.