Skip to content

Commit 81c03a5

Browse files
author
andrey
committed
MFD-78 Added dict in generated mfd file
1 parent 9111c09 commit 81c03a5

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

generators/testdata/expected/newsportal.mfd

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,30 @@
88
</Languages>
99
<GoPGVer>10</GoPGVer>
1010
<CustomTypes></CustomTypes>
11+
<Dict>
12+
<actions>Действия</actions>
13+
<add>Добавить</add>
14+
<alias>Системное имя</alias>
15+
<categories>Категории</categories>
16+
<category>Категория</category>
17+
<content>Содержание</content>
18+
<createdAt>Создано</createdAt>
19+
<delete>Удалить</delete>
20+
<deletedAt>Удалено</deletedAt>
21+
<description>Описание</description>
22+
<edit>Редактировать</edit>
23+
<email>Email</email>
24+
<foreword>Краткое содержание</foreword>
25+
<image>Изображение</image>
26+
<login>Логин</login>
27+
<modifiedAt>Изменено</modifiedAt>
28+
<password>Пароль</password>
29+
<status>Статус</status>
30+
<statusId>Статус</statusId>
31+
<tag>Тег</tag>
32+
<tags>Теги</tags>
33+
<title>Название</title>
34+
<user>Пользователь</user>
35+
<users>Пользователи</users>
36+
</Dict>
1137
</Project>

mfd/files.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func LoadProject(filename string, create bool, goPGVer int) (*Project, error) {
5252

5353
project.Namespaces = []*Namespace{}
5454
project.VTNamespaces = []*VTNamespace{}
55+
project.Dict = NewDict()
5556

5657
dir := filepath.Dir(filename)
5758
for _, pf := range project.NamespaceNames {

mfd/model.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"encoding/xml"
66
"fmt"
7+
"sort"
78
"strings"
89

910
"github.com/dizzyfool/genna/model"
@@ -91,18 +92,54 @@ type Project struct {
9192
Languages []string `xml:"Languages>string" json:"languages"`
9293
GoPGVer int `xml:"GoPGVer" json:"goPGVer"`
9394
CustomTypes CustomTypes `xml:"CustomTypes>CustomType,omitempty" json:"customTypes,omitempty"`
95+
Dict *Dict `xml:"Dict" json:"dict,omitempty"`
9496

9597
Namespaces []*Namespace `xml:"-" json:"-"`
9698
VTNamespaces []*VTNamespace `xml:"-" json:"-"`
9799
NSMapping []NSMapping `xml:"-" json:"namespaces"`
98100
}
99101

102+
type Dict struct {
103+
Entries []Entry `xml:",any"`
104+
}
105+
106+
type Entry struct {
107+
XMLName xml.Name
108+
Value string `xml:",chardata"`
109+
}
110+
111+
func NewDict() *Dict {
112+
return &Dict{Entries: NewEntries()}
113+
}
114+
115+
func NewEntries() []Entry {
116+
var entries []Entry
117+
118+
d := presetsTranslations[RuLang]
119+
kk := make([]string, 0, len(d))
120+
for k := range d {
121+
kk = append(kk, k)
122+
}
123+
124+
// так как map не упорядочен в go, будем сортировать ключи по алфавиту
125+
sort.Strings(kk)
126+
for _, k := range kk {
127+
entries = append(entries, Entry{
128+
XMLName: xml.Name{Local: k},
129+
Value: d[k],
130+
})
131+
}
132+
133+
return entries
134+
}
135+
100136
func NewProject(name string, goPGVer int) *Project {
101137
return &Project{
102138
Name: name,
103139
NamespaceNames: []string{},
104140

105141
GoPGVer: goPGVer,
142+
Dict: NewDict(),
106143
Languages: []string{EnLang},
107144

108145
XMLxsi: "",

0 commit comments

Comments
 (0)