Debian Codegraph @

keyfile/localestring.go

raw
1 package keyfile
2
3 import (
4 "fmt"
5 )
6
7 // LocaleString returns the value for group 'g' and key 'k' using the
8 // system's locale.
9 func (kf *KeyFile) LocaleString(g, k string) (string, error) {
10 return kf.LocaleStringWithLocale(g, k, DefaultLocale())
11 }
12
13 // LocaleStringWithLocale returns the value for group 'g', key 'k', and
14 // locale 'l'.
15 func (kf *KeyFile) LocaleStringWithLocale(g, k string, l Locale) (string, error) {
16 for _, locale := range l.Variants() {
17 key := fmt.Sprintf("%v[%v]", k, locale)
18 if kf.KeyExists(g, key) {
19 return kf.String(g, key)
20 }
21 }
22 return kf.String(g, k)
23 }
24
25 // LocaleStringList returns a slice of strings for group 'g' and key
26 // 'k'.
27 func (kf *KeyFile) LocaleStringList(g, k string) ([]string, error) {
28 return kf.LocaleStringListWithLocale(g, k, DefaultLocale())
29 }
30
31 // LocaleStringListWithLocale returns a slice of strings for group 'g',
32 // key 'k', and locale 'l'.
33 func (kf *KeyFile) LocaleStringListWithLocale(g, k string, l Locale) ([]string, error) {
34 for _, locale := range l.Variants() {
35 key := fmt.Sprintf("%v[%v]", k, locale)
36 if kf.KeyExists(g, key) {
37 return kf.StringList(g, key)
38 }
39 }
40 return kf.StringList(g, k)
41 }