Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

55 linhas
1.2 KiB

  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. // +build ignore
  5. package main
  6. import (
  7. "log"
  8. "golang.org/x/text/internal/gen"
  9. "golang.org/x/text/internal/language"
  10. "golang.org/x/text/internal/language/compact"
  11. "golang.org/x/text/unicode/cldr"
  12. )
  13. func main() {
  14. r := gen.OpenCLDRCoreZip()
  15. defer r.Close()
  16. d := &cldr.Decoder{}
  17. data, err := d.DecodeZip(r)
  18. if err != nil {
  19. log.Fatalf("DecodeZip: %v", err)
  20. }
  21. w := gen.NewCodeWriter()
  22. defer w.WriteGoFile("parents.go", "compact")
  23. // Create parents table.
  24. type ID uint16
  25. parents := make([]ID, compact.NumCompactTags)
  26. for _, loc := range data.Locales() {
  27. tag := language.MustParse(loc)
  28. index, ok := compact.FromTag(tag)
  29. if !ok {
  30. continue
  31. }
  32. parentIndex := compact.ID(0) // und
  33. for p := tag.Parent(); p != language.Und; p = p.Parent() {
  34. if x, ok := compact.FromTag(p); ok {
  35. parentIndex = x
  36. break
  37. }
  38. }
  39. parents[index] = ID(parentIndex)
  40. }
  41. w.WriteComment(`
  42. parents maps a compact index of a tag to the compact index of the parent of
  43. this tag.`)
  44. w.WriteVar("parents", parents)
  45. }