Skip to content
Snippets Groups Projects
Verified Commit 3b91ff9d authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: init data structures

parent b6242b63
No related branches found
No related tags found
No related merge requests found
...@@ -188,8 +188,8 @@ func applyTranslations(page, origin types.PageData, translations map[string]stri ...@@ -188,8 +188,8 @@ func applyTranslations(page, origin types.PageData, translations map[string]stri
} }
newPage.Meta = newMeta newPage.Meta = newMeta
// Text.Text newPage.Text = make([]types.Text, len(origin.Text))
for i, t := range newPage.Text { for i, t := range origin.Text {
tt := origin.Text[i] tt := origin.Text[i]
if tr, ok := translations[tt.Text]; ok { if tr, ok := translations[tt.Text]; ok {
newPage.Text[i].Text = tr newPage.Text[i].Text = tr
...@@ -198,30 +198,26 @@ func applyTranslations(page, origin types.PageData, translations map[string]stri ...@@ -198,30 +198,26 @@ func applyTranslations(page, origin types.PageData, translations map[string]stri
} }
} }
// Images: Alt und Title newPage.Images = make([]types.Image, len(origin.Images))
for i, img := range newPage.Images { for i, img := range origin.Images {
imgOrigin := origin.Images[i] if tr, ok := translations[img.Alt]; ok {
if tr, ok := translations[imgOrigin.Alt]; ok {
newPage.Images[i].Alt = tr newPage.Images[i].Alt = tr
} else { } else {
newPage.Images[i].Alt = img.Alt newPage.Images[i].Alt = img.Alt
} }
if tr, ok := translations[imgOrigin.Title]; ok { if tr, ok := translations[img.Title]; ok {
newPage.Images[i].Title = tr newPage.Images[i].Title = tr
} else { } else {
newPage.Images[i].Title = img.Title newPage.Images[i].Title = img.Title
} }
} }
// Anchors: Title newPage.Anchors = make([]types.Anchor, len(origin.Anchors))
for i, anc := range newPage.Anchors { for i, anc := range origin.Anchors {
ancOrigin := origin.Anchors[i]
if tr, ok := translations[ancOrigin.Title]; ok { if tr, ok := translations[anc.Title]; ok {
newPage.Anchors[i].Title = tr newPage.Anchors[i].Title = tr
} else { } else {
newPage.Anchors[i].Title = anc.Title newPage.Anchors[i].Title = anc.Title
...@@ -229,7 +225,8 @@ func applyTranslations(page, origin types.PageData, translations map[string]stri ...@@ -229,7 +225,8 @@ func applyTranslations(page, origin types.PageData, translations map[string]stri
} }
// Translations: KeyValues (nur falls Value ein String ist) // Translations: KeyValues (nur falls Value ein String ist)
for i, t := range newPage.Translations { newPage.Translations = make([]types.Translations, len(origin.Translations))
for i, t := range origin.Translations {
newKV := make(map[string]interface{}) newKV := make(map[string]interface{})
for k, v := range t.KeyValues { for k, v := range t.KeyValues {
if s, ok := v.(string); ok { if s, ok := v.(string); ok {
......
...@@ -19,10 +19,12 @@ type Anchor struct { ...@@ -19,10 +19,12 @@ type Anchor struct {
Title string `yaml:"title"` Title string `yaml:"title"`
} }
type TranslationKeyValues map[string]any
type Translations struct { type Translations struct {
Id string `yaml:"id"` Id string `yaml:"id"`
Type string `yaml:"type"` Type string `yaml:"type"`
KeyValues map[string]any `yaml:"translations"` KeyValues TranslationKeyValues `yaml:"translations"`
} }
type AddModification struct { type AddModification struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment