diff options
author | Asaad Mahmood <asaad@spinpunch.com> | 2016-01-20 10:38:13 +0500 |
---|---|---|
committer | Asaad Mahmood <asaad@spinpunch.com> | 2016-01-20 10:38:13 +0500 |
commit | 547ad113c171ba9d2e3d7fc536b3184440b52303 (patch) | |
tree | c7afbb4684d63516e68b47b4a2a8fd8c52d813b2 /Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/translation/plural_translation.go | |
parent | 2b69cf31aea40d12690e97ce3981e3bd955f501b (diff) | |
parent | 1acd38b7b19521d06d274c42c00ce7072cd92196 (diff) | |
download | chat-547ad113c171ba9d2e3d7fc536b3184440b52303.tar.gz chat-547ad113c171ba9d2e3d7fc536b3184440b52303.tar.bz2 chat-547ad113c171ba9d2e3d7fc536b3184440b52303.zip |
Merge branch 'master' of https://github.com/mattermost/platform into ui-improvements
Diffstat (limited to 'Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/translation/plural_translation.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/translation/plural_translation.go | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/translation/plural_translation.go b/Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/translation/plural_translation.go new file mode 100644 index 000000000..4f579d16a --- /dev/null +++ b/Godeps/_workspace/src/github.com/nicksnyder/go-i18n/i18n/translation/plural_translation.go @@ -0,0 +1,78 @@ +package translation + +import ( + "github.com/nicksnyder/go-i18n/i18n/language" +) + +type pluralTranslation struct { + id string + templates map[language.Plural]*template +} + +func (pt *pluralTranslation) MarshalInterface() interface{} { + return map[string]interface{}{ + "id": pt.id, + "translation": pt.templates, + } +} + +func (pt *pluralTranslation) ID() string { + return pt.id +} + +func (pt *pluralTranslation) Template(pc language.Plural) *template { + return pt.templates[pc] +} + +func (pt *pluralTranslation) UntranslatedCopy() Translation { + return &pluralTranslation{pt.id, make(map[language.Plural]*template)} +} + +func (pt *pluralTranslation) Normalize(l *language.Language) Translation { + // Delete plural categories that don't belong to this language. + for pc := range pt.templates { + if _, ok := l.Plurals[pc]; !ok { + delete(pt.templates, pc) + } + } + // Create map entries for missing valid categories. + for pc := range l.Plurals { + if _, ok := pt.templates[pc]; !ok { + pt.templates[pc] = mustNewTemplate("") + } + } + return pt +} + +func (pt *pluralTranslation) Backfill(src Translation) Translation { + for pc, t := range pt.templates { + if t == nil || t.src == "" { + pt.templates[pc] = src.Template(language.Other) + } + } + return pt +} + +func (pt *pluralTranslation) Merge(t Translation) Translation { + other, ok := t.(*pluralTranslation) + if !ok || pt.ID() != t.ID() { + return t + } + for pluralCategory, template := range other.templates { + if template != nil && template.src != "" { + pt.templates[pluralCategory] = template + } + } + return pt +} + +func (pt *pluralTranslation) Incomplete(l *language.Language) bool { + for pc := range l.Plurals { + if t := pt.templates[pc]; t == nil || t.src == "" { + return true + } + } + return false +} + +var _ = Translation(&pluralTranslation{}) |