Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic locale detection #4199

Merged
merged 5 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,7 @@
[[constraint]]
name = "golang.org/x/text"
revision = "342b2e1fbaa52c93f31447ad2c6abc048c63e475"

[[constraint]]
name = "github.com/cloudfoundry-attic/jibber_jabber"
branch = "master"
17 changes: 15 additions & 2 deletions pkg/minikube/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strconv"
"strings"

"github.com/cloudfoundry-attic/jibber_jabber"
"github.com/golang/glog"
isatty "github.com/mattn/go-isatty"
"golang.org/x/text/language"
Expand Down Expand Up @@ -88,14 +89,20 @@ func OutStyle(style, format string, a ...interface{}) error {

// Out writes a basic formatted string to stdout
func Out(format string, a ...interface{}) error {
locale, err := jibber_jabber.DetectIETF()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind taking some Go benchmarks to see how if this adversely affects the Out() call performance?

If so, perhaps we should move the preferred language setup to cmd/minikube/main.go.

if err != nil {
glog.Warningf("Getting system locale failed: %s", err)
locale = ""
}
SetPreferredLanguage(locale)
p := message.NewPrinter(preferredLanguage)
if outFile == nil {
if _, err := p.Fprintf(os.Stdout, "(stdout unset)"+format, a...); err != nil {
return err
}
return fmt.Errorf("no output file has been set")
}
_, err := p.Fprintf(outFile, format, a...)
_, err = p.Fprintf(outFile, format, a...)
return err
}

Expand Down Expand Up @@ -124,14 +131,20 @@ func ErrStyle(style, format string, a ...interface{}) error {

// Err writes a basic formatted string to stderr
func Err(format string, a ...interface{}) error {
locale, err := jibber_jabber.DetectIETF()
if err != nil {
glog.Warningf("Getting system locale failed: %s", err)
locale = ""
}
SetPreferredLanguage(locale)
p := message.NewPrinter(preferredLanguage)
if errFile == nil {
if _, err := p.Fprintf(os.Stderr, "(stderr unset)"+format, a...); err != nil {
return err
}
return fmt.Errorf("no error file has been set")
}
_, err := p.Fprintf(errFile, format, a...)
_, err = p.Fprintf(errFile, format, a...)
return err
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading