gen.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2013 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. // Language tag table generator.
  6. // Data read from the web.
  7. package main
  8. import (
  9. "flag"
  10. "fmt"
  11. "log"
  12. "golang.org/x/text/internal/gen"
  13. "golang.org/x/text/unicode/cldr"
  14. )
  15. var (
  16. test = flag.Bool("test",
  17. false,
  18. "test existing tables; can be used to compare web data with package data.")
  19. outputFile = flag.String("output",
  20. "tables.go",
  21. "output file for generated tables")
  22. )
  23. func main() {
  24. gen.Init()
  25. w := gen.NewCodeWriter()
  26. defer w.WriteGoFile("tables.go", "compact")
  27. fmt.Fprintln(w, `import "golang.org/x/text/internal/language"`)
  28. b := newBuilder(w)
  29. gen.WriteCLDRVersion(w)
  30. b.writeCompactIndex()
  31. }
  32. type builder struct {
  33. w *gen.CodeWriter
  34. data *cldr.CLDR
  35. supp *cldr.SupplementalData
  36. }
  37. func newBuilder(w *gen.CodeWriter) *builder {
  38. r := gen.OpenCLDRCoreZip()
  39. defer r.Close()
  40. d := &cldr.Decoder{}
  41. data, err := d.DecodeZip(r)
  42. if err != nil {
  43. log.Fatal(err)
  44. }
  45. b := builder{
  46. w: w,
  47. data: data,
  48. supp: data.Supplemental(),
  49. }
  50. return &b
  51. }