Skip to content

Commit

Permalink
fix: [close #22] Properly detect system locale
Browse files Browse the repository at this point in the history
  • Loading branch information
axtloss committed Nov 2, 2024
1 parent d549faa commit 38c3824
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package orchid

import (
"os"
"strings"

l "github.com/vanilla-os/orchid/log"
)
Expand Down Expand Up @@ -29,10 +30,20 @@ func InitLog(prefix string, flags int) {
// from the LANG environment variable, or "en"
// if unset.
func Locale() string {
lang := os.Getenv("LANG")
if lang == "" {
lang = "en"
var locale string
for _, env := range []string{"LC_ALL", "LC_MESSAGES", "LANG"} {
locale = os.Getenv(env)
if strings.TrimSpace(locale) != "" {
break
}
}
if strings.TrimSpace(locale) == "C" || strings.TrimSpace(locale) == "POSIX" {
return strings.TrimSpace(locale)
}

langs := strings.Split(os.Getenv("LANGUAGE"), ":")
if len(langs) > 0 {
return strings.Split(langs[0], "_")[0]
}
locale := lang[:2]
return locale
}

0 comments on commit 38c3824

Please sign in to comment.