package main import ( "errors" "fmt" "golang.org/x/text/message" "golang.org/x/text/language" _ "golang.org/x/text/message" ) //go:generate gotext -srclang=en update -out=catalog.go -lang=fr,en type ErrorKind int const ( NoError ErrorKind = iota Unimplemented ) var Errors = map[ErrorKind]string{ NoError: "No error", Unimplemented: "Not yet implemented", } type Error struct { error Kind ErrorKind } func MakeError(kind ErrorKind, detail string) Error { var message string if len(detail) == 0 { message = Errors[kind] } else { message = fmt.Sprintf("%s: %s", Errors[kind], detail) } return Error{ Kind: kind, error: errors.New(message), } } func main() { p := message.NewPrinter(language.French) err := MakeError(NoError, "all is well") p.Printf(err) }