mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-09-19 01:22:30 +00:00
.github
bridge
ci
contrib
docker
gateway
hook
img
matterclient
matterhook
vendor
github.com
42wim
Philipp15b
bwmarrin
davecgh
dfordsoft
dgrijalva
fsnotify
go-telegram-bot-api
golang
google
gorilla
hashicorp
jpillora
kardianos
konsorten
labstack
lrstanley
magiconair
matterbridge
mattermost
mattn
mgutz
mitchellh
mreiferson
mrexodia
nicksnyder
go-i18n
i18n
bundle
language
translation
plural_translation.go
single_translation.go
template.go
translation.go
i18n.go
LICENSE
nlopes
paulrosania
pborman
pelletier
peterhellberg
pkg
pmezard
rs
russross
saintfish
shazow
shurcooL
sirupsen
spf13
stretchr
technoweenie
valyala
zfjagann
go.uber.org
golang.org
gopkg.in
modules.txt
.travis.yml
Dockerfile
LICENSE
README.md
changelog.md
go.mod
go.sum
matterbridge.go
matterbridge.toml.sample
matterbridge.toml.simple
79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
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{})
|