Go package for working with RFC 5646 language tags.
You will need to have both Go
(specifically version 1.12 or higher because we're using Go modules) and the make
programs installed on your computer. Assuming you do just type:
make tools
All of this package's dependencies are bundled with the code in the vendor
directory.
This is a pretty naive implementation. It works for the common language tags, including extensions and private use subtags, but might not work for grandfathered or irregular tags.
package main
import (
"flag"
"github.com/whosonfirst/go-rfc-5646/tags"
"log"
)
func main() {
flag.Parse()
for _, raw := range flag.Args() {
langtag, _ := tags.NewLangTag(raw)
log.Println(langtag.String())
log.Println(langtag.Language())
}
}
Note that error handling has been left out for the sake of brevity.
As of this writing there is only one interface for language tags themselves, and all its methods return strings. Eventually there will be interfaces for the subtags that make up a language tag and the current interface will be updated accordingly.
type LanguageTag interface {
Language() string
ExtLang() string
Script() string
Region() string
Variant() string
Extension() string
PrivateUse() string
String() string
}