...
1 package cldr_test
2
3 import (
4 "fmt"
5 "os"
6 "path/filepath"
7
8 "golang.org/x/text/internal/gen"
9 "golang.org/x/text/unicode/cldr"
10 )
11
12 func ExampleDecoder() {
13
14
15 var d cldr.Decoder
16
17
18 d.SetDirFilter("main", "supplemental")
19 d.SetSectionFilter("numbers", "plurals")
20
21 cldr, err := d.DecodeZip(gen.OpenCLDRCoreZip())
22 if err != nil {
23 fmt.Println("ERROR", err)
24 return
25 }
26 supplemental := cldr.Supplemental()
27
28 fmt.Println(supplemental.MeasurementData.MeasurementSystem[0].Type)
29 for _, lang := range cldr.Locales() {
30 data := cldr.RawLDML(lang)
31 fmt.Println(lang, data.Identity.Version.Number)
32 }
33 }
34
35 func ExampleDecoder_DecodePath() {
36
37
38 path := filepath.FromSlash("../../DATA/cldr/" + cldr.Version)
39
40 var d cldr.Decoder
41
42
43 d.SetDirFilter("main")
44 d.SetSectionFilter("numbers")
45
46 cldr, err := d.DecodePath(path)
47 if err != nil {
48
49 fmt.Println("ERROR", err)
50 return
51 }
52 for _, lang := range cldr.Locales() {
53 if numbers := cldr.RawLDML(lang).Numbers; numbers != nil {
54 fmt.Println(lang, len(numbers.Symbols))
55 }
56 }
57 }
58
59 func ExampleDecoder_DecodeZip() {
60
61
62 path := filepath.FromSlash("../../DATA/cldr/" + cldr.Version)
63
64 var d cldr.Decoder
65
66 r, err := os.Open(filepath.Join(path, "core.zip"))
67 if err != nil {
68 fmt.Println("error:", err)
69 return
70 }
71
72
73
74 d.SetDirFilter("supplemental")
75 cldr, err := d.DecodeZip(r)
76 if err != nil {
77 fmt.Println("error:", err)
78 return
79 }
80
81 fmt.Println(cldr.Supplemental().MeasurementData.MeasurementSystem[0].Type)
82 }
83
84 func ExampleSlice() {
85 var dr *cldr.CLDR
86
87 x, _ := dr.LDML("en")
88 cs := x.Collations.Collation
89
90 cldr.MakeSlice(&cs).Filter(func(e cldr.Elem) bool {
91 return e.GetCommon().Type != x.Collations.Default()
92 })
93 for i, c := range cs {
94 fmt.Println(i, c.Type)
95 }
96 }
97
View as plain text