blob: df0c33d0a3c6caf1e22e578cb0fdb6cb36855cb1 (
plain)
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
|
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")
}
|