github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/util/configv3/locale.go (about)

     1  package configv3
     2  
     3  import "strings"
     4  
     5  const (
     6  	// DefaultLocale is the default CFConfig value for Locale.
     7  	DefaultLocale = ""
     8  )
     9  
    10  // Locale returns the locale/language the UI should be displayed in. This value
    11  // is based off of:
    12  //   1. The 'Locale' setting in the .cf/config.json
    13  //   2. The $LC_ALL environment variable if set
    14  //   3. The $LANG environment variable if set
    15  //   4. Defaults to DefaultLocale
    16  func (config *Config) Locale() string {
    17  	if config.ConfigFile.Locale != "" {
    18  		return config.ConfigFile.Locale
    19  	}
    20  
    21  	if config.ENV.LCAll != "" {
    22  		return config.convertLocale(config.ENV.LCAll)
    23  	}
    24  
    25  	if config.ENV.Lang != "" {
    26  		return config.convertLocale(config.ENV.Lang)
    27  	}
    28  
    29  	return DefaultLocale
    30  }
    31  
    32  func (config *Config) convertLocale(local string) string {
    33  	lang := strings.Split(local, ".")[0]
    34  	return strings.Replace(lang, "_", "-", -1)
    35  }