diff options
author | Christopher Speller <crspeller@gmail.com> | 2016-05-12 15:08:58 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-05-12 16:37:29 -0400 |
commit | 84d2482ddbff9564c9ad75b2d30af66e3ddfd44d (patch) | |
tree | 8bfa567d2b6381f4a996ada2deff8a16aa85a3ac /Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/translation/translation.go | |
parent | d1efb66ad7b017f0fbfe6f0c20843b30f396e504 (diff) | |
download | chat-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/translation/translation.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/translation/translation.go | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/translation/translation.go b/Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/translation/translation.go deleted file mode 100644 index fa93180b8..000000000 --- a/Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/translation/translation.go +++ /dev/null @@ -1,83 +0,0 @@ -// Package translation defines the interface for a translation. -package translation - -import ( - "fmt" - - "github.com/nicksnyder/go-i18n/i18n/language" -) - -// Translation is the interface that represents a translated string. -type Translation interface { - // MarshalInterface returns the object that should be used - // to serialize the translation. - MarshalInterface() interface{} - ID() string - Template(language.Plural) *template - UntranslatedCopy() Translation - Normalize(language *language.Language) Translation - Backfill(src Translation) Translation - Merge(Translation) Translation - Incomplete(l *language.Language) bool -} - -// SortableByID implements sort.Interface for a slice of translations. -type SortableByID []Translation - -func (a SortableByID) Len() int { return len(a) } -func (a SortableByID) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a SortableByID) Less(i, j int) bool { return a[i].ID() < a[j].ID() } - -// NewTranslation reflects on data to create a new Translation. -// -// data["id"] must be a string and data["translation"] must be either a string -// for a non-plural translation or a map[string]interface{} for a plural translation. -func NewTranslation(data map[string]interface{}) (Translation, error) { - id, ok := data["id"].(string) - if !ok { - return nil, fmt.Errorf(`missing "id" key`) - } - var pluralObject map[string]interface{} - switch translation := data["translation"].(type) { - case string: - tmpl, err := newTemplate(translation) - if err != nil { - return nil, err - } - return &singleTranslation{id, tmpl}, nil - case map[interface{}]interface{}: - // The YAML parser uses interface{} keys so we first convert them to string keys. - pluralObject = make(map[string]interface{}) - for k, v := range translation { - kStr, ok := k.(string) - if !ok { - return nil, fmt.Errorf(`invalid plural category type %T; expected string`, k) - } - pluralObject[kStr] = v - } - case map[string]interface{}: - pluralObject = translation - case nil: - return nil, fmt.Errorf(`missing "translation" key`) - default: - return nil, fmt.Errorf(`unsupported type for "translation" key %T`, translation) - } - - templates := make(map[language.Plural]*template, len(pluralObject)) - for k, v := range pluralObject { - pc, err := language.NewPlural(k) - if err != nil { - return nil, err - } - str, ok := v.(string) - if !ok { - return nil, fmt.Errorf(`plural category "%s" has value of type %T; expected string`, pc, v) - } - tmpl, err := newTemplate(str) - if err != nil { - return nil, err - } - templates[pc] = tmpl - } - return &pluralTranslation{id, templates}, nil -} |