github.com/go-enjin/golang-org-x-text@v0.12.1-enjin.2/internal/language/compact/gen_parents.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build ignore 6 // +build ignore 7 8 package main 9 10 import ( 11 "log" 12 13 "github.com/go-enjin/golang-org-x-text/internal/gen" 14 "github.com/go-enjin/golang-org-x-text/internal/language" 15 "github.com/go-enjin/golang-org-x-text/internal/language/compact" 16 "github.com/go-enjin/golang-org-x-text/unicode/cldr" 17 ) 18 19 func main() { 20 r := gen.OpenCLDRCoreZip() 21 defer r.Close() 22 23 d := &cldr.Decoder{} 24 data, err := d.DecodeZip(r) 25 if err != nil { 26 log.Fatalf("DecodeZip: %v", err) 27 } 28 29 w := gen.NewCodeWriter() 30 defer w.WriteGoFile("parents.go", "compact") 31 32 // Create parents table. 33 type ID uint16 34 parents := make([]ID, compact.NumCompactTags) 35 for _, loc := range data.Locales() { 36 tag := language.MustParse(loc) 37 index, ok := compact.FromTag(tag) 38 if !ok { 39 continue 40 } 41 parentIndex := compact.ID(0) // und 42 for p := tag.Parent(); p != language.Und; p = p.Parent() { 43 if x, ok := compact.FromTag(p); ok { 44 parentIndex = x 45 break 46 } 47 } 48 parents[index] = ID(parentIndex) 49 } 50 51 w.WriteComment(` 52 parents maps a compact index of a tag to the compact index of the parent of 53 this tag.`) 54 w.WriteVar("parents", parents) 55 }