summaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/language/language.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-05-12 15:08:58 -0400
committerChristopher Speller <crspeller@gmail.com>2016-05-12 16:37:29 -0400
commit84d2482ddbff9564c9ad75b2d30af66e3ddfd44d (patch)
tree8bfa567d2b6381f4a996ada2deff8a16aa85a3ac /Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/language/language.go
parentd1efb66ad7b017f0fbfe6f0c20843b30f396e504 (diff)
downloadchat-84d2482ddbff9564c9ad75b2d30af66e3ddfd44d.tar.gz
chat-84d2482ddbff9564c9ad75b2d30af66e3ddfd44d.tar.bz2
chat-84d2482ddbff9564c9ad75b2d30af66e3ddfd44d.zip
Updating go depencancies. Switching to go1.6 vendoring (#2949)
Diffstat (limited to 'Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/language/language.go')
-rw-r--r--Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/language/language.go99
1 files changed, 0 insertions, 99 deletions
diff --git a/Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/language/language.go b/Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/language/language.go
deleted file mode 100644
index 9a155efc5..000000000
--- a/Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/language/language.go
+++ /dev/null
@@ -1,99 +0,0 @@
-// Package language defines languages that implement CLDR pluralization.
-package language
-
-import (
- "fmt"
- "strings"
-)
-
-// Language is a written human language.
-type Language struct {
- // Tag uniquely identifies the language as defined by RFC 5646.
- //
- // Most language tags are a two character language code (ISO 639-1)
- // optionally followed by a dash and a two character country code (ISO 3166-1).
- // (e.g. en, pt-br)
- Tag string
- *PluralSpec
-}
-
-func (l *Language) String() string {
- return l.Tag
-}
-
-// MatchingTags returns the set of language tags that map to this Language.
-// e.g. "zh-hans-cn" yields {"zh", "zh-hans", "zh-hans-cn"}
-// BUG: This should be computed once and stored as a field on Language for efficiency,
-// but this would require changing how Languages are constructed.
-func (l *Language) MatchingTags() []string {
- parts := strings.Split(l.Tag, "-")
- var prefix, matches []string
- for _, part := range parts {
- prefix = append(prefix, part)
- match := strings.Join(prefix, "-")
- matches = append(matches, match)
- }
- return matches
-}
-
-// Parse returns a slice of supported languages found in src or nil if none are found.
-// It can parse language tags and Accept-Language headers.
-func Parse(src string) []*Language {
- var langs []*Language
- start := 0
- for end, chr := range src {
- switch chr {
- case ',', ';', '.':
- tag := strings.TrimSpace(src[start:end])
- if spec := getPluralSpec(tag); spec != nil {
- langs = append(langs, &Language{NormalizeTag(tag), spec})
- }
- start = end + 1
- }
- }
- if start > 0 {
- tag := strings.TrimSpace(src[start:])
- if spec := getPluralSpec(tag); spec != nil {
- langs = append(langs, &Language{NormalizeTag(tag), spec})
- }
- return dedupe(langs)
- }
- if spec := getPluralSpec(src); spec != nil {
- langs = append(langs, &Language{NormalizeTag(src), spec})
- }
- return langs
-}
-
-func dedupe(langs []*Language) []*Language {
- found := make(map[string]struct{}, len(langs))
- deduped := make([]*Language, 0, len(langs))
- for _, lang := range langs {
- if _, ok := found[lang.Tag]; !ok {
- found[lang.Tag] = struct{}{}
- deduped = append(deduped, lang)
- }
- }
- return deduped
-}
-
-// MustParse is similar to Parse except it panics instead of retuning a nil Language.
-func MustParse(src string) []*Language {
- langs := Parse(src)
- if len(langs) == 0 {
- panic(fmt.Errorf("unable to parse language from %q", src))
- }
- return langs
-}
-
-// Add adds support for a new language.
-func Add(l *Language) {
- tag := NormalizeTag(l.Tag)
- pluralSpecs[tag] = l.PluralSpec
-}
-
-// NormalizeTag returns a language tag with all lower-case characters
-// and dashes "-" instead of underscores "_"
-func NormalizeTag(tag string) string {
- tag = strings.ToLower(tag)
- return strings.Replace(tag, "_", "-", -1)
-}