forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage.go
61 lines (53 loc) · 1.67 KB
/
language.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package uadmin
import "fmt"
// Language !
type Language struct {
Model
EnglishName string `uadmin:"required;read_only;filter;search"`
Name string `uadmin:"required;read_only;filter;search"`
Flag string `uadmin:"image;list_exclude"`
Code string `uadmin:"filter;read_only;list_exclude"`
RTL bool `uadmin:"list_exclude"`
Default bool `uadmin:"help:Set as the default language;list_exclude"`
Active bool `uadmin:"help:To show this in available languages;filter"`
AvailableInGui bool `uadmin:"help:The App is available in this language;read_only"`
}
// String !
func (l Language) String() string {
return l.Code
}
// Save !
func (l *Language) Save() {
if l.Default {
Update([]Language{}, "default", false, "`default` = ?", true)
defaultLang = *l
}
Save(l)
tempActiveLangs := []Language{}
Filter(&tempActiveLangs, "`active` = ?", true)
activeLangs = tempActiveLangs
tanslationList := []translation{}
for i := range activeLangs {
tanslationList = append(tanslationList, translation{
Active: activeLangs[i].Active,
Default: activeLangs[i].Default,
Code: activeLangs[i].Code,
Name: fmt.Sprintf("%s (%s)", activeLangs[i].Name, activeLangs[i].EnglishName),
})
}
for modelName := range Schema {
for i := range Schema[modelName].Fields {
if Schema[modelName].Fields[i].Type == cMULTILINGUAL {
Schema[modelName].Fields[i].Translations = tanslationList
}
}
}
}
// GetDefaultLanguage returns the default language
func GetDefaultLanguage() Language {
return defaultLang
}
// GetActiveLanguages returns a list of active langages
func GetActiveLanguages() []Language {
return activeLangs
}