I am trying to write Go code that will check whether or not a string represents a valid locale. From the documentation, I've gotten to here:
import "golang.org/x/text/language"
locale := "en"
tag, err := language.Parse(locale)
if err != nil {
return errors.New("Invalid locale: " + locale)
}
I think that this should work, and it seems to work most of the time, but it doesn't always give me an error when I expect it to. For example, if I say locale := "bcd" I don't get an error.
What am I missing here?
bcd is a valid ISO 639-3 language code for the North Babar language, and by extension it's a valid locale name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With