forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locale.go
35 lines (28 loc) · 850 Bytes
/
locale.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
package configv3
import "strings"
const (
// DefaultLocale is the default CFConfig value for Locale.
DefaultLocale = ""
)
// Locale returns the locale/language the UI should be displayed in. This value
// is based off of:
// 1. The 'Locale' setting in the .cf/config.json
// 2. The $LC_ALL environment variable if set
// 3. The $LANG environment variable if set
// 4. Defaults to DefaultLocale
func (config *Config) Locale() string {
if config.ConfigFile.Locale != "" {
return config.ConfigFile.Locale
}
if config.ENV.LCAll != "" {
return config.convertLocale(config.ENV.LCAll)
}
if config.ENV.Lang != "" {
return config.convertLocale(config.ENV.Lang)
}
return DefaultLocale
}
func (config *Config) convertLocale(local string) string {
lang := strings.Split(local, ".")[0]
return strings.Replace(lang, "_", "-", -1)
}