Merge pull request #11721 from sharifelgamal/windows-locale

let windows users use the LC_ALL env var to set locale
pull/11708/head
Sharif Elgamal 2021-06-21 16:04:35 -07:00 committed by GitHub
commit 49f9bc868a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 4 deletions

View File

@ -19,6 +19,8 @@ package translate
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os"
"runtime"
"strings" "strings"
"github.com/cloudfoundry-attic/jibber_jabber" "github.com/cloudfoundry-attic/jibber_jabber"
@ -60,10 +62,18 @@ func T(s string) string {
// DetermineLocale finds the system locale and sets the preferred language for output appropriately. // DetermineLocale finds the system locale and sets the preferred language for output appropriately.
func DetermineLocale() { func DetermineLocale() {
locale, err := jibber_jabber.DetectIETF() var locale string
if err != nil { // Allow windows users to overload the same env vars as unix users
klog.V(1).Infof("Getting system locale failed: %v", err) if runtime.GOOS == "windows" {
locale = "" locale = os.Getenv("LC_ALL")
}
if locale == "" {
var err error
locale, err = jibber_jabber.DetectIETF()
if err != nil {
klog.V(1).Infof("Getting system locale failed: %v", err)
locale = ""
}
} }
SetPreferredLanguage(locale) SetPreferredLanguage(locale)