register encoder
This commit is contained in:
parent
710b14ab9a
commit
c2100310eb
1 changed files with 11 additions and 0 deletions
|
@ -115,6 +115,14 @@ func ParseLocales(locales []string) Locales {
|
|||
return out
|
||||
}
|
||||
|
||||
func (l Locales) String() string {
|
||||
tags := make([]string, len(l))
|
||||
for i, tag := range l {
|
||||
tags[i] = tag.String()
|
||||
}
|
||||
return strings.Join(tags, " ")
|
||||
}
|
||||
|
||||
// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
|
||||
// It decodes an unquoted space seperated string into Locales.
|
||||
// Undefined language tags in the input are ignored and ommited from
|
||||
|
@ -231,6 +239,9 @@ func NewEncoder() *schema.Encoder {
|
|||
e.RegisterEncoder(SpaceDelimitedArray{}, func(value reflect.Value) string {
|
||||
return value.Interface().(SpaceDelimitedArray).String()
|
||||
})
|
||||
e.RegisterEncoder(Locales{}, func(value reflect.Value) string {
|
||||
return value.Interface().(Locales).String()
|
||||
})
|
||||
return e
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue