diff options
Diffstat (limited to 'vendor/github.com/jmshal/go-locale/detect_locale_linux.go')
-rw-r--r-- | vendor/github.com/jmshal/go-locale/detect_locale_linux.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/vendor/github.com/jmshal/go-locale/detect_locale_linux.go b/vendor/github.com/jmshal/go-locale/detect_locale_linux.go new file mode 100644 index 0000000..df0c33d --- /dev/null +++ b/vendor/github.com/jmshal/go-locale/detect_locale_linux.go @@ -0,0 +1,31 @@ +package go_locale + +import ( + "strings" + "errors" +) + +func DetectLocale() (string, error) { + out, err := getCommandOutput("locale") + if err != nil { + return "", err + } + + lines := strings.Split(out, "\n") + for _, line := range lines { + if line != "" { + parts := strings.Split(line, "=") + value := strings.Trim(parts[1], `"`) + + if value != "C" && value != "" { + encodingIndex := strings.Index(value, ".") + if encodingIndex != -1 { + value = value[0:encodingIndex] + } + return value, nil + } + } + } + + return "", errors.New("unable to locale locale") +} |