Skip to content

Commit 4fca19f

Browse files
author
andrey
committed
Added custom translation in base translation map
1 parent 81c03a5 commit 4fca19f

File tree

4 files changed

+9
-54
lines changed

4 files changed

+9
-54
lines changed

generators/testdata/expected/newsportal.mfd

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,4 @@
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>
3711
</Project>

generators/xml-lang/generator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func (g *Generator) Generate() error {
8989
g.options.Namespaces = project.VTNamespaceNames()
9090
}
9191

92+
mfd.AddedCustomTranslations(project.Dict)
9293
langs := mergeLangs(project.Languages, g.options.Languages)
9394

9495
translations, err := mfd.LoadTranslations(g.options.MFDPath, langs)

mfd/files.go

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

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

5756
dir := filepath.Dir(filename)
5857
for _, pf := range project.NamespaceNames {
@@ -274,3 +273,11 @@ func LoadTemplate(path, def string) (string, error) {
274273

275274
return string(contents), nil
276275
}
276+
277+
func AddedCustomTranslations(d *Dict) {
278+
if d != nil {
279+
for _, e := range d.Entries {
280+
presetsTranslations[RuLang][e.XMLName.Local] = e.Value
281+
}
282+
}
283+
}

mfd/model.go

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

109
"github.com/dizzyfool/genna/model"
@@ -108,38 +107,12 @@ type Entry struct {
108107
Value string `xml:",chardata"`
109108
}
110109

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-
136110
func NewProject(name string, goPGVer int) *Project {
137111
return &Project{
138112
Name: name,
139113
NamespaceNames: []string{},
140114

141115
GoPGVer: goPGVer,
142-
Dict: NewDict(),
143116
Languages: []string{EnLang},
144117

145118
XMLxsi: "",

0 commit comments

Comments
 (0)