Files
abra/pkg/lang/lang.go
decentral1se d44b18d7be
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
wip: feat: translate
2025-08-04 16:02:45 +02:00

35 lines
505 B
Go

package lang
import (
"os"
"strings"
"github.com/leonelquinteros/gotext"
)
func GetLocale() string {
if loc := os.Getenv("LC_MESSAGES"); loc != "" {
return NormalizeLocale(loc)
}
if loc := os.Getenv("LANG"); loc != "" {
return NormalizeLocale(loc)
}
return "C.UTF-8"
}
func NormalizeLocale(loc string) string {
if idx := strings.Index(loc, "."); idx != -1 {
return loc[:idx]
}
if idx := strings.Index(loc, "@"); idx != -1 {
return loc[:idx]
}
return loc
}
var T = gotext.Get