Example #1
0
func ExampleID_Script() {
	en := locale.Make("en")
	sr := locale.Make("sr")
	fmt.Println(en.Script())
	fmt.Println(sr.Script())
	// TODO:Output:
	// Latn High
	// Cyrl Low
}
Example #2
0
func ExampleID_Part() {
	loc := locale.Make("sr-RS")
	script := loc.Part(locale.ScriptPart)
	region := loc.Part(locale.RegionPart)
	fmt.Printf("%q %q", script, region)
	// TODO:Output: "" "RS"
}
Example #3
0
// parseMain parses XML files in the main directory of the CLDR core.zip file.
func parseMain() {
	d := &cldr.Decoder{}
	d.SetDirFilter("main")
	d.SetSectionFilter("characters")
	data := decodeCLDR(d)
	for _, loc := range data.Locales() {
		x := data.RawLDML(loc)
		if skipLang(x.Identity.Language.Type) {
			continue
		}
		if x.Characters != nil {
			x, _ = data.LDML(loc)
			loc = locale.Make(loc).String()
			for _, ec := range x.Characters.ExemplarCharacters {
				if ec.Draft != "" {
					continue
				}
				if _, ok := localeChars[loc]; !ok {
					mainLocales = append(mainLocales, loc)
					localeChars[loc] = make(charSets)
				}
				localeChars[loc][ec.Type] = parseCharacters(ec.Data())
			}
		}
	}
}
Example #4
0
func ExampleID_Scope() {
	loc := locale.Make("sr")
	set := loc.Scope()
	fmt.Println(set.Locales())
	fmt.Println(set.Languages())
	fmt.Println(set.Scripts())
	fmt.Println(set.Regions())
	// TODO:Output:
	// [sr_Cyrl sr_Cyrl_ME sr_Latn sr_Latn_ME sr_Cyrl_BA sr_Cyrl_RS sr_Latn_BA sr_Latn_RS]
	// [sr]
	// [Cyrl Latn]
	// [BA ME RS]
}
Example #5
0
func ExampleScript_Scope() {
	loc := locale.Make("zen-Tfng")
	script, _ := loc.Script()
	set := script.Scope()
	fmt.Println(set.Locales())
	fmt.Println(set.Languages())
	fmt.Println(set.Scripts())
	fmt.Println(set.Regions())
	// TODO:Output:
	// [shi shi-Tfng shi-Tfng_MA tzm]
	// [shi tzm zen]
	// [Tfng]
	// [MA]
}
Example #6
0
func (g *phraseGenerator) init(id string) {
	ec := exemplarCharacters
	loc := locale.Make(id).String()
	// get sets for locale or parent locale if the set is not defined.
	for i := range g.sets {
		for p, ok := loc, true; ok; p, ok = parent(p) {
			if set, ok := ec[p]; ok && set[i] != "" {
				g.sets[i].set = strings.Split(set[i], " ")
				break
			}
		}
	}
	r := newRewriter()
	r.addCases = *cases
	for i := range g.sets {
		g.sets[i].set = r.rewrite(g.sets[i].set)
	}
	// compute indexes
	for i, set := range g.sets {
		g.n += len(set.set)
		g.sets[i].charIndex = g.n
	}
}
Example #7
0
func newGoCollator(loc string) (Collator, error) {
	c := &goCollator{c: collate.New(locale.Make(loc))}
	return c, nil
}
Example #8
0
func ExampleID_Written() {
	loc := locale.Make("sl-Latn-IT-nedis")
	fmt.Println(loc.Written())
	// TODO:Output: sl-Latn
}
Example #9
0
func ExampleID_Parent() {
	loc := locale.Make("sl-Latn-IT-nedis")
	fmt.Println(loc.Parent())
	// TODO:Output: sl-Latn-IT
}