-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlang.go
47 lines (39 loc) · 846 Bytes
/
lang.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
package golib
import "golang.org/x/text/language"
type Language string
type Languages []Language
func (lg Language) Tag() language.Tag {
return language.Make(string(lg))
}
func (lgs Languages) Tags() []language.Tag {
t := make([]language.Tag, len(lgs))
for idx, lg := range lgs {
t[idx] = lg.Tag()
}
return t
}
func (lgs Languages) Strings() []string {
s := make([]string, len(lgs))
for idx, lg := range lgs {
s[idx] = string(lg)
}
return s
}
func (lgs Languages) Contains(lang string) bool {
for _, lg := range lgs {
if string(lg) == lang {
return true
}
}
return false
}
func NewLanguage(tag language.Tag) Language {
return Language(tag.String())
}
func NewLanguages(tags []language.Tag) Languages {
lgs := make(Languages, len(tags))
for idx, tag := range tags {
lgs[idx] = NewLanguage(tag)
}
return lgs
}