Skip to content
Snippets Groups Projects
Commit f3777780 authored by Semyon Krestyaninov's avatar Semyon Krestyaninov :dog2: Committed by Pavel Antonov
Browse files

feat(core): Добавлен перевод названий коллекций

Issue: #3091
parent 07c2f8bb
No related branches found
No related tags found
No related merge requests found
id: space_actions
name: Настройки/Действия
name: Settings/Actions
hidden: true
schema:
ui:
......@@ -224,3 +224,6 @@ schema:
widget: Icon
type: string
params: { }
translations:
ru:
name: Настройки/Действия
\ No newline at end of file
id: space_extensions
name: Настройки/Расширения
name: Settings/Extensions
hidden: true
schema:
ui:
......@@ -71,3 +71,6 @@ schema:
type: number
params:
format: int
translations:
ru:
name: Настройки/Расширения
\ No newline at end of file
......@@ -40,3 +40,22 @@ schema:
type: string
params:
required: true
---
id: collection_d
name: Коллекция D
schema:
type: object
params:
inline: false
fields:
name:
title: Название
description: Название коллекции
type: string
params:
required: true
translations:
en:
name: "Collection D"
fr:
name: "Le Collection D"
\ No newline at end of file
Subproject commit 0627c9f829178bc6de2623a0b6d42964c44de496
Subproject commit 95aca241a0cb17f5e1e9f584b1993bf7b933588e
package collections
import (
"maps"
"reflect"
"time"
"git.perx.ru/perxis/perxis-go/pkg/data"
......@@ -93,6 +95,8 @@ type Collection struct {
// Tags - список тегов коллекции. Добавляются при отправке событий events
Tags []string `json:"tags,omitempty" bson:"tags,omitempty"`
Translations map[string]map[string]string `json:"translations,omitempty" bson:"translations,omitempty"`
Config *Config `json:"-" bson:"-"`
}
......@@ -121,7 +125,8 @@ func (c Collection) Equal(other *Collection) bool {
c.MaxRevisions != other.MaxRevisions ||
c.RevisionTTL != other.RevisionTTL ||
!c.View.Equal(other.View) ||
!data.ElementsMatch(c.Tags, other.Tags) {
!data.ElementsMatch(c.Tags, other.Tags) ||
!reflect.DeepEqual(c.Translations, other.Translations) {
return false
}
return true
......@@ -224,6 +229,12 @@ func (c Collection) Clone() *Collection {
if c.Tags != nil {
clone.Tags = append([]string{}, c.Tags...)
}
if c.Translations != nil {
clone.Translations = make(map[string]map[string]string, len(c.Translations))
for k, v := range c.Translations {
clone.Translations[k] = maps.Clone(v)
}
}
return clone
}
......
......@@ -14,6 +14,7 @@ import (
commonpb "git.perx.ru/perxis/perxis-go/proto/common"
jsoniter "github.com/json-iterator/go"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"
)
......@@ -103,6 +104,17 @@ func PtrCollectionToProto(coll *service.Collection) (*pb.Collection, error) {
}
}
protoCollection.Translations = make(map[string]*structpb.Struct, len(coll.Translations))
for lang, dict := range coll.Translations {
s := &structpb.Struct{
Fields: make(map[string]*structpb.Value, len(dict)),
}
for field, translation := range dict {
s.Fields[field] = structpb.NewStringValue(translation)
}
protoCollection.Translations[lang] = s
}
return protoCollection, nil
}
......@@ -173,6 +185,14 @@ func ProtoToPtrCollection(protoCollection *pb.Collection) (*service.Collection,
}
}
collection.Translations = make(map[string]map[string]string, len(protoCollection.Translations))
for lang, dict := range protoCollection.Translations {
collection.Translations[lang] = make(map[string]string)
for field, translation := range dict.GetFields() {
collection.Translations[lang][field] = translation.GetStringValue()
}
}
return collection, nil
}
......
......@@ -13,8 +13,16 @@ func TestConfig_Load(t *testing.T) {
cfg := NewConfig()
cfg, err := cfg.Load(os.DirFS("../../assets/tests/setup"))
assert.NoError(t, err)
assert.Len(t, cfg.Collections, 3)
assert.Len(t, cfg.Collections, 4)
assert.Equal(t, cfg.Collections[0].Value(nil).ID, "collection_a")
assert.Equal(t, cfg.Collections[1].Value(nil).ID, "collection_b")
assert.Equal(t, cfg.Collections[2].Value(nil).ID, "collection_c")
{
coll := cfg.Collections[3].Value(nil)
assert.Equal(t, "collection_d", coll.ID)
assert.Equal(t, map[string]map[string]string{
"en": {"name": "Collection D"},
"fr": {"name": "Le Collection D"},
}, coll.Translations)
}
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment