本文整理汇总了Golang中golang.org/x/text/language.Make函数的典型用法代码示例。如果您正苦于以下问题:Golang Make函数的具体用法?Golang Make怎么用?Golang Make使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Make函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ExampleCompose
func ExampleCompose() {
nl, _ := language.ParseBase("nl")
us, _ := language.ParseRegion("US")
de := language.Make("de-1901-u-co-phonebk")
jp := language.Make("ja-JP")
fi := language.Make("fi-x-ing")
u, _ := language.ParseExtension("u-nu-arabic")
x, _ := language.ParseExtension("x-piglatin")
// Combine a base language and region.
fmt.Println(language.Compose(nl, us))
// Combine a base language and extension.
fmt.Println(language.Compose(nl, x))
// Replace the region.
fmt.Println(language.Compose(jp, us))
// Combine several tags.
fmt.Println(language.Compose(us, nl, u))
// Replace the base language of a tag.
fmt.Println(language.Compose(de, nl))
fmt.Println(language.Compose(de, nl, u))
// Remove the base language.
fmt.Println(language.Compose(de, language.Base{}))
// Remove all variants.
fmt.Println(language.Compose(de, []language.Variant{}))
// Remove all extensions.
fmt.Println(language.Compose(de, []language.Extension{}))
fmt.Println(language.Compose(fi, []language.Extension{}))
// Remove all variants and extensions.
fmt.Println(language.Compose(de.Raw()))
// An error is gobbled or returned if non-nil.
fmt.Println(language.Compose(language.ParseRegion("ZA")))
fmt.Println(language.Compose(language.ParseRegion("HH")))
// Compose uses the same Default canonicalization as Make.
fmt.Println(language.Compose(language.Raw.Parse("en-Latn-UK")))
// Call compose on a different CanonType for different results.
fmt.Println(language.All.Compose(language.Raw.Parse("en-Latn-UK")))
// Output:
// nl-US <nil>
// nl-x-piglatin <nil>
// ja-US <nil>
// nl-US-u-nu-arabic <nil>
// nl-1901-u-co-phonebk <nil>
// nl-1901-u-nu-arabic <nil>
// und-1901-u-co-phonebk <nil>
// de-u-co-phonebk <nil>
// de-1901 <nil>
// fi <nil>
// de <nil>
// und-ZA <nil>
// und language: subtag "HH" is well-formed but unknown
// en-Latn-GB <nil>
// en-GB <nil>
}
示例2: ExampleTag_Region
func ExampleTag_Region() {
ru := language.Make("ru")
en := language.Make("en")
fmt.Println(ru.Region())
fmt.Println(en.Region())
// Output:
// RU Low
// US Low
}
示例3: ExampleTag_Base
func ExampleTag_Base() {
fmt.Println(language.Make("und").Base())
fmt.Println(language.Make("und-US").Base())
fmt.Println(language.Make("und-NL").Base())
fmt.Println(language.Make("und-419").Base()) // Latin America
fmt.Println(language.Make("und-ZZ").Base())
// Output:
// en Low
// en High
// nl High
// es Low
// en Low
}
示例4: ExampleTags
func ExampleTags() {
n := display.Tags(language.English)
fmt.Println(n.Name(language.Make("nl")))
fmt.Println(n.Name(language.Make("nl-BE")))
fmt.Println(n.Name(language.Make("nl-CW")))
fmt.Println(n.Name(language.Make("nl-Arab")))
fmt.Println(n.Name(language.Make("nl-Cyrl-RU")))
// Output:
// Dutch
// Flemish
// Dutch (Curaçao)
// Dutch (Arabic)
// Dutch (Cyrillic, Russia)
}
示例5: Load
//Load load locales from filesystem
func (p *I18n) Load(dir string) error {
if err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
p.Logger.Debugf("Find locale file %s", path)
if err != nil {
return err
}
if info.Mode().IsRegular() {
ss := strings.Split(info.Name(), ".")
if len(ss) != 3 {
return fmt.Errorf("Ingnore locale file %s", info.Name())
}
code := ss[0]
lang := language.Make(ss[1])
fd, err := os.Open(path)
if err != nil {
return err
}
defer fd.Close()
sc := bufio.NewScanner(fd)
for sc.Scan() {
line := sc.Text()
idx := strings.Index(line, "=")
if idx <= 0 || line[0] == '#' {
continue
}
p.set(&lang, strings.TrimSpace(code+"."+line[0:idx]), strings.TrimSpace(line[idx+1:len(line)]))
}
}
return nil
}); err != nil {
return err
}
for lang := range p.Locales {
lng := language.Make(lang)
ks, err := p.Provider.Keys(&lng)
if err != nil {
return err
}
for _, k := range ks {
p.Locales[lang][k] = p.Provider.Get(&lng, k)
}
p.Logger.Debugf("Find locale %s, %d items.", lang, len(p.Locales[lang]))
}
return nil
}
示例6: ExampleParent
func ExampleParent() {
p := func(tag string) {
fmt.Printf("parent(%v): %v\n", tag, language.Make(tag).Parent())
}
p("zh-CN")
// Australian English inherits from World English.
p("en-AU")
// If the tag has a different maximized script from its parent, a tag with
// this maximized script is inserted. This allows different language tags
// which have the same base language and script in common to inherit from
// a common set of settings.
p("zh-HK")
// If the maximized script of the parent is not identical, CLDR will skip
// inheriting from it, as it means there will not be many entries in common
// and inheriting from it is nonsensical.
p("zh-Hant")
// The parent of a tag with variants and extensions is the tag with all
// variants and extensions removed.
p("de-1994-u-co-phonebk")
// Remove default script.
p("de-Latn-LU")
// Output:
// parent(zh-CN): zh
// parent(en-AU): en-001
// parent(zh-HK): zh-Hant
// parent(zh-Hant): und
// parent(de-1994-u-co-phonebk): de
// parent(de-Latn-LU): de
}
示例7: parseMain
// 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 = language.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())
}
}
}
}
示例8: ExampleCanonType
func ExampleCanonType() {
p := func(id string) {
fmt.Printf("Default(%s) -> %s\n", id, language.Make(id))
fmt.Printf("BCP47(%s) -> %s\n", id, language.BCP47.Make(id))
fmt.Printf("Macro(%s) -> %s\n", id, language.Macro.Make(id))
fmt.Printf("All(%s) -> %s\n", id, language.All.Make(id))
}
p("en-Latn")
p("sh")
p("zh-cmn")
p("bjd")
p("iw-Latn-fonipa-u-cu-usd")
// Output:
// Default(en-Latn) -> en-Latn
// BCP47(en-Latn) -> en
// Macro(en-Latn) -> en-Latn
// All(en-Latn) -> en
// Default(sh) -> sr-Latn
// BCP47(sh) -> sh
// Macro(sh) -> sh
// All(sh) -> sr-Latn
// Default(zh-cmn) -> cmn
// BCP47(zh-cmn) -> cmn
// Macro(zh-cmn) -> zh
// All(zh-cmn) -> zh
// Default(bjd) -> drl
// BCP47(bjd) -> drl
// Macro(bjd) -> bjd
// All(bjd) -> drl
// Default(iw-Latn-fonipa-u-cu-usd) -> he-Latn-fonipa-u-cu-usd
// BCP47(iw-Latn-fonipa-u-cu-usd) -> he-Latn-fonipa-u-cu-usd
// Macro(iw-Latn-fonipa-u-cu-usd) -> iw-Latn-fonipa-u-cu-usd
// All(iw-Latn-fonipa-u-cu-usd) -> he-Latn-fonipa-u-cu-usd
}
示例9: stopWordsCount
func (stop *StopWords) stopWordsCount(lang string, text string) wordStats {
if text == "" {
return wordStats{}
}
ws := wordStats{}
stopWords := set.New()
text = strings.ToLower(text)
tokenizer := NewMultilangTokenizer(language.Make(lang))
items := tokenizer.Tokenize(text)
stops := stop.cachedStopWords[lang]
if stops != nil {
for _, item := range items {
if stops.Has(item) {
stopWords.Add(item)
}
}
}
ws.stopWordCount = stopWords.Size()
ws.wordCount = len(items)
ws.stopWords = stopWords
return ws
}
示例10: TestTokenizer
func TestTokenizer(t *testing.T) {
japanese := language.Make("en")
tokenizer := NewMultilangTokenizer(japanese)
tokens := tokenizer.Tokenize("Language and Locale Matching in Go")
if !reflect.DeepEqual(tokens, []string{"Language", "and", "Locale", "Matching", "in", "Go"}) {
t.Fatalf("cannot tokenize english string. tokens %v", tokens)
}
}
示例11: TestJapaneseTokenizer
func TestJapaneseTokenizer(t *testing.T) {
japanese := language.Make("ja")
tokenizer := NewMultilangTokenizer(japanese)
tokens := tokenizer.Tokenize("すもももももももものうち")
if !reflect.DeepEqual(tokens, []string{"すもも", "も", "もも", "も", "もも", "の", "うち"}) {
t.Fatalf("cannot tokenize japanese string. tokens %v", tokens)
}
}
示例12: ExampleTag_Script
func ExampleTag_Script() {
en := language.Make("en")
sr := language.Make("sr")
sr_Latn := language.Make("sr_Latn")
fmt.Println(en.Script())
fmt.Println(sr.Script())
// Was a script explicitly specified?
_, c := sr.Script()
fmt.Println(c == language.Exact)
_, c = sr_Latn.Script()
fmt.Println(c == language.Exact)
// Output:
// Latn High
// Cyrl Low
// false
// true
}
示例13: Supported
// Supported returns the list of languages for which collating differs from its parent.
func Supported() []language.Tag {
ids := strings.Split(availableLocales, ",")
tags := make([]language.Tag, len(ids))
for i, s := range ids {
tags[i] = language.Make(s)
}
return tags
}
示例14: checkLang
func checkLang(srcStr, targStr string) tree.Bool {
srcLang := language.Make(srcStr)
srcRegion, srcRegionConf := srcLang.Region()
targLang := language.Make(targStr)
targRegion, targRegionConf := targLang.Region()
if srcRegionConf == language.Exact && targRegionConf != language.Exact {
return tree.Bool(false)
}
if srcRegion != targRegion && srcRegionConf == language.Exact && targRegionConf == language.Exact {
return tree.Bool(false)
}
_, _, conf := language.NewMatcher([]language.Tag{srcLang}).Match(targLang)
return tree.Bool(conf >= language.High)
}
示例15: getCollator
// getCollator returns a collate package Collator pointer. This can result in a
// panic, so this function must recover from that if it happens.
func getCollator(locale string) *collate.Collator {
defer func() {
recover()
}()
tag := language.Make(locale)
if tag == language.Und {
return nil
}
return collate.New(tag)
}