Check language tag

Hi! Tell me please how I can current check language tag?
I tried something like this
func main() {

 t, err := language.Parse("en")
 if err != nil {
  fmt.Println(err.Error())
 }

 fmt.Println(t)


 k, err := language.ParseBase("en")
 if err != nil {
  fmt.Println(err.Error())
 }

 fmt.Println(k)

 r, err := language.ParseRegion("en")
 if err != nil {
  fmt.Println(err.Error())
 }

 fmt.Println(r)
}

But the result is

en
en
language: subtag "EN" is well-formed but unknown
ZZ

and that little confused to me
Which pkg can check tags correctly?
Thanks!

Where is language coming from? I can not find such a package in the stdlib.

Aside of that, I’m not aware of any language that would have a sub-language “en”, perhaps you should try something like “us” or “uk” there?

Sorry, pkg - “golang.org/x/text/language
En - I mean like ENG

I can not find en or eng in the list of valid values per https://en.wikipedia.org/wiki/ISO_3166-1

Oh I see, only tags from ISO work’s fine?
But I need check tags with alpha3 value(
https://www.loc.gov/standards/iso639-2/php/English_list.php

Documentation says this:

ParseRegion parses a 2- or 3-letter ISO 3166-1 or a UN M.49 code. It returns a ValueError if s is a well-formed but unknown region identifier or another error if another error occurred.

So if you have to deal with ISO 639-2, then you need to find a library that can deal with that. Your current library explicitely states it does not.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.