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
|
package keyfile
import (
"fmt"
)
// LocaleString returns the value for group 'g' and key 'k' using the
// system's locale.
func (kf *KeyFile) LocaleString(g, k string) (string, error) {
return kf.LocaleStringWithLocale(g, k, DefaultLocale())
}
// LocaleStringWithLocale returns the value for group 'g', key 'k', and
// locale 'l'.
func (kf *KeyFile) LocaleStringWithLocale(g, k string, l Locale) (string, error) {
for _, locale := range l.Variants() {
key := fmt.Sprintf("%v[%v]", k, locale)
if kf.KeyExists(g, key) {
return kf.String(g, key)
}
}
return kf.String(g, k)
}
// LocaleStringList returns a slice of strings for group 'g' and key
// 'k'.
func (kf *KeyFile) LocaleStringList(g, k string) ([]string, error) {
return kf.LocaleStringListWithLocale(g, k, DefaultLocale())
}
// LocaleStringListWithLocale returns a slice of strings for group 'g',
// key 'k', and locale 'l'.
func (kf *KeyFile) LocaleStringListWithLocale(g, k string, l Locale) ([]string, error) {
for _, locale := range l.Variants() {
key := fmt.Sprintf("%v[%v]", k, locale)
if kf.KeyExists(g, key) {
return kf.StringList(g, key)
}
}
return kf.StringList(g, k)
}
|