From d764efc1814cecdf209981ab203d83e20bd35d78 Mon Sep 17 00:00:00 2001 From: Vivek Patel Date: Thu, 7 Oct 2021 18:29:48 +0530 Subject: [PATCH] Fixes duplicate translation fields Updates ResourceTranslation compare method to check keys case-insensitively --- system/types/resource_translation.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/system/types/resource_translation.go b/system/types/resource_translation.go index e67fef722..cd531f266 100644 --- a/system/types/resource_translation.go +++ b/system/types/resource_translation.go @@ -2,6 +2,7 @@ package types import ( "database/sql/driver" + "strings" "time" "github.com/cortezaproject/corteza-server/pkg/filter" @@ -47,7 +48,7 @@ type ( } ) -// Scan on ReportDataSourceSet gracefully handles conversion from NULL +// Value scan on ReportDataSourceSet gracefully handles conversion from NULL func (l Lang) Value() (driver.Value, error) { return l.String(), nil } @@ -68,13 +69,13 @@ func (l *Lang) Scan(value interface{}) error { } func (a *ResourceTranslation) Compare(b *locale.ResourceTranslation) bool { - return a.K == b.Key && a.Lang.Tag.String() == b.Lang + return strings.EqualFold(a.K, b.Key) && a.Lang.Tag.String() == b.Lang } -func (aa ResourceTranslationSet) New(bb locale.ResourceTranslationSet) (out ResourceTranslationSet) { +func (set ResourceTranslationSet) New(bb locale.ResourceTranslationSet) (out ResourceTranslationSet) { outer: for _, b := range bb { - for _, a := range aa { + for _, a := range set { // It's not new if a.Compare(b) { continue outer @@ -91,9 +92,9 @@ outer: return } -func (aa ResourceTranslationSet) Old(bb locale.ResourceTranslationSet) (out ResourceTranslationSet) { +func (set ResourceTranslationSet) Old(bb locale.ResourceTranslationSet) (out ResourceTranslationSet) { for _, b := range bb { - for _, a := range aa { + for _, a := range set { // It's not new if a.Compare(b) { a.Message = b.Msg